Final changes, use sqrt i.o. statistics.pstdev
This commit is contained in:
parent
09a1c9eed6
commit
bee8e92f02
@ -5,7 +5,6 @@ This module defines the alternative HyperOptLoss class which can be used for
|
|||||||
Hyperoptimization.
|
Hyperoptimization.
|
||||||
"""
|
"""
|
||||||
import math
|
import math
|
||||||
import statistics
|
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
from pandas import DataFrame, date_range
|
from pandas import DataFrame, date_range
|
||||||
@ -56,7 +55,9 @@ class SortinoHyperOptLossDaily(IHyperOptLoss):
|
|||||||
sum_daily['downside_returns'] = 0
|
sum_daily['downside_returns'] = 0
|
||||||
sum_daily.loc[total_profit < 0, 'downside_returns'] = total_profit
|
sum_daily.loc[total_profit < 0, 'downside_returns'] = total_profit
|
||||||
total_downside = sum_daily['downside_returns']
|
total_downside = sum_daily['downside_returns']
|
||||||
down_stdev = statistics.pstdev(total_downside, 0)
|
# Here total_downside contains min(0, P - MAR) values,
|
||||||
|
# where P = sum_daily["profit_percent_after_slippage"]
|
||||||
|
down_stdev = math.sqrt((total_downside**2).sum() / len(total_downside))
|
||||||
|
|
||||||
if (down_stdev != 0.):
|
if (down_stdev != 0.):
|
||||||
sortino_ratio = expected_returns_mean / down_stdev * math.sqrt(days_in_year)
|
sortino_ratio = expected_returns_mean / down_stdev * math.sqrt(days_in_year)
|
||||||
|
Loading…
Reference in New Issue
Block a user