Position size on previous day [-1]
-
Dear all,
I would like to extract the position size of the "previous day" (using daily data as datafeeds).
To obtain the position of "today" I can use the following, which works well:
self.getposition(data=self.datas[i]).size
As I have several datafeeds I need the [i] to refer to the individual feeds.
However, if I would like to refer to the "previous day" I struggle...
I have tried:
self.getposition(data=self.datas[i][-1]).size
as well as
self.getposition(data=self.datas[i]).size[-1]
but both dont work and I couldn't find any hints in the documentation/the forum.
Would be great if someone could point me to a solution!
Thanks!
jf -
Position
doesn't store the actual values of previous days. It only holds the current values ofprice
andsize
.If you want to reference past positions, you need to keep them yourself.
def __init__(self): self.posis = collections.defaultdict(list) def next(self): [self.posis[d].append(self.getposition(data=d) for d in self.datas]
Of course you can also use a
for
loop and avoid the useless list full ofNone
items which is generated with the one liner