Hi,
I am trying to implement an OBV custom factor by using a global context variable to accumulate the obv each day as it isn't possible to reference earlier values of factors in the pipeline as an input in the same way as the standard data such as close price, volume, etc. Note: the obv is a running total of the volume traded where the volume is added to the previous value if the price increased and subtracted if it decreased - see obv.
Unfortunately I am getting an error:
There was a runtime error.
ValueError: operands could not be broadcast together with shapes (7824,) (7826,) (7824,)
...
USER ALGORITHM:259, in compute
context.obv += obv[-1]
Which looks like is because of trying add different arrays of different lengths into the accumulation variable context.obv (I guess this is because there are different stocks each day when the pipeline computes the values as some may cease being traded or new companies might be added etc). Is there a way to accumulate a value in a custom factor that depends on previous values each time the pipeline is called to compute a new value reliably? Also what if you want a running moving average on the accumulated value?
Thanks.