Back to Community
how to find market cap for specific date

Hello, any idea on how to find market cap for a stock on a specific date (or use shares oustanding * last close to calculate it)

Here is my example on how I get the specific day high, but would like to be able to do market cap in the same way...

test_day = '2017-06-29'
stock_syms = symbols([ 'TPX', 'COMM', 'AAPL' ])

all_pricing_df_h = get_pricing(stock_syms, start_date=test_day, end_date=test_day, fields='high', frequency='daily')
all_pricing_df_h #print

 Equity(25802 [TPX])    Equity(45734 [COMM])    Equity(24 [AAPL])  

2017-06-29 00:00:00+00:00 55.45 38.437 145.13

Thanks a lot and please advice!

8 responses

In IDE it may looks like this:

from quantopian.pipeline import Pipeline, factors, filters, classifiers  
from quantopian.algorithm import attach_pipeline, pipeline_output  
# --------------------------------------------------------------  
STK_SET = filters.StaticAssets(symbols( 'TPX', 'COMM', 'AAPL' ))  
# --------------------------------------------------------------  
def initialize(context):  
    mcap = factors.MarketCap(window_length = 1, mask = STK_SET)  
    attach_pipeline(Pipeline(columns = {'mcap': mcap}, screen = STK_SET), 'pipe')

def before_trading_start(context, data):  
    output = pipeline_output('pipe')  
    market_cap = output.mcap  
    print market_cap  
'''
START  
04/10/2019  
END  
04/11/2019

'''

2019-04-10 05:45 PRINT
Equity(24 [AAPL]) 9.406984e+11
Equity(25802 [TPX]) 3.254482e+09
Equity(45734 [COMM]) 4.709469e+09

2019-04-11 05:45 PRINT
Equity(24 [AAPL]) 9.459795e+11
Equity(25802 [TPX]) 3.483193e+09
Equity(45734 [COMM]) 4.809507e+09

Thanks a lot Vladimir, but how I can do it for a specific date in the past, let's say for '2017-06-29'

how I can do it for a specific date in the past?
Just set the backtester for the desired dates.
And Build Algorithm.

START
06/28/2017
END
06/29/2017

2017-06-29 05:45 PRINT
Equity(24 [AAPL]) 7.603343e+11
Equity(25802 [TPX]) 2.741764e+09
Equity(45734 [COMM]) 7.399385e+09

Can you please point me to a link or article, I am not sure how to set the backtester for a specific date. Thanks!

This one is old but may help you.

In Research Notebook you may try something like this:

from quantopian.pipeline.filters import StaticAssets  
from quantopian.pipeline.data import Fundamentals  
from quantopian.research import run_pipeline  
from quantopian.pipeline import Pipeline

assets_list = symbols(['TPX', 'COMM', 'AAPL'])  
pipe = Pipeline(columns = {  
    'mcap':Fundamentals.market_cap.latest},  
                screen = StaticAssets(assets_list)) 

results = run_pipeline(pipe, '2017-06-29', '2017-06-29')  
results  

2017-06-29 00:00:00+00:00
Equity(24 [AAPL]) 7.603343e+11
Equity(25802 [TPX]) 2.741764e+09
Equity(45734 [COMM]) 7.399385e+09

Hi Vladimir, it works great!

Thanks a lot for your help, just one last question, how I can get the market cap in millions... instead of exponential result 2.741764e+09 or even 2741764000, to get it rounded to millions for simplicity: 2,742

Thanks again, LJ

Try this in billions.

from quantopian.pipeline.filters import StaticAssets  
from quantopian.pipeline.data import Fundamentals  
from quantopian.research import run_pipeline  
from quantopian.pipeline import Pipeline

assets_list = symbols(['TPX', 'COMM', 'AAPL'])  
pipe = Pipeline(columns = {'mcap':Fundamentals.market_cap.latest/1000000000},screen = StaticAssets(assets_list)) 

results = run_pipeline(pipe, '2017-06-29', '2017-06-29')  
results  

2017-06-29 00:00:00+00:00 Equity(24 [AAPL]) 760.334287
Equity(25802 [TPX]) 2.741764
Equity(45734 [COMM]) 7.399385