Hi community,
I'm very new to finance algorithms in general and quantopian specifically. As a first exercise I'm trying to implement Heikin Ashi candles which seem to work fine outside of pipelines. If I want to put this code into a pipeline I guess I need to create a CustomFactor. The challenge I have with this is: how do I store data locally to the CustomFactor class instance?
The reason for this is: when caclulating HeikinAshi candles you always need data from the last days. And to make the calculations somewhat correct, you need to go back at least 10 days. So I could solve this by simple providing a window_length of 10 to my CustomFactor but then everyday for every stock I have to recalculate candles for the last 10 days. If I were to calculate the initial 10 days, store the candle data and then when the pipeline runs only use a window-length of 1 and use the stored candle history within the CustomFactor it should be much more efficient.
I already tried to put in a variable into the class (I tried both with the "self" and without the "self" reference) but that didn't work.
class HeikinAshi(CustomFactor):
window_length=10
ha_candles = {}
def compute(self, today, assets, out, prices_open, prices_high, prices_low, prices_close):
print(ha_candles)
I also tried to pass the "context" variable into my compute method so I can reference the previously calculated candles that way but that is also not allowed.
Thanks
Kurt