|
樓主 |
發表於 14-7-23 19:20
|
顯示全部樓層
有一個關於iterate across open positions 的問題想請教一下:
// start CBT
SetCustomBacktestProc( "" );
if ( Status( "action" ) == actionPortfolio )
{
bo = GetBacktesterObject(); //get access to backtester object
bo.Backtest(1); // run default backtest procedure
eq = bo.EquityArray;
st = bo.GetPerformanceStats(0); // get stats for all trades
// Output Equity at entry column in backtest result list
for ( trade = bo.GetFirstTrade(); trade; trade = bo.GetNextTrade() )
{
EquityAtExit = Lookup( eq, trade.ExitDateTime );
trade.AddCustomMetric( "Equity at exit_trade", EquityAtExit );
}
// iterate through closed trades first
for( trade = bo.GetFirstTrade(); trade; trade = bo.GetNextTrade() )
{
// here we sum up profit per $100 invested
//SumProfitPer100Inv = SumProfitPer100Inv + trade.GetPercentProfit();
//NumTrades++;
trade.AddCustomMetric("Percent_profit_close",trade.GetPercentProfit() );
}
// iterate through eventually still open positions
for( trade = bo.GetFirstOpenPos(); trade; trade = bo.GetNextOpenPos() )
{
//SumProfitPer100Inv = SumProfitPer100Inv + trade.GetPercentProfit();
//NumTrades++;
trade.AddCustomMetric("Percent_profit_open",trade.GetPercentProfit() );
}
bo.ListTrades();
}
附件是backtest result, 在最後兩段codes其實我預期result 會有兩個columns , 一個是 Percent_profit_close, 另一個是
Percent_profit_open
而Percent_profit_open 道理上全部都是零, 而最後一個row 才有數值(因為只有最後一行是open position)
但結果很奇怪, 不知道為什麼沒有Percent_profit_open的column, 而且Equity at exit_trade的最後一個row是3.33 , 一個很奇怪的數, 我估計這個值應該是Percent_profit_open吧?
應該是iterate 的logic 出了問題導致overlap了, 前輩可以提點一下嗎?
thanks.
|
-
|