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

Hi guys,

Does anybody know why I get different outputs from these in research against the backtester?

In Research I am running:

import pandas as pd  
import datetime

fundamentals = init_fundamentals()

today = (datetime.datetime.now()-datetime.timedelta(days=2)).strftime('%Y-%m-%d')  
period_of_interest = (datetime.datetime.now() - datetime.timedelta(days=8)).strftime('%Y-%m-%d')

daily_query = get_fundamentals(query(fundamentals.asset_classification.morningstar_industry_code,  
                                     fundamentals.balance_sheet.total_assets,  
                                      fundamentals.financial_statement_filing.file_date,  
                                      fundamentals.valuation.market_cap)  
                                      .filter(fundamentals.valuation.market_cap > 1)  
                                      .filter(fundamentals.financial_statement_filing.file_date > period_of_interest)  
                                      .order_by(fundamentals.valuation.market_cap.desc())  
                                      .limit(1),  
                                      today)  
print daily_query  

which (running on 25 Aug) I believe gives me the last filing for the largest market cap if it is within 6 days of the 23rd (as in the last full run date available in the back tester)

The output is:

security Equity(8229 [WMT])
morningstar_industry_code 20533079
total_assets 1.9862e+11
file_date 2015-08-18
market_cap 220833020999

In the back tester I am running (23rd to 24th):

import pandas as pd  
import datetime

def initialize(context):  
    pass

def handle_data(context, data):  
    pass

def before_trading_start(context):  
    #today = datetime.datetime.now().strftime('%Y-%m-%d')  
    period_of_interest = (datetime.datetime.now() - datetime.timedelta(days=8)).strftime('%Y-%m-%d')  
    daily_query = get_fundamentals(query(fundamentals.asset_classification.morningstar_industry_code,  
                                         fundamentals.balance_sheet.total_assets,  
                                         fundamentals.financial_statement_filing.file_date,  
                                         fundamentals.valuation.market_cap  
                                        )  
                                      .filter(fundamentals.valuation.market_cap > 1)  
                                      .filter(fundamentals.financial_statement_filing.file_date > period_of_interest)  
                                      .order_by(fundamentals.valuation.market_cap.desc())  
                                      .limit(1)  
                                   )  
    print daily_query  
    update_universe(daily_query.columns.values)  

There is no output to the log and I do not appear to have any securities in my universe. Does anyone know what I am not understanding about how it works?

2 responses

The issue you are running into is your use of datetime.datetime.now() in the backtest, we feed you the current datetime with the get_datetime() method. Replace datetime.datetime.now() with get_datetime() and you should start seeing results.

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.

Thanks Christopher - I knew I was being stupid but didn't know how