backtesting.py icon indicating copy to clipboard operation
backtesting.py copied to clipboard

Both SHORT and LONG trades in the same strategy: Returns don't add up.

Open texasraj opened this issue 3 years ago • 0 comments

Expected Behavior

Here is the code for both long and short:

    if self.position.size <= 0 and self.sma1[-1] > 1.01 * self.sma2[-1] :
        self.buy()
        
    if self.position.size > 0 and self.sma1[-1] < self.sma2[-1] :
        self.position.close()
        
    if self.position.size >= 0 and self.sma1[-1] < 0.98 * self.sma2[-1]  :
        self.sell()
        
    if self.position.size < 0 and self.sma1[-1] > self.sma2[-1] :
        self.position.close()

Long only:

Start 2003-09-11 04:00:00 End 2022-09-19 04:00:00 Duration 6948 days 00:00:00 Exposure Time [%] 61.16 Equity Final [$] 9.14573e+06 Equity Peak [$] 1.02025e+07 Return [%] 9045.73 Buy & Hold Return [%] 37609.1 Return (Ann.) [%] 26.9058 Volatility (Ann.) [%] 29.2338 Sharpe Ratio 0.920365 Sortino Ratio 1.84697 Calmar Ratio 0.937813

Short only:

Start 2003-09-11 04:00:00 End 2022-09-19 04:00:00 Duration 6948 days 00:00:00 Exposure Time [%] 31.8886 Equity Final [$] 17258.9 Equity Peak [$] 100534 Return [%] -82.7411 Buy & Hold Return [%] 37620.3 Return (Ann.) [%] -8.8531 Volatility (Ann.) [%] 18.6792 Sharpe Ratio 0 Sortino Ratio 0 Calmar Ratio 0

Both:

Start 2003-09-11 04:00:00 End 2022-09-19 04:00:00 Duration 6948 days 00:00:00 Exposure Time [%] 92.7973 Equity Final [$] 1.57611e+06 Equity Peak [$] 2.17842e+06 Return [%] 1476.11 Buy & Hold Return [%] 37609.1 Return (Ann.) [%] 15.6616 Volatility (Ann.) [%] 36.0923 Sharpe Ratio 0.433932 Sortino Ratio 0.760536 Calmar Ratio 0.319967

Expecting 9045.73 + -82.7411 in BOTH scenario.

Thanks!

texasraj avatar Sep 19 '22 17:09 texasraj