Simplify SortinoLoss
This commit is contained in:
parent
958ad7d446
commit
5aaa05f2f2
@ -4,8 +4,8 @@ This module defines the alternative HyperOptLoss class which can be used for
|
|||||||
Hyperoptimization.
|
Hyperoptimization.
|
||||||
"""
|
"""
|
||||||
import logging
|
import logging
|
||||||
import os
|
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
from typing import Dict
|
||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
from pandas import DataFrame, Timedelta
|
from pandas import DataFrame, Timedelta
|
||||||
@ -16,11 +16,7 @@ from freqtrade.optimize.hyperopt import IHyperOptLoss
|
|||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
interval = os.getenv("FQT_TIMEFRAME") or "5m"
|
|
||||||
slippage = 0.0005
|
|
||||||
target = 0
|
target = 0
|
||||||
annualize = np.sqrt(365 * (Timedelta("1D") / Timedelta(interval)))
|
|
||||||
|
|
||||||
logger.info(f"SortinoLossBalance target is set to: {target}")
|
logger.info(f"SortinoLossBalance target is set to: {target}")
|
||||||
|
|
||||||
|
|
||||||
@ -31,28 +27,24 @@ class SortinoLossBalance(IHyperOptLoss):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def hyperopt_loss_function(
|
def hyperopt_loss_function(results: DataFrame, trade_count: int,
|
||||||
results: DataFrame,
|
min_date: datetime, max_date: datetime,
|
||||||
trade_count: int,
|
config: Dict, processed: Dict[str, DataFrame],
|
||||||
min_date: datetime,
|
*args, **kwargs) -> float:
|
||||||
max_date: datetime,
|
|
||||||
*args,
|
|
||||||
**kwargs,
|
|
||||||
) -> float:
|
|
||||||
"""
|
"""
|
||||||
Objective function, returns smaller number for more optimal results.
|
Objective function, returns smaller number for more optimal results.
|
||||||
Uses Sortino Ratio calculation.
|
Uses Sortino Ratio calculation.
|
||||||
"""
|
"""
|
||||||
hloc = kwargs["processed"]
|
|
||||||
timeframe = SortinoLossBalance.timeframe
|
timeframe = SortinoLossBalance.timeframe
|
||||||
|
annualize = np.sqrt(365 * (Timedelta("1D") / Timedelta(timeframe)))
|
||||||
|
|
||||||
balance_total = calculate_outstanding_balance(results, timeframe, hloc)
|
balance_total = calculate_outstanding_balance(results, timeframe, processed)
|
||||||
|
|
||||||
returns = balance_total.mean()
|
returns = balance_total.mean()
|
||||||
# returns = balance_total.values.mean()
|
# returns = balance_total.values.mean()
|
||||||
|
|
||||||
downside_returns = np.where(balance_total < 0, balance_total, 0)
|
downside_returns = np.where(balance_total < 0, balance_total, 0)
|
||||||
downside_risk = np.sqrt((downside_returns ** 2).sum() / len(hloc))
|
downside_risk = np.sqrt((downside_returns ** 2).sum() / len(processed))
|
||||||
|
|
||||||
if downside_risk != 0.0:
|
if downside_risk != 0.0:
|
||||||
sortino_ratio = (returns - target) / downside_risk * annualize
|
sortino_ratio = (returns - target) / downside_risk * annualize
|
||||||
|
Loading…
Reference in New Issue
Block a user