Merge pull request #132 from FelipeFernandesLeandro/master

fix hyperopting multi-value categories on AverageHyperopt
This commit is contained in:
Matthias
2021-03-12 06:14:03 +01:00
committed by GitHub
+22 -10
View File
@@ -43,9 +43,11 @@ class AverageHyperopt(IHyperOpt):
conditions = []
# TRIGGERS
if 'trigger' in params:
trigger = [int(item) for item in params['trigger'].split('-')]
conditions.append(qtpylib.crossed_above(
dataframe[f"maShort({params['trigger'][0]})"],
dataframe[f"maMedium({params['trigger'][1]})"])
dataframe[f"maShort({trigger[0]})"],
dataframe[f"maMedium({trigger[1]})"])
)
# Check that volume is not 0
@@ -68,9 +70,13 @@ class AverageHyperopt(IHyperOpt):
buyTriggerList = []
for short in range(shortRangeBegin, shortRangeEnd):
for medium in range(mediumRangeBegin, mediumRangeEnd):
# The output will be (short, long)
"""
The output will be '{short}-{long}' so we can split it on the trigger
this will prevent an error on scikit-optimize not accepting tuples as
first argument to Categorical
"""
buyTriggerList.append(
(short, medium)
'{}-{}'.format(short, medium)
)
return [
Categorical(buyTriggerList, name='trigger')
@@ -90,10 +96,12 @@ class AverageHyperopt(IHyperOpt):
# TRIGGERS
if 'sell-trigger' in params:
trigger = [int(item) for item in params['sell-trigger'].split('-')]
conditions.append(qtpylib.crossed_above(
dataframe[f"maMedium({params['sell-trigger'][1]})"],
dataframe[f"maShort({params['sell-trigger'][0]})"])
)
dataframe[f"maMedium({trigger[1]})"],
dataframe[f"maShort({trigger[0]})"])
)
if conditions:
dataframe.loc[
@@ -112,9 +120,13 @@ class AverageHyperopt(IHyperOpt):
sellTriggerList = []
for short in range(shortRangeBegin, shortRangeEnd):
for medium in range(mediumRangeBegin, mediumRangeEnd):
# The output will be (short, long)
"""
The output will be '{short}-{long}' so we can split it on the trigger
this will prevent an error on scikit-optimize not accepting tuples as
first argument to Categorical
"""
sellTriggerList.append(
(short, medium)
'{}-{}'.format(short, medium)
)
return [
@@ -151,4 +163,4 @@ class AverageHyperopt(IHyperOpt):
),
'sell'] = 1
return dataframe
return dataframe