Hello,

I found out what it is:

"position value" in trade list output in AA uses OPENING price of open 
positions whereas my trade.GetProfit() using CLOSING price.

But I still wonder what the reasoning is for using the open rather than the 
close???

Thanks

Markus

  ----- Original Message ----- 
  From: Markus Witzler 
  To: [email protected] 
  Sent: Tuesday, January 19, 2010 2:15 PM
  Subject: [amibroker] Deviation of open position value on last day


    

Hello, I wonder why the following is happening: After the i-incremented for 
loop of my low-level CBT code (which I displayed as a template below), I summed 
up thevalue of all positions that were still open at end of backtest (variable 
"Last_open_position_value"). This variable (which to my understanding still 
contains marginloan) should correspond with column "position value" of trade 
list output for open positions, but it doesn´t.  I added it as metric via 
bo.addcustommetric ("Last_open_position_value", Last_open_position_value) in 
backtest report to check for deviation. Could someone let me know why the 
differ? I can´t see the flaw in my code. Thanks Markus  
SetCustomBacktestProc("");
if (Status("action") == actionPortfolio)
{
    bo = GetBacktesterObject(); //  Get backtester object
    bo.PreProcess();    //  Do pre-processing
    for (i = 0; i < BarCount; i++)      //  Loop through all bars
    {
        for (sig = bo.GetFirstSignal(i); sig; sig = bo.GetNextSignal(i))
        {       //  Loop through all signals at this bar
            . . . .
        }       //  End of for loop over signals at this bar
        bo.HandleStops(i);      //  Handle programmed stops at this bar
        bo.UpdateStats(i, 1);   //  Update MAE/MFE stats for bar
        bo.UpdateStats(i, 2);   //  Update stats at bar's end
    }   //  End of for loop over bars

  ... Here comes the actual part of code that I am referring to:

  for (trade = bo.GetFirstOpenPos(); trade; trade = bo.GetNextOpenPos())


  { // first variable should still include marginloan, right??

  Last_open_position_value = Last_open_position_value + 
trade.GetPositionValue();

  // second variable doesn´t contain marginloan, right??

  Profit_open_positions_last_day = Profit_open_positions_last_day + 
trade.GetProfit(); 

  }

  Ending_equity = Profit_open_positions_last_day + bo.cash;

  Starting_equity = bo.initialequity;

  Total_portfolio_bars_in_datenum = StaticVarGet("last_bars_date",a[BarCount - 
1]) - StaticVarGet("last_bars_date",a[0]);

  bo.addcustommetric("Last_open_position_value", Last_open_position_value);

  bo.addcustommetric("My_ending_equity", ending_equity);

  bo.PostProcess(); // Do post-processing

  }


  

  __________ Information from ESET Smart Security, version of virus signature 
database 4668 (20091207) __________

  The message was checked by ESET Smart Security.

  http://www.eset.com

Reply via email to