While studying Python, there was a module that seemed to be interesting, so I tried using it
pandas_datareader
You can install it with the following code
pip install pandas-datarader
This time I got the stock price of a company called GAFA Please search Yahoo Finance for other stocks.
read-stock
import pandas_datareader as web
import pandas as pd
import datetime
data=web.get_data_yahoo(['GOOG','AAPL','FB','AMZN'])['Adj Close']
print(data.pct_change().tail())
Output example
Symbols GOOG AAPL FB AMZN Date 2020-09-04 -0.030941 0.000662 -0.028820 -0.021787 2020-09-08 -0.036863 -0.067295 -0.040922 -0.043944 2020-09-09 0.016034 0.039887 0.009441 0.037707 2020-09-10 -0.016018 -0.032646 -0.020568 -0.028605 2020-09-11 -0.007376 -0.013129 -0.005521 -0.018547
Simple ~~ Explanation ~~ data: Adjusted closing price of each stock (Adj Close) pct_change (): Method to find the amount of change tail (): Get the last 5 rows of DataFrame
datetime
#If you want to decide the acquisition period
data=web,get_data_yahoo(['GOOG','AAPL','FB','AMZN'],
start=datetime.datetime(20xx,yy,zz),
end=datetime.datetime(20xx,yy,zz))['Adj Close']
Besides Open: Open price Close: Close price High: High Low: Low price Volume: Volume And so on
Recommended Posts