Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Some trouble with Fetcher syntax

Hi All -

I'm trying to use Fetcher to pull some outside data into the backtester:

def rename_col(df):  
    df = df.rename(columns={'XLB': 'rank'})  
    df = df.fillna(method='ffill')  
    df = df[['rank', 'sid']]  
    log.info(' \n %s % df.head()')  
    return df

def initialize(context):  
    #Read the rankings  
    fetch_csv('https://www.dropbox.com/s/3cj153w85xs1mjo/XLB_Ranks.csv',  
              date_column='Date',  
              symbol=sid(19654),  
              post_func=rename_col)  


def handle_data(context, data):  
    if 'rank' in data[sid(19654)]:  
        log.debug (str(data[sid(19654)]['rank']))  

So... a few questions. First, this code is giving me the following error

File testalgorithm_sycheck.py:16, in initialize
File algoproxy.py:1411, in fetch_csv
File requests_csv.py:359, in __init
_
File requests_csv.py:255, in load_df
File requests_csv.py:365, in fetch_data
File parsers.py:400, in parser_f
File parsers.py:205, in _read
File parsers.py:608, in read
File parsers.py:1028, in read
File parser.pyx:706, in pandas.parser.TextReader.read (pandas/parser.c:6745)
File parser.pyx:728, in pandas.parser.TextReader._read_low_memory (pandas/parser.c:6964)
File parser.pyx:781, in pandas.parser.TextReader._read_rows (pandas/parser.c:7568)
File parser.pyx:768, in pandas.parser.TextReader._tokenize_rows (pandas/parser.c:7451)
File parser.pyx:1661, in pandas.parser.raise_parser_error (pandas/parser.c:18744)

Also, if I'm doing this for 9 different sids, is there an easier way than creating, saving and importing each separately?

Thanks all.

3 responses

Daniel, your URL is hitting a "pretty" HTML page from Dropbox. Fetcher is faithfully trying to parse that "pretty" page and failing. You need to find the other link. It starts something like https://dl.dropboxusercontent.com/s/

That type of link is to the actual file.

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.

Oh - and what you should do is make a column in your file called ''symbol" and then put the stock's symbol in the data in that column. That way you can load many different stocks in a single file, and the data is linked within Quantopian based on that symbol column.

Darn pretty files.... lol - Thanks Dan.