Portfolio Backtester: Closing positions based on Acc Equity
Posted: May 04 2013
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:
Please let me know what other info you need to help debug what may be going on.
thanks,
-Rob
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