passing parameters to strategies: __init__() user params from backtest (Part II)

Brandon_JohnsonBrandon_Johnson Posts: 8
edited June 2017 in Under The Hood

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:

Image and video hosting by TinyPic

I keep getting an error complaining about the parameter I am passing into init via the backtester module.

imageImage and video hosting by TinyPic" 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

Sign In or Register to comment.