No need for np; make flake happy

This commit is contained in:
hroff-1902 2020-02-05 18:05:41 +03:00
parent 8e6ab0eaaf
commit f3e94969b3

View File

@ -4,10 +4,10 @@ SharpeHyperOptLossDaily
This module defines the alternative HyperOptLoss class which can be used for This module defines the alternative HyperOptLoss class which can be used for
Hyperoptimization. Hyperoptimization.
""" """
import math
from datetime import datetime from datetime import datetime
from pandas import DataFrame, date_range from pandas import DataFrame, date_range
import numpy as np
from freqtrade.optimize.hyperopt import IHyperOptLoss from freqtrade.optimize.hyperopt import IHyperOptLoss
@ -35,7 +35,8 @@ class SharpeHyperOptLossDaily(IHyperOptLoss):
risk_free_rate = annual_risk_free_rate / days_in_year risk_free_rate = annual_risk_free_rate / days_in_year
# apply slippage per trade to profit_percent # apply slippage per trade to profit_percent
results.loc[:, 'profit_percent_after_slippage'] = results['profit_percent'] - slippage_per_trade_ratio results.loc[:, 'profit_percent_after_slippage'] = \
results['profit_percent'] - slippage_per_trade_ratio
# create the index within the min_date and end max_date # create the index within the min_date and end max_date
t_index = date_range(start=min_date, end=max_date, freq=resample_freq) t_index = date_range(start=min_date, end=max_date, freq=resample_freq)
@ -50,11 +51,11 @@ class SharpeHyperOptLossDaily(IHyperOptLoss):
up_stdev = total_profit.std() up_stdev = total_profit.std()
if (up_stdev != 0.): if (up_stdev != 0.):
sharp_ratio = expected_returns_mean / up_stdev * np.sqrt(days_in_year) sharp_ratio = expected_returns_mean / up_stdev * math.sqrt(days_in_year)
else: else:
# Define high (negative) sharpe ratio to be clear that this is NOT optimal. # Define high (negative) sharpe ratio to be clear that this is NOT optimal.
sharp_ratio = -20. sharp_ratio = -20.
#print(t_index, sum_daily, total_profit) # print(t_index, sum_daily, total_profit)
#print(risk_free_rate, expected_returns_mean, up_stdev, sharp_ratio) # print(risk_free_rate, expected_returns_mean, up_stdev, sharp_ratio)
return -sharp_ratio return -sharp_ratio