Back to Community
How To Use Your Own Stocks with Quantopian?

So I don't want the algorithm to run through all the stocks out there, but I want it to use a handful of different stocks I give it each day to trade on. How would I go about doing this?


10 responses

Joshua -

See Alternatively, whatever process you are using to pick the stocks potentially could be coded into an algo to run on Quantopian.

Thanks Grant, I'm playing around with the CSV fetcher and I think this will do the trick. How can I view data from my csv in my Notebook to make sure it's working?

Are you using the backtester/algo IDE, or the Quantopian research platform?

@Joshua if you're using pipeline, you can use the make_us_equity_universe function to create your own dynamically allocated universe. You can read more about that here.

@Grant I'm using the Backtester with my algo.

You can output limited data to the log. There is also a debugger, which might be helpful. Another approach is to use the record function and then view data in the research platform, but this has limitations, and probably isn't best for your problem. I'd start with output to the log.

Just try:

print my_output

If you are using a Pandas DataFrame, then you may want to use my_output.head(5) and my_output.tail(5) just to confirm that everything is there, as expected.

Alright, I've got that part down now. I have one column for the "Date" and another for the "Symbol" of the stocks I want to trade. How can I take the stock symbols in my CSV and use their SIDs to trade with? Would I put this code in the pre_func?

import talib  
import pandas

def preview(df):  
    # Get stocks from CSV here?  
    return df

# Setup our variables  
def initialize(context):  
    context.stocks = symbols('SPY', 'QQQ') # These will need to come from CSV  
    fetch_csv('', pre_func = preview, post_func = None, date_column = 'Date', date_format='%m/%d/%y', timezone='UTC')  

Joshua -

Before you get too deep into this, I'm wondering what your objective might be? If you are aiming to get an allocation from Quantopian, I'm not sure they are so keen on fetcher, and may even not allow it (e.g. trading $50M with a link to an external google doc sounds like a non-starter). Also, note that Quantopian no longer supports retail trading (see

You may want to consider doing everything within the Quantopian API, using the supplied data.

Thanks Grant, I didn't realize Quantopian was shutting down retail trading.

My objective is this:
- Each morning I create my own watchlist of stocks that I want to trade. I would input these tickers into the CSV, and when certain criteria are met the algo would execute trades on those stocks.

I am not necessarily shooting for allocation from Quantopian on this algo, it is more for personal experimentation. If I use the Quantopian API to filter through stocks, I would not be able to personally pick out the ones I want traded each day. That's why I haven't gone down that road so far. I have the CSV loaded and can log the stock symbols, but I don't know how to pull the symbols out of that dataframe and use their SIDs for trading.

I'm not so familiar with this end of Quantopian, and would have to dig into it. I'm not planning to use fetcher down the road, so maybe someone else can lend a hand here.

If you know the complete universe you are trading in, it can be put into the algo explicitly as a list (e.g. using symbols). Then, point-in-time, your fetcher file would specify which stocks to trade, in the master list. There's probably a better way of doing things, but this should work.