Final changes, use sqrt i.o. statistics.pstdev

This commit is contained in:
hroff-1902 2020-02-28 23:50:25 +03:00 committed by GitHub
parent 09a1c9eed6
commit bee8e92f02
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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)