COCO研究院

 找回密碼
 註冊
搜索
查看: 3462|回復: 17

回測結果的數據可以保存嗎?

[複製鏈接]
發表於 13-5-20 15:44 | 顯示全部樓層 |閱讀模式
backtest後得出individual equity的曲線,那曲線的詳細數據可以保存嗎?I mean模擬出的每日資產總值的數據。多謝各位啦!               
發表於 13-5-21 22:58 | 顯示全部樓層
Yes, if analysis window is open go to File>Export HTML/CSV

But you can also create a button via customize function on the toolbar http://img809.imageshack.us/img809/8107/94220772.png
發表於 13-5-21 23:00 | 顯示全部樓層
But you can also copy the results list of the backtest output and paste it into Excel directly, for example
發表於 13-5-21 23:02 | 顯示全部樓層
本帖最後由 joshsmi 於 13-5-21 23:36 編輯

Via custom backtest interface you can create a column of equity as each backtest default list has column "Cum. profit" only.

I will show the code later

You can create any additional backtest metric! http://www.amibroker.com/guide/a_custombacktest.html‎
 樓主| 發表於 13-5-21 23:31 來自手機 | 顯示全部樓層
joshsmi 發表於 13-5-21 22:58
Yes, if analysis window is open go to File>Export HTML/CSV

But you can also create a button via cus ...

thanks a lot. but what i want to get is the daily data points rather than the non-consecutive data. e.g. a strategy made 20 trades within 3 years. i want daily result data within these 3 years (more than 600 data points) rather than only 20 data points shown directly on the result table.
發表於 13-5-21 23:32 | 顯示全部樓層
本帖最後由 joshsmi 於 13-5-22 00:33 編輯

Add this code to your backtest code and click portfolio backtest as portfolio equity symbol is used. At first use click it two times.

http://www.amibroker.com/newsletter/01-2005.html

  1. //equity function for backtester
  2. function FindEquityAtDateTime( eq, dt, Value )
  3. {
  4.         found = -1;
  5.         for( i = 0; i < BarCount AND found == -1; i++ )
  6.         {
  7.                 if( dt[ i ] == Value ) found = i;
  8.         }

  9.         return IIf( found != -1, eq[ found - 1 ], Null );
  10. }

  11. SetOption("ExtraColumnsLocation", 12 );
  12. SetCustomBacktestProc( "" );

  13. //Now custom-backtest procedure follows
  14. if ( Status( "action" ) == actionPortfolio )
  15. {
  16.     bo = GetBacktesterObject();

  17.     //bo.PreProcess(); // Initialize backtester
  18.     bo.Backtest( 1 ); // run default backtest procedure.  Run backtests with no trade listing

  19.     dt = DateTime();
  20.     eq = Foreign( "~~~EQUITY", "C" );

  21.     // iterate through closed trades first
  22.     for ( trade = bo.GetFirstTrade(); trade; trade = bo.GetNextTrade() )
  23.     {
  24.         //  Loop through all closed trades
  25.         EquityAtExit = FindEquityAtDateTime( eq, dt, trade.ExitDateTime );
  26.         trade.AddCustomMetric( "Equity", EquityAtExit );
  27.     }

  28.     //bo.PostProcess(); // Finalize backtester
  29.     bo.ListTrades();
  30. }
複製代碼
發表於 13-5-21 23:38 | 顯示全部樓層
omelet 發表於 13-5-21 23:31
thanks a lot. but what i want to get is the daily data points rather than the non-consecutive data ...

Ok, let me think about it .....
 樓主| 發表於 13-5-21 23:40 來自手機 | 顯示全部樓層
joshsmi 發表於 13-5-21 23:38
Ok, let me think about it .....

trillions of thanks lah!!
發表於 13-5-21 23:49 | 顯示全部樓層
One thing is for sure .. you would have to do it via Exploration not via Backtest as backtest only outputs entry and exit dates, AFAIK.

Exploration can also be used for backtesting but only for individual backtests not portfolio. So I will think about it. Should be possible.
 樓主| 發表於 13-5-21 23:56 來自手機 | 顯示全部樓層
joshsmi 發表於 13-5-21 23:49
One thing is for sure .. you would have to do it via Exploration not via Backtest as backtest only o ...

good, will have a try. 3q
發表於 13-5-22 00:17 | 顯示全部樓層
本帖最後由 joshsmi 於 13-5-22 00:34 編輯

Here it is

Use it in exploration!


  1. CCI0   = CCI(20);

  2. Buy   = Cross( CCI0, 100 );
  3. Sell  = Cross( 100, CCI0 );
  4. Short = Cross( -100, CCI0 );
  5. Cover = Cross( CCI0, -100 );
  6. BuyPrice = SellPrice = ShortPrice = CoverPrice = O;

  7. SetTradeDelays( 1, 1, 1, 1 ); // i.e. set to 1 if entering on next bar's open, set to 0 if entering on same bar's close.

  8. SetBacktestMode( backtestRegular );
  9. SetOption( "InitialEquity", 100000 );
  10. SetOption( "FuturesMode" , False );//False for Shares, True for FX or for Futures
  11. SetOption( "UsePrevBarEquityForPosSizing", True );// Set to False to use current equity for Pos Sizing
  12. SetOption( "ActivateStopsImmediately", False );
  13. SetOption( "Allowsamebarexit", False );
  14. SetOption( "PriceBoundChecking", True );
  15. SetOption( "AllowPositionShrinking", True );//in case there is not enough cash
  16. SetOption( "MaxOpenPositions", 1 );
  17. SetPositionSize( 25, spsPercentOfEquity );

  18. eq = Equity( 2 ); //1 -> tradedelays == 0, use flag 2 if tradedelays != 0. But this flag setting should be used carefully, read manual

  19. Filter = 1;

  20. AddColumn( ValueWhen(Sell || Cover, Eq), "Equity", 1.2, 47, 23, 70 );
複製代碼
發表於 13-5-22 02:11 | 顯示全部樓層
Or use this one

  1.     CCI0   = CCI(20);

  2.     Buy   = Cross( CCI0, 100 );
  3.     Sell  = Cross( 100, CCI0 );
  4.     Short = Cross( -100, CCI0 );
  5.     Cover = Cross( CCI0, -100 );
  6.     BuyPrice = SellPrice = ShortPrice = CoverPrice = O;

  7.     SetTradeDelays( 1, 1, 1, 1 ); // i.e. set to 1 if entering on next bar's open, set to 0 if entering on same bar's close.

  8.     SetBacktestMode( backtestRegular );
  9.     SetOption( "InitialEquity", 100000 );
  10.     SetOption( "FuturesMode" , False );//False for Shares, True for FX or for Futures
  11.     SetOption( "UsePrevBarEquityForPosSizing", True );// Set to False to use current equity for Pos Sizing
  12.     SetOption( "ActivateStopsImmediately", False );
  13.     SetOption( "Allowsamebarexit", False );
  14.     SetOption( "PriceBoundChecking", True );
  15.     SetOption( "AllowPositionShrinking", True );//in case there is not enough cash
  16.     SetOption( "MaxOpenPositions", 1 );
  17.     SetPositionSize( 25, spsPercentOfEquity );

  18.     eq = Equity( 2 ); //1 -> tradedelays == 0, use flag 2 if tradedelays != 0. But this flag setting should be used carefully, read manual

  19.     Filter = 1;

  20.     AddColumn( Eq, "Equity", 1.2, 47, 23, 70 );
複製代碼
發表於 13-5-22 05:48 來自手機 | 顯示全部樓層
意思是要與backtest的帳戶連動嗎?

用 equity()這個函數就可以了
 樓主| 發表於 13-5-22 10:08 | 顯示全部樓層
kilroy 發表於 13-5-22 05:48
意思是要與backtest的帳戶連動嗎?

用 equity()這個函數就可以了

i need the whole set of data which form the equity line.
發表於 13-5-22 12:10 | 顯示全部樓層
omelet 發表於 13-5-22 10:08
i need the whole set of data which form the equity line.

那就把它畫出來吧 XD

eq = Foreign("~~~EQUITY", "C");
Plot( eq, " Equity ", 2, styleLine );

您需要登錄後才可以回帖 登錄 | 註冊

本版積分規則

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

GMT+8, 24-5-17 16:59

Powered by Discuz! X3.4

Copyright © 2001-2023, Tencent Cloud.

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