-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest2.py
More file actions
74 lines (69 loc) · 1.32 KB
/
Copy pathtest2.py
File metadata and controls
74 lines (69 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import yfinance as yf
import time
msft = yf.Ticker("MSFT")
print(msft)
"""
returns
<yfinance.Ticker object at 0x1a1715e898>
"""
time.sleep(1)
# get stock info
print(msft.info['shortName'])
"""
returns:
{
'quoteType': 'EQUITY',
'quoteSourceName': 'Nasdaq Real Time Price',
'currency': 'USD',
'shortName': 'Microsoft Corporation',
'exchangeTimezoneName': 'America/New_York',
...
'symbol': 'MSFT'
}
"""
# get historical market data
print(msft.history(period="max"))
"""
returns:
Open High Low Close Volume Dividends Splits
Date
1986-03-13 0.06 0.07 0.06 0.07 1031788800 0.0 0.0
1986-03-14 0.07 0.07 0.07 0.07 308160000 0.0 0.0
...
2019-04-15 120.94 121.58 120.57 121.05 15792600 0.0 0.0
2019-04-16 121.64 121.65 120.10 120.77 14059700 0.0 0.0
"""
# show actions (dividends, splits)
msft.actions
"""
returns:
Dividends Splits
Date
1987-09-21 0.00 2.0
1990-04-16 0.00 2.0
...
2018-11-14 0.46 0.0
2019-02-20 0.46 0.0
"""
# show dividends
msft.dividends
"""
returns:
Date
2003-02-19 0.08
2003-10-15 0.16
...
2018-11-14 0.46
2019-02-20 0.46
"""
# show splits
msft.splits
"""
returns:
Date
1987-09-21 2.0
1990-04-16 2.0
...
1999-03-29 2.0
2003-02-18 2.0
"""