Take Locondo (3358), which has increased 3.5 times in 3 months, as an example. The environment is Google Colaboratory.
Create a method that can get stock price data with stooq.
import pandas as pd
import pandas_datareader.data as pdr
import numpy as np
from pandas.testing import assert_frame_equal
def makeDataFrame(code):
df_temp = pdr.DataReader("{}.JP".format(code), "stooq")
df = df_temp.loc[:,['Open','High','Low','Close','Volume']].sort_values('Date')
return df
Verification Get the data for the last 100 business days.
df = makeDataFrame(3558).tail(100)
df.tail()
Install with pip.
You can display it just by specifying the type and plotting.
import mplfinance as mpf
mpf.plot(df, type='candle')
Just add the option volume = True.
The moving average line can be displayed by specifying the date with the mav option. This is an example of displaying the 5, 25, 75 day line.
mpf.plot(df, type='candle', mav=(5, 25, 75), volume=True)
Install the library pyti that calculates Bollinger Bands.
Calculate at reference line 20.
from pyti.bollinger_bands import upper_bollinger_band as bb_up
from pyti.bollinger_bands import middle_bollinger_band as bb_mid
from pyti.bollinger_bands import lower_bollinger_band as bb_low
data = df['Close'].values.tolist()
period = 20
bb_up = bb_up(data,period)
bb_mid = bb_mid(data,period)
bb_low = bb_low(data,period)
df['bb_up'] = bb_up
df['bb_mid'] = bb_mid
df['bb_low'] = bb_low
Let's plot and check if it can be calculated.
By default, mplfinance only recognizes'Open',' High',' Low',' Close', and'Volume'. Make mplfinance recognize the item you want to add with make_addplot. When displaying, specify the items to be displayed together with the option of addplot.
apd = mpf.make_addplot(df[['bb_up', 'bb_mid', 'bb_low']])
mpf.plot(df, type='candle', addplot=apd, volume=True)