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

nan with indicator when working with offset



  • Hey Experts,

    I made a prediction-indicator working (prototype): 100 past periods predict the next two.
    But it seems, the predict is 5 periods late,
    So I have to move the predictions 5 periods back (offset).
    (Off course this is just prototyping...not for going live!)
    But finally the successive Indicators switch to "nan" (and i have more Indis than just one).
    Any possible solution for this?

    The well-working code is:

    class predictIndi(bt.Indicator):
        lines = ('pred_a', 'pred_b', 'a_diff_b',)
        params = (('period', 100), ('offset', 5),)
        
        def __init__(self):
            self.addminperiod(self.params.period + self.params.offset)
        
        def next(self):              
            ---- doing-some-magic-predict-request ---
            self.pred_a[0] = predValueA
            self.pred_b[0] = predValueB
            self.a_diff_b = self.pred_a - self.pred_b
    

    This works well and I can log (printout) the corresponding values

    529c1f4a-66c1-4129-8211-7170169bad66-grafik.png

    But as the prediction seems 5 periods late, I have to move the prediction to 5 periods earlier.
    This works very well on the plot-graphics and seems to workout.
    Lines of ValueA and ValueB moved 5periods back and are much better in place for building indicator on them.

            ...
            self.pred_a[-self.params.offset] = predValueA
            self.pred_b[-self.params.offset] = predValueB
    

    But then, a problem is rising with the subsequent indicators which turn to "nan"

            ...
            self.pred_a[-self.params.offset] = predValueA
            self.pred_b[-self.params.offset] = predValueB
            self.a_diff_b = self.tfpred_a - self.tfpred_b
            self.b_diff_a = self.tfpred_b - self.tfpred_a
    

    b6d930c6-39f3-4f7d-b3fd-85a284d9d088-grafik.png

    I tried alot, nothing make them alive again. (Have researched docu and forum)
    Any solution for this?
    Maybe just notation/syntax problem?



  • just to mention, timeframe within datarequest is ok, its all sized to M5

    dataLoad = bt.feeds.IBData(
                    dataname='GBP.USD-CASH-IDEALPRO', 
                    host='127.0.0.1', 
                    port=7496, 
                    historical=True,
                    timeframe=bt.TimeFrame.TFrame("Minutes"),
                    compression = 5
                    )
    


  • too simple...of course [0] of the indicators are NONE if they are filled on [offset].
    Then [0] cannot be handled anymore by next indicators.

    Solution: All indicators needs be doubled with offset-twin.

            ...
            self.pred_a[0] = predValueA
            self.pred_b[0] = predValueB
            self.a_diff_b[0] = self.pred_a - self.pred_b
    
            self.predOffset_a[-self.params.offset] = predValueA
            self.predOffset_b[-self.params.offset] = predValueB
            self.a_diff_b_Offset = self.predOffset_a - self.predOffset_b
    

    That works.



  • I dont want to bother anyone here with too simple or 100% exact posting

    ...so this post needs to be edit or delete...I was looking for this many times but I cannot find a link providing me this possibility.

    If someone can give me a hint, how to change (edit/delete) after posting, I would be very happy.


Log in to reply
 

});