Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Record Moving Average of stock ratio

Hello,
how is it possible to record or plot the MA of a ratio (StockA / Stock B)?

My approach :
ma = ta.MA(timeperdiod = 14)
price_cvx = data[context.cvx].price
price_xom = data[context.xom].price
spread = price_cvx / price_xom
ma_data = ma(data)
spread_ma = ma_data[context.spread]

Thanks in advance!
Best
bob

5 responses

Hello,

My attempt. I don't know if it's what you wanted.

P.

Hi Christoph (and Peter),

Here's another example (hopefully self-explanatory).

Grant

Hi,
first thx for your replys.

Why we need the history function here?

The history API provides a trailing window of security data at the start of your backtest (so your backtest is "warmed up"). --Grant

The 'history' feature is new so it's nice to get familiar with it but it is not required.

P.