Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

How to change the optimization input parameter range to include decimal values instead of just integers? #934

Answered by ddm-j
LANDERWANG asked this question in Q&A
Discussion options

bt = Backtest(BackTestingData, SuperTrendPlus, cash=starting_cash,
commission=_commission, exclusive_orders=False, trade_on_close=True)

stats, heatmap = bt.optimize(ATR_Period=range(
10, 20, 2), InputMultuplier=range(4, 6, 1), method='grid', return_heatmap=True)

How to change the optimization input parameter range to include decimal values instead of just integers?like InputMultuplier=range(4, 6, 0.5)

You must be logged in to vote

The optimizer takes a list or similar type as arguments for the parameters to optimize over.

Therefore you can do something like this:

stats, heatmap = bt.optimize(ATR_Period=range(10, 20, 2), InputMultuplier=list(np.linspace(4, 6, 4)), method='grid', return_heatmap=True)

You can also just type out the list:
InputMultiplier=[4, 4.5, 5, 5.5, 6]

Or use numpy,arange which is similar to range (remember that we need to convert to list):
InputMultiplier=list(np.arange(4, 6, 0.5))

The optimizer may take an np.array type, but I'm not sure.

Replies: 1 comment 1 reply

Comment options

The optimizer takes a list or similar type as arguments for the parameters to optimize over.

Therefore you can do something like this:

stats, heatmap = bt.optimize(ATR_Period=range(10, 20, 2), InputMultuplier=list(np.linspace(4, 6, 4)), method='grid', return_heatmap=True)

You can also just type out the list:
InputMultiplier=[4, 4.5, 5, 5.5, 6]

Or use numpy,arange which is similar to range (remember that we need to convert to list):
InputMultiplier=list(np.arange(4, 6, 0.5))

The optimizer may take an np.array type, but I'm not sure.

You must be logged in to vote
1 reply
Comment options

kernc Apr 1, 2023
Maintainer

The optimizer may take an np.array type, but I'm not sure.

It might not currently, but I'm considering this to be a bug. 😅

Answer selected by kernc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet

AltStyle によって変換されたページ (->オリジナル) /