Back to Community
fetch_csv and context

I'm trying to load a list of symbols using fetch_csv and iterate through the symbols using a for loop. I'm a bit lost on how to do this. Here is what I have so far -- please help. Thanks.

def initialize(context):  
    # import the custom CSV data file  
    fetch_csv('https://docs.google.com/spreadsheets/d/1jOfn45Hyjeg4ZwaxwGc8PE8ZMnoewIaL6DEcA0eaAEw/pub?output=csv',  
              date_column='dummydate')

def handle_data(context,data):  
    #iterate through list of symbols found in the csv file  
    for stock in fetcher_data:  
        if stock.price > 100:  
              do something  
6 responses

I think I'm closer but data.fetcher_assets() is empty.

def initialize(context):  
    # import the custom CSV data file  
        fetch_csv('https://docs.google.com/spreadsheets/d/1jOfn45Hyjeg4ZwaxwGc8PE8ZMnoewIaL6DEcA0eaAEw/pub?output=csv',  
              date_column='dummydate')

def handle_data(context,data):  
    for sec in data.fetcher_assets():  
        log.info(data.current(sec, 'price'))  

Are you running the backtest on the same dates defined in the date column in your CSV?

Hi Brian,

I have the same issue data.fetcher_assets is empty. Have you figured out the resolution?

I had a similar issue, and resolved it with a pre_func that modifies the dates forward to today's date so it works in live trading. In backtesting the dates need to be the date you want the backtest to start using the security, or an earlier date to work always (ie. 1/1/2002)

see the code at https://www.quantopian.com/posts/dynamic-tspp-list

Thanks Luke just want to ask what does kwargs do?

kwargs = {'sep':'|','dtype':{'Effective_Date':str}}  

I'm not 100% sure, I kind of stumbled through that part but the way I understood it is that quantopian's "fetch_csv" function really is just an custom addition to pandas "read_csv" function. kwargs are arguments that are passed to the read_csv function within fetch_csv that help tell it how to parse your CSV file. The file I was using was from a source that I can't control and their csv is actually a .txt file with "|" as the separator instead of commas, their date format is also a non-standard string like "02102016" instead of something that quantopian understands as a date. So I had to tell read_csv to treat the effective_date column as a string so that quantopian could understand better.

http://pandas.pydata.org/pandas-docs/stable/generated/pandas.read_csv.html