Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Fundamentals Charts

Hi all,

I'm new to Quantopian. I'm looking to bar chart some fundamentals (e.g. ROIC and revenue growth) for the last quarter (say) so I can compare and rank companies by e.g. ROIC/revenue/other. Thinking real simple bar chart with highest to lowest (top 10/20/30 etc)

Any help much appreciated as the charting tutorials are very much setup for time series viz.

Cheers,
Nick

5 responses

Fundamental data is fetched using 'pipeline'. The output is a dataframe containing columns with specified data. With the data in a dataframe one can use the various pandas methods to slice and dice and sort the things before finally applying theplot method to visualize the data. Once the pipeline is set up just a few lines of code is needed

# Assume 'result' is the dataframe returned by the pipeline  
# If we just want a specific 'as of' date use xs method  
current_results = result.xs('9-28-2018', level=0)

# Use the plot method to plot this data. Specify 'bar' for bar charts.  
# Maybe just take the top 10 largest revenue_growth  
current_results.nlargest(10, 'revenue_growth').revenue_growth.plot('bar')

One can do a lot of manipulation and make some very appealing graphs with the addition of some parameters. This shows how to get the basics. Attached is a notebook. Happy plotting!

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.

Fantastic - many thanks Dan!

Dan,

Quick follow-up question - I want to show the same views with the average ROIC over a 5-year period. How can this be best done?

Any help much appreciated!

Nick

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.

Dan - thanks again

Cheers
N