Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
fetch_csv limitations

Hi guys,

I have to questions regarding the fetcher:

1-Is is possible to download an arbitrary csv, i.e. do something like this:

df = fetch_csv('www.url/file.csv')  

where the data is not associated with any stock symbol or date?

2-If I update my CSV daily, how can I download the new data if fetch_csv can only be used within initialize?

3 responses

Hi Jean,

  1. It is possible to load an arbitrary time series data set using fetcher. Fetcher makes a distinction between "Symbol" data and "Signals" data. From the docs on fetcher:

For Signals, your CSV file does not need a symbol column. Instead, you provide it via the symbol parameter:

def initialize(context):  
    fetch_csv('http://yourserver.com/cpi.csv', symbol='cpi')  
    context.stock = symbol('AAPL')

def handle_data(context, data):  
    # get the cpi for this date  
    current_cpi = data['cpi']['value']

    # plot it  
    record(cpi=current_cpi)
  1. In a live trading scenario, initialize is run every day so updates to your csv can be used, as long as you append the new data to the end of the file. I'd encourage you to read the fuller documentation on this particular topic to ensure you understand the requirements.

Good luck!

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.

Hi Josh, thanks for your answer! In handle_data:

def handle_data(context, data):  
    # get the cpi for this date  
    current_cpi = data['cpi']['value']  

What if I want to have access to this data regardless of the date? Is there a reason why this needs to be so complicated in comparison with a simple:

context.df = fetch_csv('www.url/file.csv')

The data in your file will be available from the first date in the file. Then it will be forward-filled until the date changes.

So if you want to have the data alway available, then you can have a single unchanged date in the CSV. Here's an example where the algo has access to all of the stocks in the Fetcher file (from Oct 1, 2013-present): https://www.quantopian.com/posts/define-custom-universe-via-fetcher-using-the-new-universe-func-callback

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.