Download history stock prices automatically from yahoo finance in python

后端 未结 6 1866
忘掉有多难
忘掉有多难 2020-12-04 05:42

Is there a way to automatically download historical prices of stocks from yahoo finance or google finance (csv format)? Preferably in Python.

6条回答
  •  -上瘾入骨i
    2020-12-04 06:16

    It's trivial when you know how:

    import yfinance as yf
    df = yf.download('CVS', '2015-01-01')
    df.to_csv('cvs-health-corp.csv')
    

    If you wish to plot it:

    import finplot as fplt
    fplt.candlestick_ochl(df[['Open','Close','High','Low']])
    fplt.show()
    

提交回复
热议问题