Fix sortino std calculation

This commit is contained in:
Matthias 2022-12-28 14:59:23 +01:00
parent d5b516842c
commit 32bbe603cb
2 changed files with 2 additions and 5 deletions

View File

@ -237,9 +237,7 @@ def calculate_sortino(trades: pd.DataFrame, min_date: datetime, max_date: dateti
expected_returns_mean = total_profit.sum() / days_period
trades['downside_returns'] = 0
trades.loc[total_profit < 0, 'downside_returns'] = (trades['profit_abs'] / starting_balance)
down_stdev = np.std(trades['downside_returns'])
down_stdev = np.std(trades.loc[trades['profit_abs'] < 0, 'profit_abs'] / starting_balance)
if down_stdev != 0:
sortino_ratio = expected_returns_mean / down_stdev * np.sqrt(365)

View File

@ -1,4 +1,3 @@
from datetime import datetime
from pathlib import Path
from unittest.mock import MagicMock
@ -365,7 +364,7 @@ def test_calculate_sortino(testdatadir):
0.01,
)
assert isinstance(sortino, float)
assert pytest.approx(sortino) == 55.1447312
assert pytest.approx(sortino) == 35.17722
def test_calculate_sharpe(testdatadir):