For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/

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


  • administrators

    Position doesn't store the actual values of previous days. It only holds the current values of price and size.

    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 of None items which is generated with the one liner