Previous data, like financial_leverage
, can be fetched with the help of a small custom factor. Something like the following (there is also a relevant post with a similar issue here )
class Previous(CustomFactor):
def compute(self, today, assets, out, input):
out[:] = input[0]
# create a factor for financial_leverage 252 trading days ago (approx 1 calendar year)
leverage_prev = Previous(inputs=[Fundamentals.financial_leverage], window_length=252)
The Morningstar data is primarily based on the latest quarterly filing. So values like roa
will be the last quarter net Income / average total assets. The FactSet FS_Fundamentals.roa_af
will be the annual roa or last annual report net Income / total assets. It's probably best not to mix the two. A 'good' way to get a delta quarterly roa would be
roa = Fundamentals.roa.latest
roa_prev = Previous(inputs=[Fundamentals.roa], window_length=252)
delta_roa = roa / roa_prev
One could do the same thing with the FactSet annual data but it would only change annually. The quarterly Morningstar data will capture quarterly changes which may be good or bad depending on your application.
Now, I said this is a 'good' way, however simply looking back 252 trading days can lead to comparing the wrong quarters at times, especially near the dates where a quarterly report is released. To be more accurate, one would need to look at the asof_date
, subtract a year, then lookup the latest value with that previous asof_date
. A little more work but also a little more accurate.
Hope that helps.
Disclaimer
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by Quantopian. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. No information contained herein should be regarded as a suggestion to engage in or refrain from any investment-related course of action as none of Quantopian nor any of its affiliates is undertaking to provide investment advice, act as an adviser to any plan or entity subject to the Employee Retirement Income Security Act of 1974, as amended, individual retirement account or individual retirement annuity, or give advice in a fiduciary capacity with respect to the materials presented herein. If you are an individual retirement or other investor, contact your financial advisor or other fiduciary unrelated to Quantopian about whether any given investment idea, strategy, product or service described herein may be appropriate for your circumstances. All investments involve risk, including loss of principal. Quantopian makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances.