In [2]:
import numpy as np
import pandas_datareader.data as web


# https://github.com/gtnx/pandas-highcharts
from pandas_highcharts.display import display_charts


# https://github.com/arnoutaertgeerts/python-highcharts
import charts
In [11]:
# 日経平均のデータで試してみます
df = web.get_data_yahoo('^N225', '2000')
print(df.shape)
df.head()
(4046, 6)
Out[11]:
Open High Low Close Volume Adj Close
Date
2000-01-04 18937.449219 19187.609375 18937.449219 19002.859375 0 19002.859375
2000-01-05 19003.509766 19003.509766 18221.820312 18542.550781 0 18542.550781
2000-01-06 18574.009766 18582.740234 18168.269531 18168.269531 0 18168.269531
2000-01-07 18194.050781 18285.730469 18068.099609 18193.410156 0 18193.410156
2000-01-11 18246.099609 18887.560547 18246.099609 18850.919922 0 18850.919922
In [12]:
# まずはpandas_highchartsのほう とても簡単に使えて(・∀・)イイ!!
display_charts(df[['Adj Close']], chart_type='stock')
In [13]:
# python-highchartsのほう ボタンで表示非表示を切り替えれるんですね
charts.plot(df, stock=True, show='inline', display=['Close', 'High', 'Low'])
Out[13]:

Adjust chart settings

.json
In [14]:
# ローソク足も表示できるみたいです

# 移動平均の計算
ma_periods = [5, 10, 25, 50, 100, 200]
for n in ma_periods:
    df['ma{}'.format(n)] = df['Adj Close'].rolling(n).mean().round()

# ドンチャンチャネルの計算
df['channel_upper'] = df['High'].rolling(100).max().round()
df['channel_lower'] = df['Low'].rolling(100).min().round()

# ロウソク足のぶんのデータの設定
df['Time'] = df.index.astype(np.int64)//10**6
series = [{'type':'candlestick',
           'name':'candle',
           'data':df[['Time', 'Open', 'High', 'Low', 'Close']].as_matrix().round()}]

# 移動平均のぶん
series += [{'type':'line',
            'name':'ma{}d'.format(n),
            'data':df[['Time', 'ma{}'.format(n)]].dropna().as_matrix()
           } for n in ma_periods]

# チャネルのぶん
series += [{'type':'line',
            'name': name,
            'data': df[['Time', name]].dropna().as_matrix()
           } for name in ['channel_upper', 'channel_lower']]

# こんなかんじでオプションが指定できるみたいです
options = {'rangeSelector':{'selected':0},
           'xAxis':{'gridLineWidth':1, 'gridLineDashStyle':'Dot'},
           'yAxis':{'gridLineWidth':1, 'gridLineDashStyle':'Dot'}}

# 初期表示するやつを指定
display = ['candle', 'ma100d', 'channel_upper', 'channel_lower']

charts.plot(series, stock=True, show='inline', options=options, display=display)
Out[14]:

Adjust chart settings

.json