Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
MarketCap Issue Using Pipeline for Real Money Trading

I got a warning message from all my algo that are using MarketCap class. To my best knowledge, it was caused by unadjusted data. I am wondering whether anyone has a way to workaround. Couple of my algo are waiting for this final missing piece

Thanks.

Warning NotAllowedInLiveWarning: The fundamentals attribute valuation.shares_outstanding is not yet allowed in broker-backed live trading

class MarketCap(CustomFactor):  
    inputs = [USEquityPricing.close, morningstar.valuation.shares_outstanding]  
    window_length = 1  
    def compute(self, today, assets, out, close, shares):  
        out[:] = close[-1] * shares[-1]  
3 responses

One way around it (and this might be unpalatable) is to use market cap directly from the morningstar data set in pipeline.

The reason this isn't used in the samples is as follows:
1) Quantopian gets daily updates from Morningstar
2) In these daily updates, a new value for market cap is delivered.
3) We have daily, fresh updates of market cap for the time period of approximately 6/1/2014 to present day.
4) Historic Morningstar data from before Quantopian had an agreement with Morningstar only provides monthly updates. When we got our initial set of data from Morningstar, we only got monthly values for market cap for the time period of 2002 - 6/1/2014.

The impact of this is that for your backtest, you'll see static values for market cap for a month. It will only change on or around the 1st of the month, each month from 2002 - 2014. Then, in 2014, you'll see the market cap updating daily in the backtester.

Hope this helps,
Josh

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.

@ Josh: Can you give me an example code to explain how to implement it?

Is there any way to calculate MarketCap without using pipeline?

You can use the get_fundamentals() function to get the market cap data.

Here's a simple example of getting market cap with pipeline:

from quantopian.algorithm import attach_pipeline, pipeline_output  
from quantopian.pipeline import Pipeline  
from quantopian.pipeline.data import morningstar

def initialize(context):

    # Create and attach an empty Pipeline.  
    pipe = Pipeline()  
    pipe = attach_pipeline(pipe, name='my_pipeline')

    pipe.add(morningstar.valuation.market_cap.latest, 'market_cap')

def before_trading_start(context, data):  
    # Access results using the name passed to `attach_pipeline`.  
    results = pipeline_output('my_pipeline')  
    print results.sort('market_cap', ascending=False).head(10)

    # Define a universe with the results of a Pipeline.  
    update_universe(results.sort('market_cap', ascending=False).index[:10])  

def handle_data(context, data):  
    pass