どんな記事
このバックテストでは、次のことがわかります。
- サイジングの有効性 データによる裏付け
- 基準にするATR は加工したほうが良いのか
- 単利の資金管理 を含めるとどうなるのか
今回のバックテストを行うにあたって、これまでのバックテストに単利の資金管理を含める開発を行いました。サイジングの検証は、資金管理を含めないと意味をなさない からです。
この辺りから 〝チャートを眺めて行うバックテストではできない領域〟 に入ってくると思います。以前まで行っていた検証に比べるとまだまだ機能が劣りますが(鋭意開発中)、何より計算が速い。機能をフルに盛り込んでも以前の100倍くらいの速さで行うことができそうです。楽しみ。
2018年8月19日 修正
値幅による損益の統計の記述を一部修正しました。
バックテストに使用したツールと価格データ
ここは過去に書いた記事とまったく一緒なので引用します。
使用したツール
Python(Google Colaboratory)
Pythonを手軽に試したいなら、Google Colaboratoryがめちゃくちゃオススメです。Google Driveでドキュメントやスプレッドシートを作る感覚でPythonを試すことができます。今回のような、ちゃちゃっと検証したいときに非常に便利です。
使用した価格データ
1分毎の価格データを含むcsvファイル
日経225
MT4のhstファイル
USDJPY、EURJPY、GBPJPY、AUDJPY、EURUSD、GBPUSD、AUDUSD
日経225は独自に保有しているもので、hstファイルはFXDDさんのものを使用しています。
テストする手法
今回も以前のロジックを一部流用しています。
今回のバックテ ストの目的
今回のバックテストは以下を目的として行った
- 資金管理を含めたバックテストの開発
- ATRの数値には素直に従うべきか(前回の宿題)
- 資金管理(サイジング)が成績に及ぼす影響の確認
開発にともなう変更点
今回の開発にともなって生じたバックテストの変更点
- 資金管理を含めたバックテストの導入
- 検証の期間の変更
これまでの検証期間は、元データが同一であるため「短期の手法の検証期間 > 長期の手法の検証期間」であったが、「長期の手法の検証期間」にあわせることとした - ティックごとのオペレーションの調整
先々の開発を見据えて1ティックごとのオペレーションを調整。それにともない売買回数や成績に若干の差異が生じたが、結果の本質には影響がないと考える(改めて入念な確認をしたため、今回のほうが正しい)
資金管理(サイジング)
今回のバックテストから導入する資金管理(サイジング)です。単利で、すべてのパターンで同一としています。
- 元金:1000万円
- 1エントリーのサイズ:1日のリスクが元金の1%(10万円)
となるように
で1ティックごとに算出しています。
これだけじゃわからない方は以前の記事をお読みください。
エントリー
今回は、次の2パターンのエントリーでバックテストを行いました。
ENTRY_Cycle63_FILTER_none
通常のパターン
ENTRY_Cycle63_FILTER_UpperCycle63
上位 足のフィルター有りのパターン
「ENTRY」は4時間足のステージで、「FILTER」は日足相当のステージです。
日足のトレンドを、4時間足のエントリーのフィルターとする
日足のトレンドを確認すると言っても毎回チャートを切り替えるのは手間なので、次の考え方を用います。以下は4時間足であっても、120本の移動平均線は20日相当、240本は40日相当になるということです。
- 4時間 ✕ 6 = 1日(24時間)
- 4時間 ✕ 120 = 20日
- 4時間 ✕ 240 = 40日
また、移動平均のもみ合い時の「だまし」を軽減するために、小次郎講師による移動平均線大循環分析の「ステージ」の考えを用います。
4時間足のトレンド
EMA5とEMA20、EMA40の関係でステージを判断する日足のトレンド
4時間足のEMA5とEMA120、EMA240の関係でステージを判断する上昇トレンド
ステージ6:早仕掛け、ステージ1:本仕掛け下降トレンド
ステージ3:早仕掛け、ステージ4:本仕掛け
決済1
決済1も以前と同じものです。
決済1は、同じく小次郎講師による移動平均線大循環分析の「ステージ」の考えに基づくものです。主に、「利益確定」や、「トレンドがなくなったことを確認した損切り」の決済です。
今回のバックテストでは、ステージによる決済は以下で統一しています。
EXIT1_CycleStage36
通常のパターン(エントリーが遅くなりがち)
買いエントリー(ステージ6か1)はステージ3で決済
売りエントリー(ステージ3か4)はステージ6で決済
決済2
決済2は前回と同じものをつかいます。
決済2(EXIT2)のパターン
none SO_Entry_3_UM SO_Close_3_UM SO_Entry_3_20 SO_Close_3_20 SO_Entry_2_UM SO_Close_2_UM SO_Entry_2_20 SO_Close_2_20
「none」とは
「none」は、ロスカットもトレイリングストップも設定しないパターンです。「ロスカットは必要か」を確認します。
「SO_Entry_N_」「SO_Close_N_」の意味
- 「固定ロスカットとトレイリングストップ」どちらが良いのか
- 「固定ロスカットの有効な幅」
- 「トレイリングストップの有効な幅」
を、確認します。
SO_Entry_N_
エントリーの価格から「N ✕ ATR」マイナス方向にロスカットを設置(固定)
例)SO_Entry_2_:エントリーから2-ATRマイナス方向SO_Close_N_
「N ✕ ATR」マイナス方向にロスカットを設置し、終値がプラス方向に推移 するごとに追随させる
例)SO_Close_3_:3-ATRマイナス方向に設置し、プラス方向に追随
「_20」「_UM」とは
この2つのパターンで「ATRの数値には素直に従うべきか」を確認します。
_20(ATR20)
ロスカットやトレイリングストップを「N ✕ 20日ATR」で算出する。_UM(Upper Middle of ATR20)
ロスカットやトレイリングストップの算出に使用するATRを、過去1800本さかのぼった20日ATRの最高値と最安値の中間以上の値とし(UM-ATR)、「N ✕ UM-ATR」で算出する。言葉で書くとややこしいので、次のグラフをご覧いただくのが良いと思います。
上がATR20、下がUM-ATRです。UM-ATRは、「ATR20 > 過去1800本最高値と最安値の中間」のときはATR20を、「ATR20 < 中間の値」のときは中間の値を使います。「なぜ、こんなことをするのか」については、次回の記事で解説したいと思います。
テストするパターン
ここも前回と一緒です。
Entry Filter Exit1 Exit2 1 Cycle63 none Cycle36 none 2 Cycle63 none Cycle36 SO_Entry_3_UM 3 Cycle63 none Cycle36 SO_Entry_3_20 4 Cycle63 none Cycle36 SO_Entry_2_UM 5 Cycle63 none Cycle36 SO_Entry_2_20 6 Cycle63 none Cycle36 SO_Close_3_UM 7 Cycle63 none Cycle36 SO_Close_3_20 8 Cycle63 none Cycle36 SO_Close_2_UM 9 Cycle63 none Cycle36 SO_Close_2_20 10 Cycle63 UpperCycle63 Cycle36 none 11 Cycle63 UpperCycle63 Cycle36 SO_Entry_3_UM 12 Cycle63 UpperCycle63 Cycle36 SO_Entry_3_20 13 Cycle63 UpperCycle63 Cycle36 SO_Entry_2_UM 14 Cycle63 UpperCycle63 Cycle36 SO_Entry_2_20 15 Cycle63 UpperCycle63 Cycle36 SO_Close_3_UM 16 Cycle63 UpperCycle63 Cycle36 SO_Close_3_20 17 Cycle63 UpperCycle63 Cycle36 SO_Close_2_UM 18 Cycle63 UpperCycle63 Cycle36 SO_Close_2_20
バックテストの実施と考察
バックテストの関数
ここが一番重要だったりするのですが、ものすごく長くなってしまうので割愛します。こちらのサイトのコードを参考に作成しました((´・ω・`;)ヒィィッ すいません「バックテストを試してみました」)
参考として、ストラテジー部分を掲載します。
class Strategy_CycleEMA_Base(StrategyBase) :
def __init__(self ,symbol ,np_arr_dic ,df) :
StrategyBase.__init__(self ,symbol ,np_arr_dic ,df)
self.principal = 10000000
self.unit_pct = 0.01
self.ema5 = ta.EMA(self.c ,5)
self.ema20 = ta.EMA(self.c ,20)
self.ema40 = ta.EMA(self.c ,40)
self.ema120 = ta.EMA(self.c ,120)
self.ema240 = ta.EMA(self.c ,240)
def calc_stage(s ,m ,l) :
return np.array(list(map(lambda s ,m ,l :
1 if s > m and m > l else \
2 if m > s and s > l else \
3 if m > l and l > s else \
4 if l > m and m > s else \
5 if l > s and s > m else \
6 if s > l and l > m else \
np.nan ,s ,m ,l)))
self.stage = calc_stage(self.ema5 ,self.ema20 ,self.ema40)
self.upper_stage = calc_stage(self.ema5 ,self.ema120 ,self.ema240)
self.atrL ,self.atrH = ta.MINMAX(self.atr20 ,1800)
self.atrM = (self.atrH + self.atrL) / 2
self.atrUM = np.array(list(map(lambda a ,b :
a if a > b else \
b if a < b else \
a if np.isnan(b)==True and np.isnan(a)==False else \
b if np.isnan(a)==True and np.isnan(b)==False else \
np.nan
,self.atr20 ,self.atrM)))
self.is_nan = np.isnan(self.ema240)
def management(self ,i ,Case=None) :
first = self.first_time
not_nan = not Case == 'is_nan'
Lot = Dict_Symbol[self.symbol]['lot']
Currency = 1 if Dict_Symbol[self.symbol]['currency']=="" else self.np_arr_dic[self.symbol]['Close'][i-1]
LS = self.l_s
b4asset = np.nan if first else self.asset[i-1]
b4mgmt = np.nan if first else self.mgmt[i-1]
ATR = np.nan if first else self.atr[i-1]
ATR_N = self.atrN
Entry = self.entry_price
Close = self.c[i-1]
def mgmt_calc_unit() :
if first : self.mgmt[i]['Unit'] = np.nan
elif Case=='is_nan' : self.mgmt[i]['Unit'] = b4mgmt['Unit']
else :
UnitValue = b4asset['UnitValue'] if Case=='1st' else self.asset[i]['UnitValue']
Unit = round( UnitValue / ( ATR * Lot * Currency) )
self.mgmt[i]['Unit'] = Unit if not_nan else b4mgmt['Unit']
def mgmt_append() :
if not_nan and not first :
Amount = b4mgmt["Amount"]
self.count_nums = np.nan if Amount==0 else self.count_nums + 1
b4_SO_Close = np.nan if Amount==0 else b4mgmt["SO_Close"]
b4_SO_Entry = np.nan if Amount==0 else b4mgmt["SO_Entry"]
pre_SO_Close = np.nan if Amount==0 else Close - ATR * ATR_N * LS
pre_SO_Entry = np.nan if Amount==0 else Entry - ATR * ATR_N * LS
SO_Close = np.nan if Amount==0 else pre_SO_Close if (LS==1 and pre_SO_Close > b4_SO_Close) or (LS==-1 and pre_SO_Close < b4_SO_Close) else b4_SO_Close
SO_Entry = np.nan if Amount==0 else pre_SO_Entry if (LS==1 and pre_SO_Entry > b4_SO_Entry) or (LS==-1 and pre_SO_Entry < b4_SO_Entry) else b4_SO_Entry
self.mgmt[i]['Time'] = self.df.index[i]
self.mgmt[i]['Symol'] = self.symbol
self.mgmt[i]['b4Open'] = np.nan if first else self.o[i-1] if not_nan else b4mgmt['b4Close']
self.mgmt[i]['b4High'] = np.nan if first else self.h[i-1] if not_nan else b4mgmt['b4Close']
self.mgmt[i]['b4Low'] = np.nan if first else self.l[i-1] if not_nan else b4mgmt['b4Close']
self.mgmt[i]['b4Close'] = np.nan if first else self.c[i-1] if not_nan else b4mgmt['b4Close']
self.mgmt[i]['b4ATR'] = np.nan if first else self.atr[i-1] if not_nan else b4mgmt['b4ATR']
self.mgmt[i]['b4EMA5'] = np.nan if first else self.ema5[i-1] if not_nan else b4mgmt['b4EMA5']
self.mgmt[i]['b4EMA20'] = np.nan if first else self.ema20[i-1] if not_nan else b4mgmt['b4EMA20']
self.mgmt[i]['b4EMA40'] = np.nan if first else self.ema40[i-1] if not_nan else b4mgmt['b4EMA40']
self.mgmt[i]['b4EMA120'] = np.nan if first else self.ema120[i-1] if not_nan else b4mgmt['b4EMA120']
self.mgmt[i]['b4EMA240'] = np.nan if first else self.ema240[i-1] if not_nan else b4mgmt['b4EMA240']
self.mgmt[i]['b4Stage'] = np.nan if first else self.stage[i-1] if not_nan else b4mgmt['b4Stage']
self.mgmt[i]['b4UpperStage'] = np.nan if first else self.upper_stage[i-1] if not_nan else b4mgmt['b4UpperStage']
self.mgmt[i]['Amount'] = 0 if first else Amount if not_nan else b4mgmt['Amount']
self.mgmt[i]['CountNums'] = self.count_nums
self.mgmt[i]['EntrySig'] = 0
self.mgmt[i]['ExitSig'] = 0
self.mgmt[i]['L/S'] = LS
self.mgmt[i]['Lot'] = Lot
self.mgmt[i]['EntryPrice'] = Entry
self.mgmt[i]['ExitPrice'] = np.nan
self.mgmt[i]['b4Currency'] = Currency
self.mgmt[i]['SO'] = self.sosig
self.mgmt[i]['SO_Close'] = np.nan if first else SO_Close if not_nan else b4mgmt['SO_Close']
self.mgmt[i]['SO_Entry'] = np.nan if first else SO_Entry if not_nan else b4mgmt['SO_Entry']
self.mgmt[i]['MTM_'] = 0
self.mgmt[i]['MTM'] = 0
self.mgmt[i]['PL_'] = 0
self.mgmt[i]['PL'] = 0
def asset_count_n() :
pass
def asset_append() :
if not_nan and not first :
Total_PL = self.mgmt[i]['PL']
Total_MTM = self.mgmt[i]['MTM']
Cash = b4asset['Cash'] + Total_PL
Net = Cash + Total_MTM
MAX_Cash = Cash if Cash > b4asset['MAX_Cash'] else b4asset['MAX_Cash']
MAX_Net = Net if Net > b4asset['MAX_Net'] else b4asset['MAX_Net']
DD_Cash = Cash - MAX_Cash
DD_Net = Net - MAX_Net
DD_pct_Cash = DD_Cash / MAX_Cash
DD_pct_Net = DD_Net / MAX_Net
UnitValue = self.principal * self.unit_pct
self.asset[i]['Time'] = self.df.index[i]
self.asset[i]['Total_PL'] = 0 if first else Total_PL if not_nan else b4asset['Total_PL']
self.asset[i]['Total_MTM'] = 0 if first else Total_MTM if not_nan else b4asset['Total_MTM']
self.asset[i]['Cash'] = self.principal if first else Cash if not_nan else b4asset['Cash']
self.asset[i]['Net'] = self.principal if first else Net if not_nan else b4asset['Net']
self.asset[i]['MAX_Cash'] = self.principal if first else MAX_Cash if not_nan else b4asset['MAX_Cash']
self.asset[i]['MAX_Net'] = self.principal if first else MAX_Net if not_nan else b4asset['MAX_Net']
self.asset[i]['DD_Cash'] = 0 if first else DD_Cash if not_nan else b4asset['DD_Cash']
self.asset[i]['DD_Net'] = 0 if first else DD_Net if not_nan else b4asset['DD_Net']
self.asset[i]['DD_pct_Cash'] = 0 if first else DD_pct_Cash if not_nan else b4asset['DD_pct_Cash']
self.asset[i]['DD_pct_Net'] = 0 if first else DD_pct_Net if not_nan else b4asset['DD_pct_Net']
self.asset[i]['UnitValue'] = self.principal * self.unit_pct if first else UnitValue if not_nan else b4asset['UnitValue']
if Case=='is_nan' or first:
mgmt_append()
mgmt_calc_unit()
asset_append()
asset_count_n()
if first and not self.is_nan[i+1] : self.first_time = False
elif Case=='1st' :
mgmt_append()
asset_count_n()
elif Case=='2nd' :
self.mark_to_market(i)
asset_append()
mgmt_calc_unit()
asset_count_n()
self.count_correl_risk(i)
def entry_sig(self ,i) :
if self.FILTER=='none' :
buy_filter = sell_filter = True
elif self.FILTER=='UpperCycle63' :
buy_filter = self.mgmt[i]['b4UpperStage'] == 6 or self.mgmt[i]['b4UpperStage'] == 1
sell_filter = self.mgmt[i]['b4UpperStage'] == 3 or self.mgmt[i]['b4UpperStage'] == 4
buy_sig = self.mgmt[i]['b4Stage'] == 6 or self.mgmt[i]['b4Stage'] == 1
sell_sig = self.mgmt[i]['b4Stage'] == 3 or self.mgmt[i]['b4Stage'] == 4
if all([buy_filter ,buy_sig ,self.count_buy()==0]) : self.opsig = self.mgmt[i]['EntrySig'] = 1
elif all([sell_filter ,sell_sig ,self.count_sell()==0]) : self.opsig = self.mgmt[i]['EntrySig'] = -1
def exit_sig(self ,i) :
self.sosig = np.nan
if self.count_buy() > 0 :
clbuy = self.mgmt[i-1]['b4Stage'] < 3 and ( self.mgmt[i]['b4Stage'] == 3 or self.mgmt[i]['b4Stage'] == 4 )
if not self.EXIT2=='none' and self.mgmt[i]['b4Low'] < self.mgmt[i-1][self.EXIT2] : self.sosig = 1
if any([clbuy ,self.sosig==1 ,self.opsig==-1]) : self.clsig = self.mgmt[i]['ExitSig'] = 1
elif self.count_sell() > 0 :
clsell = ( self.mgmt[i-1]['b4Stage'] < 6 and self.mgmt[i-1]['b4Stage'] >= 4 ) and ( self.mgmt[i]['b4Stage'] == 6 or self.mgmt[i]['b4Stage'] == 1 )
if not self.EXIT2=='none' and self.mgmt[i]['b4High'] > self.mgmt[i-1][self.EXIT2] : self.sosig = 1
if any([clsell ,self.sosig==1 ,self.opsig==1]) : self.clsig = self.mgmt[i]['ExitSig'] = 1
def onTick_Base(self ,i) :
self.append_dict(i)
if self.is_nan[i] or self.first_time :
self.management(i ,Case='is_nan')
return
self.management(i ,Case='1st')
self.entry_sig(i)
self.exit_sig(i)
self.exit(i)
self.management(i ,Case='2nd')
self.entry(i)
class ENTRY_Cycle63__FILTER_none__EXIT1_Cycle36__EXIT2_none(Strategy_CycleEMA_Base) :
def __init__(self ,symbol ,np_arr_dic ,df) :
Strategy_CycleEMA_Base.__init__(self ,symbol ,np_arr_dic ,df)
self.first_time = True
self.opcl = 'close'
self.atr = self.atrUM
self.atrN = 3
self.EXIT2 = 'none'
self.FILTER = 'none'
def onTick(self ,i) : self.onTick_Base(i)
class ENTRY_Cycle63__FILTER_none__EXIT1_Cycle36__EXIT2_SO_Entry_3_UM(Strategy_CycleEMA_Base) :
def __init__(self ,symbol ,np_arr_dic ,df) :
Strategy_CycleEMA_Base.__init__(self ,symbol ,np_arr_dic ,df)
self.first_time = True
self.opcl = 'close'
self.atr = self.atrUM
self.atrN = 3
self.EXIT2 = 'SO_Entry'
self.FILTER = 'none'
def onTick(self ,i) : self.onTick_Base(i)
class ENTRY_Cycle63__FILTER_none__EXIT1_Cycle36__EXIT2_SO_Entry_3_20(Strategy_CycleEMA_Base) :
def __init__(self ,symbol ,np_arr_dic ,df) :
Strategy_CycleEMA_Base.__init__(self ,symbol ,np_arr_dic ,df)
self.first_time = True
self.opcl = 'close'
self.atr = self.atr20
self.atrN = 3
self.EXIT2 = 'SO_Entry'
self.FILTER = 'none'
def onTick(self ,i) : self.onTick_Base(i)
class ENTRY_Cycle63__FILTER_none__EXIT1_Cycle36__EXIT2_SO_Entry_2_UM(Strategy_CycleEMA_Base) :
def __init__(self ,symbol ,np_arr_dic ,df) :
Strategy_CycleEMA_Base.__init__(self ,symbol ,np_arr_dic ,df)
self.first_time = True
self.opcl = 'close'
self.atr = self.atrUM
self.atrN = 2
self.EXIT2 = 'SO_Entry'
self.FILTER = 'none'
def onTick(self ,i) : self.onTick_Base(i)
class ENTRY_Cycle63__FILTER_none__EXIT1_Cycle36__EXIT2_SO_Entry_2_20(Strategy_CycleEMA_Base) :
def __init__(self ,symbol ,np_arr_dic ,df) :
Strategy_CycleEMA_Base.__init__(self ,symbol ,np_arr_dic ,df)
self.first_time = True
self.opcl = 'close'
self.atr = self.atr20
self.atrN = 2
self.EXIT2 = 'SO_Entry'
self.FILTER = 'none'
def onTick(self ,i) : self.onTick_Base(i)
class ENTRY_Cycle63__FILTER_none__EXIT1_Cycle36__EXIT2_SO_Close_3_UM(Strategy_CycleEMA_Base) :
def __init__(self ,symbol ,np_arr_dic ,df) :
Strategy_CycleEMA_Base.__init__(self ,symbol ,np_arr_dic ,df)
self.first_time = True
self.opcl = 'close'
self.atr = self.atrUM
self.atrN = 3
self.EXIT2 = 'SO_Close'
self.FILTER = 'none'
def onTick(self ,i) : self.onTick_Base(i)
class ENTRY_Cycle63__FILTER_none__EXIT1_Cycle36__EXIT2_SO_Close_3_20(Strategy_CycleEMA_Base) :
def __init__(self ,symbol ,np_arr_dic ,df) :
Strategy_CycleEMA_Base.__init__(self ,symbol ,np_arr_dic ,df)
self.first_time = True
self.opcl = 'close'
self.atr = self.atr20
self.atrN = 3
self.EXIT2 = 'SO_Close'
self.FILTER = 'none'
def onTick(self ,i) : self.onTick_Base(i)
class ENTRY_Cycle63__FILTER_none__EXIT1_Cycle36__EXIT2_SO_Close_2_UM(Strategy_CycleEMA_Base) :
def __init__(self ,symbol ,np_arr_dic ,df) :
Strategy_CycleEMA_Base.__init__(self ,symbol ,np_arr_dic ,df)
self.first_time = True
self.opcl = 'close'
self.atr = self.atrUM
self.atrN = 2
self.EXIT2 = 'SO_Close'
self.FILTER = 'none'
def onTick(self ,i) : self.onTick_Base(i)
class ENTRY_Cycle63__FILTER_none__EXIT1_Cycle36__EXIT2_SO_Close_2_20(Strategy_CycleEMA_Base) :
def __init__(self ,symbol ,np_arr_dic ,df) :
Strategy_CycleEMA_Base.__init__(self ,symbol ,np_arr_dic ,df)
self.first_time = True
self.opcl = 'close'
self.atr = self.atr20
self.atrN = 2
self.EXIT2 = 'SO_Close'
self.FILTER = 'none'
def onTick(self ,i) : self.onTick_Base(i)
class ENTRY_Cycle63__FILTER_UpperCycle63__EXIT1_Cycle36__EXIT2_none(Strategy_CycleEMA_Base) :
def __init__(self ,symbol ,np_arr_dic ,df) :
Strategy_CycleEMA_Base.__init__(self ,symbol ,np_arr_dic ,df)
self.first_time = True
self.opcl = 'close'
self.atr = self.atrUM
self.atrN = 3
self.EXIT2 = 'none'
self.FILTER = 'UpperCycle63'
def onTick(self ,i) : self.onTick_Base(i)
class ENTRY_Cycle63__FILTER_UpperCycle63__EXIT1_Cycle36__EXIT2_SO_Entry_3_UM(Strategy_CycleEMA_Base) :
def __init__(self ,symbol ,np_arr_dic ,df) :
Strategy_CycleEMA_Base.__init__(self ,symbol ,np_arr_dic ,df)
self.first_time = True
self.opcl = 'close'
self.atr = self.atrUM
self.atrN = 3
self.EXIT2 = 'SO_Entry'
self.FILTER = 'UpperCycle63'
def onTick(self ,i) : self.onTick_Base(i)
class ENTRY_Cycle63__FILTER_UpperCycle63__EXIT1_Cycle36__EXIT2_SO_Entry_3_20(Strategy_CycleEMA_Base) :
def __init__(self ,symbol ,np_arr_dic ,df) :
Strategy_CycleEMA_Base.__init__(self ,symbol ,np_arr_dic ,df)
self.first_time = True
self.opcl = 'close'
self.atr = self.atr20
self.atrN = 3
self.EXIT2 = 'SO_Entry'
self.FILTER = 'UpperCycle63'
def onTick(self ,i) : self.onTick_Base(i)
class ENTRY_Cycle63__FILTER_UpperCycle63__EXIT1_Cycle36__EXIT2_SO_Entry_2_UM(Strategy_CycleEMA_Base) :
def __init__(self ,symbol ,np_arr_dic ,df) :
Strategy_CycleEMA_Base.__init__(self ,symbol ,np_arr_dic ,df)
self.first_time = True
self.opcl = 'close'
self.atr = self.atrUM
self.atrN = 2
self.EXIT2 = 'SO_Entry'
self.FILTER = 'UpperCycle63'
def onTick(self ,i) : self.onTick_Base(i)
class ENTRY_Cycle63__FILTER_UpperCycle63__EXIT1_Cycle36__EXIT2_SO_Entry_2_20(Strategy_CycleEMA_Base) :
def __init__(self ,symbol ,np_arr_dic ,df) :
Strategy_CycleEMA_Base.__init__(self ,symbol ,np_arr_dic ,df)
self.first_time = True
self.opcl = 'close'
self.atr = self.atr20
self.atrN = 2
self.EXIT2 = 'SO_Entry'
self.FILTER = 'UpperCycle63'
def onTick(self ,i) : self.onTick_Base(i)
class ENTRY_Cycle63__FILTER_UpperCycle63__EXIT1_Cycle36__EXIT2_SO_Close_3_UM(Strategy_CycleEMA_Base) :
def __init__(self ,symbol ,np_arr_dic ,df) :
Strategy_CycleEMA_Base.__init__(self ,symbol ,np_arr_dic ,df)
self.first_time = True
self.opcl = 'close'
self.atr = self.atrUM
self.atrN = 3
self.EXIT2 = 'SO_Close'
self.FILTER = 'UpperCycle63'
def onTick(self ,i) : self.onTick_Base(i)
class ENTRY_Cycle63__FILTER_UpperCycle63__EXIT1_Cycle36__EXIT2_SO_Close_3_20(Strategy_CycleEMA_Base) :
def __init__(self ,symbol ,np_arr_dic ,df) :
Strategy_CycleEMA_Base.__init__(self ,symbol ,np_arr_dic ,df)
self.first_time = True
self.opcl = 'close'
self.atr = self.atr20
self.atrN = 3
self.EXIT2 = 'SO_Close'
self.FILTER = 'UpperCycle63'
def onTick(self ,i) : self.onTick_Base(i)
class ENTRY_Cycle63__FILTER_UpperCycle63__EXIT1_Cycle36__EXIT2_SO_Close_2_UM(Strategy_CycleEMA_Base) :
def __init__(self ,symbol ,np_arr_dic ,df) :
Strategy_CycleEMA_Base.__init__(self ,symbol ,np_arr_dic ,df)
self.first_time = True
self.opcl = 'close'
self.atr = self.atrUM
self.atrN = 2
self.EXIT2 = 'SO_Close'
self.FILTER = 'UpperCycle63'
def onTick(self ,i) : self.onTick_Base(i)
class ENTRY_Cycle63__FILTER_UpperCycle63__EXIT1_Cycle36__EXIT2_SO_Close_2_20(Strategy_CycleEMA_Base) :
def __init__(self ,symbol ,np_arr_dic ,df) :
Strategy_CycleEMA_Base.__init__(self ,symbol ,np_arr_dic ,df)
self.first_time = True
self.opcl = 'close'
self.atr = self.atr20
self.atrN = 2
self.EXIT2 = 'SO_Close'
self.FILTER = 'UpperCycle63'
def onTick(self ,i) : self.onTick_Base(i)
バックテストの実行と結果
諸々の準備が整ったら、バックテストを実行します。4分程度で計算できてしまいます。すごい。
| Entry | Filter | Exit1 | Exit2 | |
|---|---|---|---|---|
| 1 | Cycle63 | none | Cycle36 | none |
| 2 | Cycle63 | none | Cycle36 | SO_Entry_3_UM |
| 3 | Cycle63 | none | Cycle36 | SO_Entry_3_20 |
| 4 | Cycle63 | none | Cycle36 | SO_Entry_2_UM |
| 5 | Cycle63 | none | Cycle36 | SO_Entry_2_20 |
| 6 | Cycle63 | none | Cycle36 | SO_Close_3_UM |
| 7 | Cycle63 | none | Cycle36 | SO_Close_3_20 |
| 8 | Cycle63 | none | Cycle36 | SO_Close_2_UM |
| 9 | Cycle63 | none | Cycle36 | SO_Close_2_20 |
| 10 | Cycle63 | UpperCycle63 | Cycle36 | none |
| 11 | Cycle63 | UpperCycle63 | Cycle36 | SO_Entry_3_UM |
| 12 | Cycle63 | UpperCycle63 | Cycle36 | SO_Entry_3_20 |
| 13 | Cycle63 | UpperCycle63 | Cycle36 | SO_Entry_2_UM |
| 14 | Cycle63 | UpperCycle63 | Cycle36 | SO_Entry_2_20 |
| 15 | Cycle63 | UpperCycle63 | Cycle36 | SO_Close_3_UM |
| 16 | Cycle63 | UpperCycle63 | Cycle36 | SO_Close_3_20 |
| 17 | Cycle63 | UpperCycle63 | Cycle36 | SO_Close_2_UM |
| 18 | Cycle63 | UpperCycle63 | Cycle36 | SO_Close_2_20 |
