-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathExempleYfinanceChargementDonnees.py
154 lines (107 loc) · 2.92 KB
/
ExempleYfinanceChargementDonnees.py
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
# -*- coding: utf-8 -*-
"""
Created on Wed Aug 11 08:19:02 2021
@author: vango
"""
import yfinance as yf
msft = yf.Ticker("MSFT")
# get stock info
msft.info
# get historical market data
hist = msft.history(period="max")
print(hist.head())
# show actions (dividends, splits)
msft.actions
# show dividends
msft.dividends
# show splits
msft.splits
# show financials
msft.financials
msft.quarterly_financials
# show major holders
msft.major_holders
# show institutional holders
msft.institutional_holders
# show balance sheet
msft.balance_sheet
msft.quarterly_balance_sheet
# show cashflow
msft.cashflow
msft.quarterly_cashflow
# show earnings
msft.earnings
msft.quarterly_earnings
# show sustainability
msft.sustainability
# show analysts recommendations
msft.recommendations
# show next event (earnings, etc)
msft.calendar
# show ISIN code - *experimental*
# ISIN = International Securities Identification Number
msft.isin
# show options expirations
msft.options
# get option chain for specific expiration
opt = msft.option_chain('2021-08-27')
# data available via: opt.calls, opt.puts
# Import yfinance package
import yfinance as yf
# Set the start and end date
start_date = '1990-01-01'
end_date = '2021-07-12'
# Set the ticker
ticker = 'AMZN'
# Get the data
data = yf.download(ticker, start_date, end_date)
# Print 5 rows
print(data.tail())
# Import matplotlib for plotting
import matplotlib.pyplot as plt
# Plot adjusted close price data
data['Adj Close'].plot()
plt.show()
# Plot the adjusted close price
data['Adj Close'].plot(figsize=(10, 7))
# Define the label for the title of the figure
plt.title("Adjusted Close Price of %s" % ticker, fontsize=16)
# Define the labels for x-axis and y-axis
plt.ylabel('Price', fontsize=14)
plt.xlabel('Year', fontsize=14)
# Plot the grid lines
plt.grid(which="major", color='k', linestyle='-.', linewidth=0.5)
# Show the plot
plt.show()
import pandas as pd
# Set the start and end date
start_date = '1990-01-01'
end_date = '2021-07-12'
# Define the ticker list
tickers_list = ['AAPL', 'IBM', 'MSFT', 'WMT']
# Create placeholder for data
data = pd.DataFrame(columns=tickers_list)
# Fetch the data
for ticker in tickers_list:
data[ticker] = yf.download(ticker,
start_date,
end_date)['Adj Close']
# Print first 5 rows of the data
print(data.head())
# Plot all the close prices
data.plot(figsize=(10, 7))
# Show the legend
plt.legend()
# Define the label for the title of the figure
plt.title("Adjusted Close Price", fontsize=16)
# Define the labels for x-axis and y-axis
plt.ylabel('Price', fontsize=14)
plt.xlabel('Year', fontsize=14)
# Plot the grid lines
plt.grid(which="major", color='k', linestyle='-.', linewidth=0.5)
plt.show()
intraday_data = yf.download(tickers="MSFT",
period="5d",
interval="1m",
auto_adjust=True)
intraday_data.head()