COCO研究院

 找回密碼
 註冊
搜索
查看: 2623|回復: 12

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

[複製鏈接]
發表於 12-11-1 21:16 | 顯示全部樓層 |閱讀模式
请看,explore信号里没有过滤重复信号,基本上从9:03:00-11:24:00都有信号。而backtest里却有好几段时间都没有动作:

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


10:42:00-11:00:00;
explore.png backtest.png
發表於 12-11-1 21:39 | 顯示全部樓層
我回測要先看是不是有過大的虧損造成Backtest 無法繼續測試下去

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

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

希望你可以看到一致的結果
發表於 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.



發表於 12-11-2 04:17 | 顯示全部樓層
Here is a very simple example
  1. // dummy system
  2. Buy      = Cross( MA(Close, 12) , MA( Close, 24) );
  3. Sell     = Cross( MA(Close, 24) , MA( Close, 12) );

  4. Short    = 0;
  5. Cover    = 0;

  6. BuyPrice = SellPrice = C;
  7. // dummy system

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

  9. format   = 1.5;
  10. width    = 65;
  11. Filter   = Buy || Sell;

  12. SetOption( "NoDefaultColumns", True );
  13. AddTextColumn( Name(), "Ticker", 1.0, 47, 23, width );
  14. AddColumn( DateTime(), "Date/Time", formatDateTime, 47, 23, 115 );
  15. AddColumn( IIf( Buy, BuyPrice, Null ), "Buyprice", 1.5, 47, 23, 80 );
  16. AddColumn( IIf( Sell, SellPrice, Null ), "Sellprice", 1.5, 47, 23, 80 );
複製代碼
Exploration


Backtest
 樓主| 發表於 12-11-2 23:44 | 顯示全部樓層
本帖最後由 forbbs 於 12-11-3 00:00 編輯

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

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

  1. // --- code by joshsmi ---

  2. // dummy system
  3. Buy      = Cross( MA( Close, 12 ) , MA( Close, 24 ) );
  4. Sell     = Cross( MA( Close, 24 ) , MA( Close, 12 ) );

  5. Short    = 0;
  6. Cover    = 0;

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

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

  15. if ( Status( "action" ) == actionExplore )
  16. {
  17.     dt        = DateTime();
  18.     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

  19.     SellCov   = Sell || Cover;

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

  25.     format    = 1.4; // decimal places of Ticker
  26.     width     = 70;  // column width
  27.     Filter    = SellCov;   

  28.     SetOption( "NoDefaultColumns", True );
  29.     AddTextColumn( Name(),"Ticker", 1.0, 47, 23, width );
  30.     AddColumn( IIf( Sell, 76, IIf( Cover, 83, 32) ), "Trade", formatChar, 47, IIf( Sell, 19, IIf( Cover, 24, 23 ) ) );
  31.     AddColumn( entrydate, "Entry Date/Time", formatDateTime, 47, 23, 115 );
  32.     AddColumn( dt, "Exit Date/Time", formatDateTime, 47, 23, 115 );
  33.     AddColumn( IIf( Sell, ValueWhen( Buy, BuyPrice ), Null), "Buy@", format, 47, 19, width );
  34.     AddColumn( IIf( Sell, SellPrice, Null ), "Sell@", format, 23, 25, width );
  35.     AddColumn( IIf( Sell, Diffsell, Null ), "abs. Diff", 1.2, IIf( diffsell >= 0, 43, 32 ), 23, width );
  36.     /*AddColumn( IIf( Cover, ValueWhen( Short, ShortPrice ), Null ), "Short@", format, 47, 24, width );
  37.     AddColumn( IIf( Cover, CoverPrice, Null ), "Cover@", format, 23, 36, width );
  38.     AddColumn( IIf( Cover, Diffcov, Null ), "abs. Diff", 1.2, IIf( diffcov >= 0, 43, 32 ), 23, width );*/
  39.     AddColumn( IIf( SellCov, profit, Null ), "Profit", 1.2, IIf( profit >= 0, 43, 32 ), 23, width );
  40.     AddColumn( IIf( SellCov, cumprof, Null ), "Cum. Profit", 1.2, IIf( cumprof >= 0, 43, 32 ), 23, width );
  41.     AddColumn( IIf( SellCov, Eq, Null ), "Equity", 1.2, 47, 23, width );
  42. }
複製代碼
 樓主| 發表於 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.
  1. SetPositionSize(1, spsShares);
  2. SetOption("InitialEquity", 50000000 ); // 大到不會虧完
  3. 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.
 樓主| 發表於 12-11-3 21:11 | 顯示全部樓層
Additional question:
Do you know how can I refrence the OHLC at specific intraday time in backtest?
I tried:
  1. mydatetime=DateTimeConvert( 2, DateNum(), 090000 );
  2. Openprice=Lookup( O, mydatetime);
  3. //get 9:00's openprice respective day
複製代碼
But it reports error,seems array & number confusedness.
發表於 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 code  and 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.



發表於 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

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

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

  5. Filter = DateTime() == mydatetime;

  6. AddColumn(Openprice,"Open", 1.4);
複製代碼



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


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

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

  5. Filter = O == Openprice;

  6. AddColumn(Openprice,"Open", 1.4);
複製代碼


This code searches all open prices that occurred at specified time


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

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

  4. Filter = TimeNum() == stime;

  5. AddTextColumn( Name(), "Ticker", 1.0, colorWhite, colorDarkGrey, 70 );
  6. AddColumn( DayOfWeek(), "WKD", 1.0, colorWhite, colorDarkGrey, 35 );
  7. AddColumn( DateTime(), "Date/Time", formatDateTime, colorBlack, colorGrey50, 120 );
  8. AddColumn( Open, "Close" , 1.4, colorWhite, colorDarkGrey, 100 );
複製代碼





 樓主| 發表於 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:
  1. mydatetime=DateTimeConvert( 2, DateNum(), 090000 );
  2. Openprice=Lookup( O, mydatetime);
  3. if(openprice>13.00)
  4. signal=buy;
  5. else
  6. signal=short;
複製代碼


發表於 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?


  1. start = TimeNum() == 090000;
  2. Buy = Open > 13.00 AND start;
  3. Short =  Open < 13.00 AND start;
複製代碼
 樓主| 發表於 12-11-7 22:06 | 顯示全部樓層
I want it be used in backtest.This is a gross simplification of other code that simply demonstrates.
  1. mydatetime=DateTimeConvert( 2, DateNum(), 090000 );
  2. Openprice=Lookup( O, mydatetime);
  3. if(some condition and timenum()==100000 and openprice>13.00)
  4. signal=buy;
  5. else
  6. signal=short;
複製代碼
您需要登錄後才可以回帖 登錄 | 註冊

本版積分規則

手機版|Archiver|站長信箱|廣告洽詢|COCO研究院

GMT+8, 24-5-10 05:07

Powered by Discuz! X3.4

Copyright © 2001-2023, Tencent Cloud.

快速回復 返回頂部 返回列表
理財討論網站 | AI繪圖AI超擬真美女AI beauty AI Stable DiffusionAI正妹AI Lookbook