コード例 #1
0
from KChart import k_chart
from Algorithm.twinety import bi
from Algorithm.indicators import swt, ts_swt
from Algorithm.mkstatus import strong
from Algorithm.mkstatus import est_trend_1 as trend

# Load data
data_path = package_path + '/Data/'
source_data = pd.read_csv(data_path+'7300.csv', parse_dates=True, index_col=0)

# Calc
n=256
df=source_data #[3:n]
# bi
df['bi'] = bi(df['High'],df['Low'])
# Calc Bench (Wavelet)
cA, cD = swt(df['Close'],6)
df['wt']=cA[1]
df['bi1'] = bi(df['High'],df['Low'],bench=cA[1])
df['bi2'] = bi(df['High'],df['Low'],bench=cA[2])
# calc main_indicator
cA, cD = ts_swt(df['Close'],6)
df['wt']=cA[2]
# calc main_indicator
df['ma'] = df['Close'].rolling(12,center=True,min_periods=1).mean()
# calc sub_indicator
#df['trend'] = trend(df['bi2'])
#df['strong'] = strong(df['bi1'],df['trend'])

# plot ohlc candlestick
コード例 #2
0
etf_tickers = ['2833']
source_data = read_csv(etf_tickers, end_date)

# 准备测试数据
end_year = 2018
start_year = 2013
hist_p = source_data[source_data.index.year <= end_year]
hist_p = hist_p[hist_p.index.year >= start_year]
wp = hist_p.resample('W', loffset=pd.offsets.timedelta(days=-6)).mean()
df = wp.copy()  #[3:n]

# Calc Bench (Wavelet) and Post_Bi
bi_level = 4
cA, cD = swt(df[etf_tickers].get_values(), bi_level + 1)
df['bi_post'] = bi(df[etf_tickers].get_values(),
                   df[etf_tickers].get_values(),
                   bench=cA[bi_level])
cA, cD = ts_swt(df[etf_tickers].get_values(), bi_level + 1)
df['wt_long'] = cA[bi_level]
# calc sub_indicator
df['dn_line'] = -0.02
df['up_line'] = 0.08
#
df['est_trend'], df['slope'] = est_trend_1(df['wt_long'])

# select data to plot
df = df[df.index.year >= start_year + 1]
df['Adj Close'] = df[etf_tickers]
# plot ohlc candlestick
plot_chart(df,
           sub_indicator_cols=['slope', 'dn_line', 'up_line'],
コード例 #3
0
ファイル: example_2.py プロジェクト: easy00000000/k_chart
from KChart import k_chart
from Algorithm.twinety import bi
from Algorithm.swt import swt, ts_swt
from Algorithm.mkstatus import trend

# Load data
data_path = package_path + '/Data/'
source_data = pd.read_csv(data_path + 'spy2018-12-31.csv',
                          parse_dates=True,
                          index_col=0)

# Calc
df = source_data  #[3:n]

# Calc Bench (Wavelet) and Post_Bi
bi_level = 6
cA, cD = swt(df['Adj Close'], bi_level + 1)
df['wt'] = cA[bi_level]
df['bi_post'] = bi(df['High'], df['Low'], bench=cA[bi_level])
# calc main_indicator
#cA, cD = ts_swt(df['Close'],6)
#df['wt']=cA[6]
# calc sub_indicator
df['trend'] = trend(df['bi_post'])

# plot ohlc candlestick
df.k_chart(main_indicator_cols=['wt'],
           volume_col=['Volume'],
           sub_indicator_cols=['trend'],
           bi_cols=['bi_post'])