passing parameters to strategies: __init__() user params from backtest (Part II)
I'm still apparently having trouble figuring out how to use the init(self, **params) method for a Strategy.
Part I of this thread is here:
https://forum.cloudquant.com/index.php?p=/discussion/56/custom-classes-and-inputs-functionality#latest
I simplified my test script to basically replicate the example from the documentation:
https://app.cloudquant.com/application/#/glossary/77
Here is the entire script I am trying to use:
`from cloudquant.interfaces import Strategy
class MyStrategy(Strategy):
def __init__(self, **params):
self.your_dictionary_key = None
if 'your_dictionary_key' in params:
self.your_dictionary_key = params['your_dictionary_key']
def on_trade(self, event, md, order, service, account):
if self.your_dictionary_key != None :
print 'got parameter passed in - ' % self.your_dictionary_key
`
Here is the prompt I get when I attempt to backtest this script:
I keep getting an error complaining about the parameter I am passing into init via the backtester module.
" alt="" />
It seems to be referring to the last Field item in the deque: "u'type'" and wants this to be an object type. The script compiles when I leave the user input blank for some reason.
Thanks for any assistance
_B
Comments
where you have
'A'
put
{"your_dictionary_key":"A"}
use double quotes not single quotes.
Thank you Shayne, this worked for me