Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
how to apply SimpleMovingAverage on Fundamental data

can anybody share how to calculate simple moving average of fundamental data? Below code failed, I got same FCF and FCF4.
Thanks!

mean_FCF_4 = SimpleMovingAverage(
inputs = [Fundamentals.free_cash_flow],
window_length=4,
)

Create the pipeline

pipe = Pipeline(
columns = {
'ClosePr' : USEquityPricing.close.latest,
'pe_ratio' : Fundamentals.pe_ratio.latest,
'market_cap' : Fundamentals.market_cap.latest,
'FCF' : Fundamentals.free_cash_flow.latest,
'FCF4': mean_FCF_4
},
screen = universe
)

4 responses

Hi Mai,
For your question, I don't know it you got the output telling you 5 features as you wanted under the columns section, but you are only confused about why FCF and FCF4 are same.

I saw your code is incomplete here, so I also have my code for the above output just make sure we are on the same page.

The reason FCF4 and FCF are the same is that you set window only equals 4 days. As we know the free cash flow is not "continuous" in real life. The company only post its financial report once a quarter, so 4 days window is just too short for the moving average of Free Cash Flow. There are all the same number for continuous 4 days. Even you luckily picked the date that company post its financial report, the Quantopian builin SimpleMovingAverage function seems to have some smoothing factor to smooth the of moving average as a flat line.

[CONTINUED] Therefore, I suggest you to change the window length to a large number, and this number is based on your research purpose. For example, 60 days is large enough to observe some valuable moving average data of FCF. However, you can see there are still a couple of days have the same value as the FCF. latest. Because 60 < 90(a quarter) for some of the values they are calculated by the same number as the Free Cash Flow at that particular day. But if you change the window length to 90 days( which is the length of a quarter) you can completely avoid FCF = FCF_Moving average. Here I post the example of single equity APPL with window length equals 60 days to help me explain the idea. You are free to modify my code if you have any related problems want to test.

On the other hand, for some of the fundamental data related to the market information( for example P/E ratio related to the price of the equity) There is no need to worry about picking the window length problem, because its value changes daily. But be careful on the date of financial reports come out.

Please let me know if I understood your question in a wrong way or I made some mistakes above.

Thanks, Siyuan.

I thought fundamental data is stored as a quarterly data, that is why I use a window length 4 to get a yearly average. It is good to know it is already expanded as a daily series in pipeline. Thanks for your explanation.

No problem !