Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
New to Quantopian. I have a list of stocks in a CSV file I want to buy. How do I backtest this?

Hi,

I have a csv file with a list of stocks that I want to buy for each date. The CSV file is uploaded to dropbox and looks something like this:

DATE, 0, 1, 2
2014-01-01 BOBE, F, AXE
2014-01-15 GM, NFLX, TSLA
2014-01-29 GM, F, AXE
etc.

I want to rebalance every two weeks.

Thank you!

1 response

https://www.quantopian.com/help#overview-fetcher might be somewhat relevant. This is for loading stock prices, but the general strategy for accessing external data seems to be to host it with a publically available URL (like on dropbox) and then just access that URL from your algorithm. Something like:

context.buy_on = {}  
for row in csv.reader(urllib.open("http://dropbox.com/your/csv/file")):  
  date = dateutil.parser.parse(row[0])  
  symbols = row[1:]  
  context.buy_on[date] = securities(symbols)  

Now buy_on is a dictionary mapping from dates to the symbols to buy on that date.

Now in handle_date you have a check like

today = get_datetime().date()  
if today in context.buy_on:  
   buy_stocks(context.buy_on[today])  

That should be a start.