Any examples with csv data
Let's say I have data in a csv format, are there any examples of loading historical data for backtesting from a csv or json file. Assuming I just have some proprietary data not available on Quantopian.
I have written some code to do this which is just a copy somewhat of the load_yahoo_data but using pandas read_csv and some file.glob patterns to load a bunch of files from a folder into a Pandas.Panel object.
You will need to make sure your data is adjusting itself and the correct columns come back.
Easiest way to debug this is to use a jupyter/ipython notebook and just use the functions and write your own in the window to parse it.
I'm using CSI data and it works ok, haven't got to slicing the data into specific time windows but thats very easy in pandas. Also missing/sparse data can be problematic as well, for instance you might want to test a universe of data but not all stocks start at the beginning date.
If you are really stuck I can dig out some of the code/gist it but it really is just using the building blocks of pandas and the python file system methods
If the data fits in memory, you can convert it into a Panel`` and pass that to the new run_algorithm function. If it is too large to fit in memory, or you would like to use this a lot, you can convert it into zipline's native data format. Information on how to do that is available here: http://www.zipline.io/bundles.html
Example code:
- Ed Bartosh: https://github.com/bartosh/zipline/blob/master/zipline/data/bundles/csvdir.py or
- Richard: http://www.prokopyshen.com/create-custom-zipline-data-bundle
Wondering if import csv functionality is of general helpfulness (like google and quandl import are) -- would it make sense to create a PR of latter code (debugged/hardened) to enhance standard zipline bundle imports?
x-ref https://github.com/quantopian/zipline/pull/1860
@llllllllll regarding:
If the data fits in memory, you can convert it into a Panel`` and pass that to the new run_algorithm function.
I'm passing a pandas.DataFrame to run_algorithm() using the data argument, so I can execute trades in Zipline's handle_data() method like this:
def handle_data(self, context, data):
order_target(symbol('LTC_BTC'), 100)
The pandas.DataFrame I'm passing contains OHLCV data, each as a column in the data frame. But, when order_target() is called, Zipline is raising the following error:
File "/home/mellertson/Documents/python_virtual_envs/zipline/local/lib/python2.7/site-packages/zipline/assets/assets.py", line 698, in _lookup_symbol_strict
raise SymbolNotFound(symbol=symbol)
SymbolNotFound: Symbol 'LTC_BTC' was not found.
The error makes sense, as I'm not registering a bundle with Zipline. What I'm trying to figure out is, by passing a DataFrame or Panel to run_algorithm() in the data argument, is it possible to place orders with that data? What is the recommended format of a pandas.DataFrame passed as the data argument to run_algorithm()?
@llllllllll
Any working sample where we can run a script with data passed into the handle_data with data argument as panel data and then using TradingAlgorithm and run method without using any ingest method. That way the script data can be completed independent to the environment.
like in this https://github.com/quantopian/pyfolio/blob/master/pyfolio/examples/zipline_algo_example.ipynb
@mellertson - Where you able to get this working with order_target, just having panel data with symbol and date as the index and the columns as OHLCV as columsn.? Any sample code you can share just to get starting.
I have a similar request as that of @Spider08 , am really confused to how to access data on zipline so that to perform actions on them without using data.history() function. I was practicing on pandas before and it was easy to perform operations on it such as to find the max value in a given period we use:
import pandas_datareader.data as web
start = dt.datetime(2017, 5, 1)
end = dt.datetime(2017, 7, 30)
df = web.DataReader('AAPL', 'google', start, end) # retrieving data from google
highest_value = df['High'].max()
Theirs extremely less guide on how to access data to perform actions other than finding EMA! ANd also i want to know how to run codes from within the IDE without having the need to run through CLI. I will be more than happy if anybody answers my query, Thanks.
I've just posted easier way to do it. Please, have a look: https://github.com/quantopian/zipline/issues/174#issuecomment-331836005
Closing in favor of #2060
I have written some code to do this which is just a copy somewhat of the load_yahoo_data but using pandas read_csv and some file.glob patterns to load a bunch of files from a folder into a Pandas.Panel object.
You will need to make sure your data is adjusting itself and the correct columns come back.
Easiest way to debug this is to use a jupyter/ipython notebook and just use the functions and write your own in the window to parse it.
I'm using CSI data and it works ok, haven't got to slicing the data into specific time windows but thats very easy in pandas. Also missing/sparse data can be problematic as well, for instance you might want to test a universe of data but not all stocks start at the beginning date.
If you are really stuck I can dig out some of the code/gist it but it really is just using the building blocks of pandas and the python file system methods
Will the panel method slow down the speed of back-testing?