sys.path.append(package_path)

import pandas as pd

from KChart.plot_chart import plot_chart
from Algorithm.twinety import bi
from Algorithm.indicators import swt, ts_swt
from Algorithm.mkstatus import est_trend_1
from Data.get_data import read_csv

# Load data
# set end_date
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])
Exemplo n.º 2
0
from Strategy.strategy_m2_plus_multi import get_shares

# set end_date
end_date = '2018-12-31'
# 读取数据
etf_tickers = [
    'SHY', 'SPY', 'XLB', 'XLC', 'XLE', 'XLF', 'XLI', 'XLK', 'XLP', 'XLRE',
    'XLU', 'XLV', 'XLY'
]
basic_tickers = [
    'SHY', 'SPY', 'XLB', 'XLE', 'XLF', 'XLI', 'XLK', 'XLP', 'XLU', 'XLV', 'XLY'
]
etf_tickers = basic_tickers
mc_budget = [0.78, 0.22, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00,
             0.00]  #
pl = read_csv(etf_tickers, end_date)
#周线
wp = pl.resample('W', loffset=pd.offsets.timedelta(days=-6)).mean().dropna()
# 选择时间
end_year = 2018
start_year = 2004
hist_p = wp[wp.index.year <= end_year]
hist_p = hist_p[hist_p.index.year >= start_year]
evaluated_data = hist_p.copy()
hist_p = wp[wp.index.year < start_year]
supporting_data = hist_p.copy()
# back testing
# Performance for Strategy
start_time = process_time()
pfm, s, w, accumulated_return, total_return, annual_return, annual_std, sharpe_ratio, max_loss, indicators = get_performance(
    supporting_data, evaluated_data, mc_budget, get_shares)
from Data.get_data import read_csv
from BackTesting.backtesting import get_performance_2 as get_performance
#from BackTesting.backtesting import get_figname
from Reporting.display import get_filename
from Strategy.strategy_m5 import get_shares

# 读取数据
etf_tickers=['SHY','SPY','XLB','XLC','XLE','XLF','XLI','XLK','XLP','XLRE','XLU','XLV','XLY']
basic_tickers = ['SHY','SPY','XLB','XLE','XLF','XLI','XLK','XLP','XLU','XLV','XLY']
etf_tickers = basic_tickers 
mc_budget = [0.8, 0.2]
if len(etf_tickers)>2:
    for e in range(2,len(etf_tickers)):
        mc_budget.append(0.0)
pl=read_csv(etf_tickers)
#周线
wp = pl.resample('W', loffset=pd.offsets.timedelta(days=0)).last().dropna()
# 选择时间
end_year = 2019
start_year = 2004
hist_p = wp[wp.index.year<=end_year]
hist_p = hist_p[hist_p.index.year>=start_year]
evaluated_data = hist_p.copy()
hist_p = wp[wp.index.year<start_year]
supporting_data = hist_p.copy()
# back testing
# Performance for Strategy
start_time = process_time()
pfm, s, w, accumulated_return, total_return, \
    annual_return, annual_std, sharpe_ratio, \