Yes, one can fetch 5 years worth of data using pipeline and then calculate the average, or mean, ROIC. One issue with fundamental data is most of the rows are the same. Typically one only sees a change once a quarter when quarterly reports are released. So, we don't really want to average all the ROIC values, but rather just one from each quarter. The pandas drop_duplicates method can do this. There are however a couple of things to do beforehand.
First, add a column to our pipeline for the roic asof_date. This is the end date of the quarter for which the roic number applies. We will need this to be able to fetch only one row per filing. Next, add another column which is the asset. This is just a copy of the level 1 index , but makes using the drop_duplicates method easier. Something like this will plot the 10 companies with the largest 5 year mean ROIC. This assumes the pipeline output is 'result' and was run over 5 years
# Find the average (ie mean) roic by company (ie group by level=1)
# Create a column from the asset index. This makes using our 'drop_duplicates' method easier to use
# Lets just take the last roic per filing date so we don't have all the duplicates
result['asset'] = result.index.get_level_values(level=1)
unique_roic = result.drop_duplicates(['asset', 'roic_asof_date'], keep='last').roic
unique_roic_mean = unique_roic.groupby(level=1).mean()
# Take the 10 largest values and plot a bar chart
unique_roic_mean.nlargest(10).plot('bar')
Look at the attached notebook. The same as above but now some added cells plotting the 10 companies with the largest 5 year mean ROIC.
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.