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 df.k_chart( main_indicator_cols=['wt'],#'ma'],
end_date = '' # 读取数据 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
# Load data data_path = package_path + '/Data/' source_data = pd.read_csv(data_path + '2833.csv', parse_dates=True, index_col=0) # 准备测试数据 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] df = hist_p.copy() # Calc Bench (Wavelet) and Post_Bi bi_level = 4 cA, cD = swt(df['Adj Close'], bi_level + 1) if 'High' in df.columns.values: df['bi_post'] = bi(df['High'], df['Low'], bench=cA[bi_level]) else: df['bi_post'] = bi(df['Adj Close'], df['Adj Close'], bench=cA[bi_level]) cA, cD = ts_swt(df['Adj Close'], bi_level + 1) # calc sub_indicator df['real_trend'] = real_trend(df['bi_post']) df['mean'], df['std'] = ts_mean_std(df['Adj Close']) df['diff'] = df['std'] * df['std'] + df['mean'] #df['cross'] = cross(df['diff'], v=0.01) df['zeros'] = 0 # df['est_trend'], df['slope'] = est_trend_1(df['diff']) # select data to plot