Dynamic calculation based on "weights" dictionary
-
Hi, I started discovering BackTrader, and I would appreciate any suggestion how to "structure" my strategy.
The algorithm needs to read a
dict
which contains differentweights
of totalposition size
. Let's say I want to split a complete position in 4 orders, then, any time thedatas[0].high
fill the target_priceposition.size += 1
out of total of 4. However, theses target prices are intended to be moved by offset. So, this target_price should be dynamic calculated based on an offset given by adict
.Following code is an example of my strategy I want to code, please keep focus on the part I want to create de
entries dictionary
based on an imported CSV, this file includes offset to then dynamically mapparams.offset.vaue
.I want to include this mapping part in the
def next()
part whenif <condition>
statement isTrue
whenFalse
theoffset
remains as initially declared.lass PoolsJedi(bt.Strategy): params = ( ('offset', 0.0055), ) def __init__(self): # Start fields self.dataopen = self.datas[0].open self.dataclose = self.datas[0].close self.datahigh = self.datas[0].high self.datalow = self.datas[0].low # Create weights dictionary qtr = pd.read_pickle('config/weights.csv') entries = { w: { 'e{}'.format(i): qtr[e][w] for i,e in enumerate(qtr.columns) } for w in qtr.index } # Initialize variables entries_length = len( entries[list(entries.keys())[0]] ) cpos = np.array( [0] * entries_length ) """ CODE CONTINUES """
I hope this part may give you the whole idea. I'd appreciate any support in advance.
-
I just figured it out. Thanks anyway for the support!