Fix sortino std calculation
This commit is contained in:
parent
d5b516842c
commit
32bbe603cb
@ -237,9 +237,7 @@ def calculate_sortino(trades: pd.DataFrame, min_date: datetime, max_date: dateti
|
|||||||
|
|
||||||
expected_returns_mean = total_profit.sum() / days_period
|
expected_returns_mean = total_profit.sum() / days_period
|
||||||
|
|
||||||
trades['downside_returns'] = 0
|
down_stdev = np.std(trades.loc[trades['profit_abs'] < 0, 'profit_abs'] / starting_balance)
|
||||||
trades.loc[total_profit < 0, 'downside_returns'] = (trades['profit_abs'] / starting_balance)
|
|
||||||
down_stdev = np.std(trades['downside_returns'])
|
|
||||||
|
|
||||||
if down_stdev != 0:
|
if down_stdev != 0:
|
||||||
sortino_ratio = expected_returns_mean / down_stdev * np.sqrt(365)
|
sortino_ratio = expected_returns_mean / down_stdev * np.sqrt(365)
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
from datetime import datetime
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from unittest.mock import MagicMock
|
from unittest.mock import MagicMock
|
||||||
|
|
||||||
@ -365,7 +364,7 @@ def test_calculate_sortino(testdatadir):
|
|||||||
0.01,
|
0.01,
|
||||||
)
|
)
|
||||||
assert isinstance(sortino, float)
|
assert isinstance(sortino, float)
|
||||||
assert pytest.approx(sortino) == 55.1447312
|
assert pytest.approx(sortino) == 35.17722
|
||||||
|
|
||||||
|
|
||||||
def test_calculate_sharpe(testdatadir):
|
def test_calculate_sharpe(testdatadir):
|
||||||
|
Loading…
Reference in New Issue
Block a user