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

Hi All -

I'm trying to use the backtester to look at a trading strategy for mutual funds (I understand this is rarely the investment vehicle of choice for algorithmic traders). So I wanted to read in the price data of a few mutual funds using the fetch_csv routine but how do I assign a sid? Here is my code so far:

# Put any initialization logic here.  The context object will be passed to  
# the other methods in your algorithm.  
def initialize(context):  
    fetch_csv('https://www.dropbox.com/s/r9vyuyqw9ldyrc3/FUGAX.csv',  
              date_column='Date',  
              symbol='FUGAX',  
              date_format='%m/%d/%Y')



# Will be called on every trade event for the securities you specify.  
def handle_data(context, data):  
    # Implement your algorithm logic here.

    # data[sid(X)] holds the trade event data for that security.  
    # data.portfolio holds the current portfolio state.

    # Place orders with the order(SID, amount) method.

    # TODO: implement your own logic here.  
    order(data['FUGAX'], context.portfolio.cash/data['FUGAX'].price)  

EDIT: The error I get is,

Error Algorithm must reference 1 to 10 SIDs, inclusive.

Is the backtester limited to a universe of only 10 securities?

4 responses

Hello Daniel - Unfortunately, Quantopian only lets you buy and sell sids that are already in our database.

Fetcher lets you:
- You can add data to a sid, like adding the open interest to Apple
- You can import a "naked" time series of data, like the price of palladium, or a mutual fund

What you can't do is trade a "naked" imported time series.

One of my most desired new features is to update the backtester so you can "trade anything." However, to get most of the benefits of Quantopian, your time series has to have a price and a volume time series. I suspect what you're working with is just a series of prices, and that is even a step further than the feature I've had in mind.

Shorter answer: it's on the list, but it's not there yet.

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 Dan - I was afraid of that. Just FYI, there are data feeds available (I'm using IQ Feed) that have price and volume data, even minute resolution, that can be ported out to csv format. My initial algorithmic trading attempts were with a program called AmiBroker, which interfaces with IQ Feed. Unfortunately the AmiBroker API, a language unique to AmiBroker called AFL (AmiBroker Formula Language) is incredibly unpredictable and "black box". I couldn't vet any of my code, had to rely on their pre-fabricated closed-source functions and would get different results running the same simulation twice!

So.... what I'm saying is that even though adding the ability to trade naked imports may mean not all features are available, I'm glad it is still on the list of additions.

A question for Dan--
"One of my most desired new features is to update the backtester so you can "trade anything." However, to get most of the benefits of Quantopian, your time series has to have a price and a volume time series. ..Shorter answer: it's on the list, but it's not there yet."

So can we trade anything now?It's already November.

Unfortunately, it's still one of many great ideas on our list. I don't have an estimate of when we'll get to it. So many great feature ideas!