Size: 1285
Comment:
|
Size: 1285
Comment:
|
Deletions are marked like this. | Additions are marked like this. |
Line 20: | Line 20: |
{{{ """#!highlight python |
{{{#!highlight python """ |
yfinance
yfinance aimes to solve this problem by offering a reliable, threaded, and Pythonic way to download historical market data from Yahoo! finance.
- pip install yfinance --user
1 import yfinance
2 from pandas._libs.tslibs.timestamps import Timestamp
3 data = yfinance.download("AMZN",start="2019-01-01",end="2020-02-12")
4 d = data.to_dict()
5 d['Close'].key
6 # for k in d['Close'].iterkeys(): print (k)
7 d['Close'][Timestamp('2019-11-22 00:00:00')]
8 d['Close'][Timestamp('2020-02-10 00:00:00')]
MSFT example
1 """
2 cd ~/Documents/
3 mkdir yfinance-test
4 cd yfinance-test/
5 sudo apt install python3-venv
6 python3 -m venv testVenv
7 source testVenv/bin/activate
8 pip install yfinance
9 """
10 import yfinance as yf
11 msft = yf.Ticker("MSFT")
12
13 historyDataFrame = msft.history(period="5d")
14 print("Available columns")
15 for colname in historyDataFrame:
16 print(" "+colname)
17
18 print("Available indexes")
19 for idx in historyDataFrame.index:
20 print(" "+str(idx))
21
22 columnClose = historyDataFrame['Close']
23 rowidx = 0
24 print("Symbol:"+msft.info['symbol'])
25 for closeValue in columnClose.values:
26 print(historyDataFrame.index[rowidx], closeValue)
27 rowidx += 1