

nikkei225| High | Low | Open | Close | Volume | Adj Close | |
|---|---|---|---|---|---|---|
| Date | ||||||
| 2021-01-04 | 27602.109375 | 27042.320312 | 27575.570312 | 27258.380859 | 51500000 | 27258.380859 | 
| 2021-01-05 | 27279.779297 | 27073.460938 | 27151.380859 | 27158.630859 | 55000000 | 27158.630859 | 
| 2021-01-06 | 27196.400391 | 27002.179688 | 27102.849609 | 27055.939453 | 72700000 | 27055.939453 | 
| 2021-01-07 | 27624.730469 | 27340.460938 | 27340.460938 | 27490.130859 | 98900000 | 27490.130859 | 
| 2021-01-08 | 28139.029297 | 27667.750000 | 27720.140625 | 28139.029297 | 84900000 | 28139.029297 | 
| ... | ... | ... | ... | ... | ... | ... | 
| 2022-04-22 | 27205.830078 | 26904.380859 | 27197.800781 | 27105.259766 | 58500000 | 27105.259766 | 
| 2022-04-25 | 26764.480469 | 26487.839844 | 26692.480469 | 26590.779297 | 62700000 | 26590.779297 | 
| 2022-04-26 | 26808.990234 | 26592.990234 | 26743.210938 | 26700.109375 | 64300000 | 26700.109375 | 
| 2022-04-27 | 26406.619141 | 26051.039062 | 26313.140625 | 26386.630859 | 97300000 | 26386.630859 | 
| 2022-04-28 | 26876.949219 | 26348.359375 | 26430.279297 | 26847.900391 | 86700000 | 26847.900391 | 
324 rows × 6 columns
ボリンジャーバンドはジョン・ボリンジャーにより考案されました。一般的に3本の線によって構成されます。ボリンジャーバンドの中央に位置する線は価格の移動平均線です(デフォルトでは20日移動平均線となります)。上限のボリンジャーバンドのラインは、移動平均線の水準に標準偏差を加算して算出されたラインです。一方、下限のラインは、移動平均線の水準から標準偏差を差し引いて算出されたラインです。
BBANDS を使います。引数は以下です。#Bollinger Bands
import talib as ta
from talib import MA_Type
bb_upper1, middle, bb_lower1 = ta.BBANDS(nikkei225.Close, timeperiod=20, nbdevup=1, nbdevdn=1, matype=MA_Type.EMA)
bb_upper2, middle, bb_lower2 = ta.BBANDS(nikkei225.Close, timeperiod=20, nbdevup=2, nbdevdn=2, matype=MA_Type.EMA)
bb_upper3, middle, bb_lower3 = ta.BBANDS(nikkei225.Close, timeperiod=20, nbdevup=3, nbdevdn=3, matype=MA_Type.EMA)import plotly.graph_objects as go
from plotly.offline import iplot 
#draw candlestick chart
fig = go.Figure(go.Candlestick(x=nikkei225.index,
                open=nikkei225.Open, high=nikkei225.High,
                low=nikkei225.Low, close=nikkei225.Close, name= 'nikkei225')
)
#add upper band
fig.add_trace(
    go.Scatter(x=bb_upper3.index ,y=bb_upper3,  name= 'bb_upper3', mode='lines', line=dict(dash='dot'),), 
)
fig.add_trace(
    go.Scatter(x=bb_upper2.index ,y=bb_upper2,  name= 'bb_upper2', mode='lines', line=dict(dash='dot'),), 
)
fig.add_trace(
    go.Scatter(x=bb_upper1.index ,y=bb_upper1,  name= 'bb_upper1', mode='lines', line=dict(dash='dot'),), 
)
#add ema
fig.add_trace(
    go.Scatter(x=middle.index ,y=middle, name= 'middle',), 
)
#add lower band
fig.add_trace(
    go.Scatter(x=bb_lower1.index ,y=bb_lower1,  name= 'bb_lower1', mode='lines', line=dict(dash='dot'),), 
)
fig.add_trace(
    go.Scatter(x=bb_lower2.index ,y=bb_lower2,  name= 'bb_lower2', mode='lines', line=dict(dash='dot'),), 
)
fig.add_trace(
    go.Scatter(x=bb_lower3.index ,y=bb_lower3,  name= 'bb_lower3', mode='lines', line=dict(dash='dot'),), 
)
iplot(fig)