mplfinance is an extension to matplotlib for visualising financial data. In this article we create graphs from financial data using mplfinance. The basic usage is explained in the Tutorials section of the mplfinance repository.
defget_finance_data(ticker_symbol:str,start="2021-01-01",end="2021-06-30",savedir="data")->pd.DataFrame:"""Retrieves data recording stock prices
Args:
ticker_symbol (str): Description of param1
start (str): Date of beginning of period, optional.
end (str): Date of end of period, optional.
Returns:
res: Stock Price Data
"""res=Nonefilepath=os.path.join(savedir,f"{ticker_symbol}_{start}_{end}_historical.csv")os.makedirs(savedir,exist_ok=True)ifnotos.path.exists(filepath):try:time.sleep(5.0)res=web.DataReader(ticker_symbol,"yahoo",start=start,end=end)res.to_csv(filepath,encoding="utf-8-sig")except(RemoteDataError,KeyError):print(f"ticker_symbol ${ticker_symbol} が正しいか確認してください。")else:res=pd.read_csv(filepath,index_col="Date")res.index=pd.to_datetime(res.index)assertresisnotNone,"データ取得に失敗しました"returnres
1
2
3
4
5
6
7
# ticker symbol, period, and destination fileticker_symbol="NVDA"start="2021-01-01"end="2021-06-30"df=get_finance_data(ticker_symbol,start=start,end=end,savedir="../data")df.head()
One of the indicators used in technical analysis of stock prices and foreign exchange is the moving average.
In current technical analysis, there are many examples where three moving averages (short, medium, and long term) are displayed simultaneously. In daily charts, the 5-day, 25-day, and 75-day moving averages are often used.
Specify the mav option to plot the 5/25/75 day moving average.