When it comes to backtesting more exhaustively, I thought it would be nice to automate the run of several backtests on an algo (ie 1-month runs starting on the 1st of each month over last 3 years, and using 3 different starting cash balances for each run...generating 12*3*3=108 backtests). To do this, I thought zipline would be the way to go! It doesn't have fetch_csv()
support, so I set out to write it myself. I'm new to pandas, so I'm stuck on how to take the Panel
returned by load_bars_from_yahoo()
(the data
object created in our Quantopian algos) and add some columns to it from the Dataframe
returned by fetch_csv
.
Here's a code skeleton for what I'm trying to do:
def fetch_csv(csv_url, pre_func, post_func, date_column, date_format, **kwargs):
""" Mimics Quantopian's Fetcher
"""
global data # this will pull in the data provided by load_bars_from_yahoo() from the outer scope
df = pd.DataFrame.from_csv(csv_url, parse_dates=[date_column], infer_datetime_format=True) #, post_func, date_column, date_format)
# This next line is bogus, but I'm looking for the correct syntax to join `df` with `data`
data.add(df)
return df
For each symbol in data
, there is a corresponding Dataframe indexed on a date. I would like to take the date_column
values from df
and insert other columns from the CSV data (now in df
) into data
for the corresponding dates and symbols.
I've also posted this question on StackOverflow, but echoing it here as quantopian
is not a valid tag there (yet).
http://stackoverflow.com/questions/32996121/creating-fetch-csv-for-zipline-how-to-add-columns-to-load-bars-from-yahoo
Thoughts? Is this some code the Quantopian team might release?