本帖最後由 skyler 於 14-11-5 18:56 編輯
寫了一個很簡單的範例
結果不多說直接看圖
short ZSTime = 2014/11/04 01:00:00
short price = 1038
backtesting result
short price = 1035
2014/11/04 01:00:00
H = 1035
---------
AFL Test code
_SECTION_BEGIN( "Product Settings" );
{
SetPositionSize( 1 , spsShares );
SetOption( "MaxOpenPositions" , 1 );
SetOption( "InitialEquity" , 5000 );
SetOption( "FuturesMode" , 1 );
SetOption( "CommissionMode" , 3 );
SetOption( "CommissionAmount" , 2.5 );
RoundLotSize = 1;
newName = strmid( Name (), 0, 2 );
if ( newName == "ZS" )
{
TickSize = 0.25;
MarginDeposit = 3750;
PS = 100;
PointValue = 0.5 * PS;
}
}
_SECTION_END();
_SECTION_BEGIN( "Logic" );
{
//前K價格
O_P1 = Ref( O, -1 );
C_P1 = Ref( C, -1 );
H_P1 = Ref( H, -1 );
L_P1 = Ref( L, -1 );
MA5_P1 = Ref( MA( C, 5 ), -1 );
MA5_P2 = Ref( MA( C, 5 ), -2 );
MA20_P1 = Ref( MA( C, 20 ), -1 );
MA20_P2 = Ref( MA( C, 20 ), -2 );
Buy = MA5_P1 > MA5_P2 AND MA20_P1 > MA20_P2 and Cross(C_P1, MA5_P1);
Sell = MA5_P2 > MA5_P1;
Short = MA5_P2 > MA5_P1 AND MA20_P2 > MA20_P1 and Cross(MA5_P1, C_P1);
Cover = MA5_P1 > MA5_P2;
Buy = ExRem( Buy, Sell );
Sell = ExRem( Sell , Buy );
Short = ExRem( Short, Cover );
Cover = ExRem( Cover , Short );
BuyPrice = (L_P1 + 7 * TickSize ) ;
SellPrice = ( O - 2 * TickSize );
ShortPrice = (H_P1 - 7 * TickSize );
CoverPrice = ( O + 2 * TickSize );
Filter = Buy OR Short;
AddColumn( Buy, "Buy", 1 );
AddColumn( Sell, "Sell", 1 );
AddColumn( Short, "Short", 1 );
AddColumn( Cover, "Cover", 1 );
AddColumn( L_P1, "L_P1", 1.2 );
AddColumn( TickSize, "TickSize", 1.2 );
AddColumn( BuyPrice, "BuyPrice(L_P1 + 7 * TickSize )", 1.2 );
AddColumn( H_P1, "H_P1", 1.2 );
AddColumn( TickSize, "TickSize", 1.2 );
AddColumn( ShortPrice, "ShortPrice( H_P1 - 7 * TickSize )", 1.2 );
}
_SECTION_END();
------------------------------
有自定義進場價格
最好是多看看回測的入場價是否合理
不然
回測結果與真實情況
的差異大到讓你吐血
------------------------------
WTF
本來實在是不太想理會某人
即然這麼想要檔案
我就附上如下
Backtester_ settings.zip
(362 Bytes, 下載次數: 344)
Analysis1.zip
(2.25 KB, 下載次數: 308)
Explore.zip
(2.25 KB, 下載次數: 296)
|