Page 1 of 1

Portfolio Backtester: Closing positions based on Acc Equity

Posted: May 04 2013
by robbob
Hi,

I'm attempting to implement an exit rule that will close a position if the current account equity has dropped by 3 percent from the previous day. Basically, if the threshold is hit, I would like the strategy to exit all positions. I am using the portfolio backtester on intraday futures data.

What I am seeing is that one symbol will exit, but other positions that are open that day will not exit.
For example, the threshold was hit on 7/26/07, which the strategy was holding positions in NQ, GBP, and EUR. The portfolio backtester exited the NQ position when the account equity theshhold was hit, but the GBP and EUR positions did not exit that day, and were closed out a few days later due to other exit rules being hit.

The calcBar() method for this rule appears below:

Code: Select all

protected override void CalcBar(){

int today = Bars.TimeValue.Day;
if( yesterdayDate == -1 ) {
yesterdayDate = today;
yesterdayEquity = currentEquity;
return;
}

if( today != yesterdayDate ) {
yesterdayEquity = currentEquity;
yesterdayDate = today;
}

stopAmount = (100.0-m_switchAmount)/100.0;

currentEquity = InitialCapital + StrategyInfo.ClosedEquity + StrategyInfo.OpenEquity;

double thresholdAmount = (yesterdayEquity * stopAmount);
Output.WriteLine( "Switch Date:" + Bars.TimeValue + " today Date: " + today + " yesterday Date: " + yesterdayDate + " currentEquity: " + currentEquity + " yesterdayEquity: " + yesterdayEquity + " switch value: " + thresholdAmount );
if( currentEquity < thresholdAmount ) {
Output.WriteLine( "### Kill switch hit" );
m_Order.Send( );
}
}

Please let me know what other info you need to help debug what may be going on.

thanks,
-Rob

Re: Portfolio Backtester: Closing positions based on Acc Equ  [SOLVED]

Posted: May 06 2013
by Henry MultiŠ”harts
Hello Rob,

The Equity calculation is incorrect. In your strategy equity is calculated for a particular strategy only, while you need to calculate it for the entire portfolio:

Code: Select all

currentEquity = InitialCapital + Portfolio.NetProfit + Portfolio.OpenPositionProfit;

Re: Portfolio Backtester: Closing positions based on Acc Equ

Posted: May 15 2013
by robbob
That took care of the problem.

Thanks!