forbbs 發表於 12-11-1 21:16

请问explore出信号和backtest实际信号不一致是怎么回事呢

请看,explore信号里没有过滤重复信号,基本上从9:03:00-11:24:00都有信号。而backtest里却有好几段时间都没有动作:

10:03:00-10:36:00;


10:42:00-11:00:00;

calvinhorng 發表於 12-11-1 21:39

我回測要先看是不是有過大的虧損造成Backtest 無法繼續測試下去

BackTest 與Explorer最大的不同是
Backtest 有資金與部位的問題
可能要檢查一下你的 SetPositionSize
或 SetOption( field, value ) 等等的設定

建議你先試一口限定方式
SetPositionSize(1, spsShares);
SetOption("InitialEquity", 50000000 ); // 大到不會虧完
SetOption("MaxOpenPositions", 1 );

希望你可以看到一致的結果

joshsmi 發表於 12-11-2 03:54

本帖最後由 joshsmi 於 12-11-2 03:57 編輯

@forbbs,

Default exploration just outputs signals but backtest includes other parameters. Also if your system is a loser and you have no capital anymore you are broke just like in real life. So the trading in backtester stops. But exploration in default mode still outputs signals of the same system and doesn't take such parameters into account.

If default Exploration would be the same as Backtest then Exploration wouldn't be called Exploration, right?

But it is possible to copy Backtester if using Equity() function in Exploration. Read about that function's settings.

Here is an example showing backtest in advanced exploration mode.

http://img59.imageshack.us/img59/6364/explorationbacktest.png

joshsmi 發表於 12-11-2 04:17

Here is a very simple example// dummy system
Buy      = Cross( MA(Close, 12) , MA( Close, 24) );
Sell   = Cross( MA(Close, 24) , MA( Close, 12) );

Short    = 0;
Cover    = 0;

BuyPrice = SellPrice = C;
// dummy system

Equity( 1 ); // see options in the Help file

format   = 1.5;
width    = 65;
Filter   = Buy || Sell;

SetOption( "NoDefaultColumns", True );
AddTextColumn( Name(), "Ticker", 1.0, 47, 23, width );
AddColumn( DateTime(), "Date/Time", formatDateTime, 47, 23, 115 );
AddColumn( IIf( Buy, BuyPrice, Null ), "Buyprice", 1.5, 47, 23, 80 );
AddColumn( IIf( Sell, SellPrice, Null ), "Sellprice", 1.5, 47, 23, 80 );Exploration
http://img840.imageshack.us/img840/4749/exploration.png

Backtest
http://img802.imageshack.us/img802/180/backtest.png

forbbs 發表於 12-11-2 23:44

本帖最後由 forbbs 於 12-11-3 00:00 編輯

多谢各位回复。
我回测时候如果只加SetPositionSize(1, spsShares);
SetOption("InitialEquity", 50000000 ); // 大到不會虧完
SetOption("MaxOpenPositions", 1 ); explore的信号与backtest结果还是不一致。backtest依然有那些空闲间隔,也就是对于某些explore信号无动于衷。

只有加上“Equity( 1 );”
explore结果接近backtest一致点,但逐个分析仍有细微差别。不过应该这基本就是答案了,感谢两位

joshsmi 發表於 12-11-3 01:35

本帖最後由 joshsmi 於 12-11-3 01:37 編輯

Could someone please translate forbbs last reply into English, please! Google translator is not the best. :-)



Besides that here I provide a more advanced code example to show backtest results in Exploration
// --- code by joshsmi ---

// dummy system
Buy      = Cross( MA( Close, 12 ) , MA( Close, 24 ) );
Sell   = Cross( MA( Close, 24 ) , MA( Close, 12 ) );

Short    = 0;
Cover    = 0;

BuyPrice = SellPrice = O; // entry at next bar's open, see settradedelays below
//ShortPrice = CoverPrice = O;
// dummy system

SetBacktestMode( backtestRegular );
SetOption( "FuturesMode", True );
SetOption( "InitialEquity", 100000 );
SetPositionSize( 20, spsPercentOfEquity );
SetTradeDelays( 1, 1, 1, 1 ); // check Equity( ... ) below

if ( Status( "action" ) == actionExplore )
{
    dt      = DateTime();
    eq      = Equity( 2 ); // Use "1" if SetTradeDelays( 0, 0, 0, 0 ). Use flag "2" if SetTradeDelays != 0. But flag 2 setting should be used carefully

    SellCov   = Sell || Cover;

    entrydate = IIf( Sell, ValueWhen( Buy, dt ), IIf( Cover, ValueWhen( Short, dt ), Null ) );
    profit    = IIf( Sell, ValueWhen( Sell, eq ) - ValueWhen( Buy, eq ), /*Short*/IIf( Cover, ValueWhen( Cover, eq ) - ValueWhen( Short, eq ), 0 ) );
    cumprof   = Cum( profit );
    Diffsell= ( ValueWhen( Sell, SellPrice ) - ValueWhen( Buy, BuyPrice ) ) / TickSize;
    Diffcov   = ( ValueWhen( Cover, CoverPrice ) - ValueWhen( Short, ShortPrice ) ) / TickSize;

    format    = 1.4; // decimal places of Ticker
    width   = 70;// column width
    Filter    = SellCov;   

    SetOption( "NoDefaultColumns", True );
    AddTextColumn( Name(),"Ticker", 1.0, 47, 23, width );
    AddColumn( IIf( Sell, 76, IIf( Cover, 83, 32) ), "Trade", formatChar, 47, IIf( Sell, 19, IIf( Cover, 24, 23 ) ) );
    AddColumn( entrydate, "Entry Date/Time", formatDateTime, 47, 23, 115 );
    AddColumn( dt, "Exit Date/Time", formatDateTime, 47, 23, 115 );
    AddColumn( IIf( Sell, ValueWhen( Buy, BuyPrice ), Null), "Buy@", format, 47, 19, width );
    AddColumn( IIf( Sell, SellPrice, Null ), "Sell@", format, 23, 25, width );
    AddColumn( IIf( Sell, Diffsell, Null ), "abs. Diff", 1.2, IIf( diffsell >= 0, 43, 32 ), 23, width );
    /*AddColumn( IIf( Cover, ValueWhen( Short, ShortPrice ), Null ), "Short@", format, 47, 24, width );
    AddColumn( IIf( Cover, CoverPrice, Null ), "Cover@", format, 23, 36, width );
    AddColumn( IIf( Cover, Diffcov, Null ), "abs. Diff", 1.2, IIf( diffcov >= 0, 43, 32 ), 23, width );*/
    AddColumn( IIf( SellCov, profit, Null ), "Profit", 1.2, IIf( profit >= 0, 43, 32 ), 23, width );
    AddColumn( IIf( SellCov, cumprof, Null ), "Cum. Profit", 1.2, IIf( cumprof >= 0, 43, 32 ), 23, width );
    AddColumn( IIf( SellCov, Eq, Null ), "Equity", 1.2, 47, 23, width );
}
http://is.gd/eN3auE

forbbs 發表於 12-11-3 21:03

Hi,joshsmi.If I add following code only,the difference between explore rusults and bacetest results is still there.It change nothing.SetPositionSize(1, spsShares);
SetOption("InitialEquity", 50000000 ); // 大到不會虧完
SetOption("MaxOpenPositions", 1 ); But if I add “Equity( 1 )”,there is little difference between explore and backtest results.I believe it's the point.Thank you!

I also tried your more advanced code example,but I get no results in explore or backtest,what's the problem?Your very simple example can work.

forbbs 發表於 12-11-3 21:11

Additional question:
Do you know how can I refrence the OHLC at specific intraday time in backtest?
I tried:mydatetime=DateTimeConvert( 2, DateNum(), 090000 );
Openprice=Lookup( O, mydatetime);
//get 9:00's openprice respective dayBut it reports error,seems array & number confusedness.

joshsmi 發表於 12-11-3 23:29


I also tried your more advanced code example,but I get no results in explore or backtest,what's the problem?Your very simple example can work.

The code uses Ticksize and Futuresmode is set to true.
If you are using stocks than set Futuresmode to False. Set Ticksize in Information window or delete Ticksize from the codeand try again.

If you still have the same problem then please upload the data of your Symbol. Go to the data base folder and there go the subfolder that has the first letter of your symbol.

Normally the code should work just fine. I have tested it for Stocks and Forex.



joshsmi 發表於 12-11-3 23:56

本帖最後由 joshsmi 於 12-11-4 00:20 編輯

Additional question:
Do you know how can I refrence the OHLC at specific intraday time in backtest?
I tried:
[*]mydatetime=DateTimeConvert( 2, DateNum(), 090000 );
[*]Openprice=Lookup( O, mydatetime);
[*]//get 9:00's openprice respective day



But it reports error,seems array & number confusedness.
Lookup searches for specified datetime. So you datenum is wrong.

This code looks for specific date and time

dn = ParamDate( "Date", "2012-10-30", 0 );
tn = ParamTime( "Time", "09:00:00" );

mydatetime = DateTimeConvert( 2, dn, tn );
Openprice = Lookup( O, mydatetime );

Filter = DateTime() == mydatetime;

AddColumn(Openprice,"Open", 1.4);


This code searches for all same Open prices that occured at dates lower or equal to specified date time


dn = ParamDate( "Date", "2012-10-30", 0 );
tn = ParamTime( "Time", "09:00:00" );

mydatetime = DateTimeConvert( 2, dn, tn );
Openprice = Lookup( O, mydatetime );

Filter = O == Openprice;

AddColumn(Openprice,"Open", 1.4);

This code searches all open prices that occurred at specified time


sTime = ParamTime("Time to search", "09:00:00");

SetOption( "NoDefaultColumns", True );
SetSortColumns( -3 );

Filter = TimeNum() == stime;

AddTextColumn( Name(), "Ticker", 1.0, colorWhite, colorDarkGrey, 70 );
AddColumn( DayOfWeek(), "WKD", 1.0, colorWhite, colorDarkGrey, 35 );
AddColumn( DateTime(), "Date/Time", formatDateTime, colorBlack, colorGrey50, 120 );
AddColumn( Open, "Close" , 1.4, colorWhite, colorDarkGrey, 100 );




forbbs 發表於 12-11-4 11:18

本帖最後由 forbbs 於 12-11-4 11:20 編輯

Thank you very much for the detailed explaination!I have get example worked,the explore and backtest results are exactly same now.I learned much,Thank you!

About "Lookup",Seems I didn't get the problem clear.I want use open price value at 9:00 in respective day to produce the day's intraday buy/short signal for explore or backtest.like this:
mydatetime=DateTimeConvert( 2, DateNum(), 090000 );
Openprice=Lookup( O, mydatetime);
if(openprice>13.00)
signal=buy;
else
signal=short;

joshsmi 發表於 12-11-4 19:33

I'm still not quite sure what exactly you are trying to do. Do you want the buy condition to be true every day?


start = TimeNum() == 090000;
Buy = Open > 13.00 AND start;
Short =Open < 13.00 AND start;

forbbs 發表於 12-11-7 22:06

I want it be used in backtest.This is a gross simplification of other code that simply demonstrates.mydatetime=DateTimeConvert( 2, DateNum(), 090000 );
Openprice=Lookup( O, mydatetime);
if(some condition and timenum()==100000 and openprice>13.00)
signal=buy;
else
signal=short;
頁: [1]
查看完整版本: 请问explore出信号和backtest实际信号不一致是怎么回事呢