omelet 發表於 13-5-20 15:44

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

backtest後得出individual equity的曲線,那曲線的詳細數據可以保存嗎?I mean模擬出的每日資產總值的數據。多謝各位啦!               

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 customize function on the toolbar http://img809.imageshack.us/img809/8107/94220772.png

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

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

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

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

//equity function for backtester
function FindEquityAtDateTime( eq, dt, Value )
{
        found = -1;
        for( i = 0; i < BarCount AND found == -1; i++ )
        {
                if( dt[ i ] == Value ) found = i;
        }

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

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

//Now custom-backtest procedure follows
if ( Status( "action" ) == actionPortfolio )
{
    bo = GetBacktesterObject();

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

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

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

    //bo.PostProcess(); // Finalize backtester
    bo.ListTrades();
}

joshsmi 發表於 13-5-21 23:38

omelet 發表於 13-5-21 23:31 static/image/common/back.gif
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 .....

omelet 發表於 13-5-21 23:40

joshsmi 發表於 13-5-21 23:38
Ok, let me think about it .....

trillions of thanks lah!!

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 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.

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

joshsmi 發表於 13-5-22 00:17

本帖最後由 joshsmi 於 13-5-22 00:34 編輯

Here it is

Use it in exploration!


CCI0   = CCI(20);

Buy   = Cross( CCI0, 100 );
Sell= Cross( 100, CCI0 );
Short = Cross( -100, CCI0 );
Cover = Cross( CCI0, -100 );
BuyPrice = SellPrice = ShortPrice = CoverPrice = O;

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.

SetBacktestMode( backtestRegular );
SetOption( "InitialEquity", 100000 );
SetOption( "FuturesMode" , False );//False for Shares, True for FX or for Futures
SetOption( "UsePrevBarEquityForPosSizing", True );// Set to False to use current equity for Pos Sizing
SetOption( "ActivateStopsImmediately", False );
SetOption( "Allowsamebarexit", False );
SetOption( "PriceBoundChecking", True );
SetOption( "AllowPositionShrinking", True );//in case there is not enough cash
SetOption( "MaxOpenPositions", 1 );
SetPositionSize( 25, spsPercentOfEquity );

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

Filter = 1;

AddColumn( ValueWhen(Sell || Cover, Eq), "Equity", 1.2, 47, 23, 70 );

joshsmi 發表於 13-5-22 02:11

Or use this one

    CCI0   = CCI(20);

    Buy   = Cross( CCI0, 100 );
    Sell= Cross( 100, CCI0 );
    Short = Cross( -100, CCI0 );
    Cover = Cross( CCI0, -100 );
    BuyPrice = SellPrice = ShortPrice = CoverPrice = O;

    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.

    SetBacktestMode( backtestRegular );
    SetOption( "InitialEquity", 100000 );
    SetOption( "FuturesMode" , False );//False for Shares, True for FX or for Futures
    SetOption( "UsePrevBarEquityForPosSizing", True );// Set to False to use current equity for Pos Sizing
    SetOption( "ActivateStopsImmediately", False );
    SetOption( "Allowsamebarexit", False );
    SetOption( "PriceBoundChecking", True );
    SetOption( "AllowPositionShrinking", True );//in case there is not enough cash
    SetOption( "MaxOpenPositions", 1 );
    SetPositionSize( 25, spsPercentOfEquity );

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

    Filter = 1;

    AddColumn( Eq, "Equity", 1.2, 47, 23, 70 );

kilroy 發表於 13-5-22 05:48

意思是要與backtest的帳戶連動嗎?

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

omelet 發表於 13-5-22 10:08

kilroy 發表於 13-5-22 05:48 static/image/common/back.gif
意思是要與backtest的帳戶連動嗎?

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

i need the whole set of data which form the equity line. {:9_618:}

kilroy 發表於 13-5-22 12:10

omelet 發表於 13-5-22 10:08 static/image/common/back.gif
i need the whole set of data which form the equity line.

那就把它畫出來吧 XD

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

頁: [1] 2
查看完整版本: 回測結果的數據可以保存嗎?