Buscar este blog

viernes, 11 de febrero de 2022

Descargar datos de Yahoo finance con PYTHON

 Instalar el modulo yahoo_fin

pip install yahoo_fin


Ejemplo de descargar datos (precio apertura, maximo, minimo, cierre, cierre ajustado, volumen) S&P 500:

from yahoo_fin.stock_info import get_data
sp500_data = get_data('^GSPC')
print(sp500_data)


Resultado:

open high low close adjclose \ 1970-03-25 0.000000 91.070000 88.110001 89.769997 89.769997 1970-03-26 0.000000 90.650002 89.180000 89.919998 89.919998 1970-03-30 0.000000 90.410004 88.910004 89.629997 89.629997 1970-03-31 0.000000 90.169998 88.849998 89.629997 89.629997 1970-04-01 0.000000 90.620003 89.300003 90.070000 90.070000 ... ... ... ... ... ... 2022-02-07 4505.750000 4521.859863 4471.470215 4483.870117 4483.870117 2022-02-08 4480.020020 4531.319824 4465.399902 4521.540039 4521.540039 2022-02-09 4547.000000 4590.029785 4547.000000 4587.180176 4587.180176 2022-02-10 4553.240234 4588.919922 4484.310059 4504.080078 4504.080078 2022-02-11 4506.270020 4515.200195 4501.529785 4504.939941 4504.939941 volume ticker 1970-03-25 17500000 ^GSPC 1970-03-26 11350000 ^GSPC 1970-03-30 9600000 ^GSPC 1970-03-31 8370000 ^GSPC 1970-04-01 9810000 ^GSPC ... ... ... 2022-02-07 3291600000 ^GSPC 2022-02-08 3509330000 ^GSPC 2022-02-09 3662810000 ^GSPC 2022-02-10 4490500000 ^GSPC






Codigo programa descargar a partir de una fecha:
from yahoo_fin.stock_info import get_data
de1999 = get_data('^GSPC' , start_date = '01/01/1999')
print(de1999)

Resultado:

open high low close adjclose \ 1999-01-04 1229.229980 1248.810059 1219.099976 1228.099976 1228.099976 1999-01-05 1228.099976 1246.109985 1228.099976 1244.780029 1244.780029 1999-01-06 1244.780029 1272.500000 1244.780029 1272.339966 1272.339966 1999-01-07 1272.339966 1272.339966 1257.680054 1269.729980 1269.729980 1999-01-08 1269.729980 1278.239990 1261.819946 1275.089966 1275.089966 ... ... ... ... ... ... 2022-02-07 4505.750000 4521.859863 4471.470215 4483.870117 4483.870117 2022-02-08 4480.020020 4531.319824 4465.399902 4521.540039 4521.540039 2022-02-09 4547.000000 4590.029785 4547.000000 4587.180176 4587.180176 2022-02-10 4553.240234 4588.919922 4484.310059 4504.080078 4504.080078 2022-02-11 4506.270020 4526.330078 4501.529785 4519.910156 4519.910156 volume ticker 1999-01-04 877000000 ^GSPC 1999-01-05 775000000 ^GSPC 1999-01-06 986900000 ^GSPC 1999-01-07 863000000 ^GSPC 1999-01-08 937800000 ^GSPC ... ... ... 2022-02-07 3291600000 ^GSPC 2022-02-08 3509330000 ^GSPC 2022-02-09 3662810000 ^GSPC 2022-02-10 4490500000 ^GSPC 2022-02-11 269992049 ^GSPC