Data Bundles¶
How To Use It¶
zipline ingest -b alpaca_api
The bundle is defined in this file:
zipline/data/bundles/alpaca_api.py
and you will execute it to ingest.There is a method called
initialize_client()
, it relies on the fact that you define your alpaca credentials in a file calledzipline-trader.yaml
as described in the configuration file section.Selecting your universe - which means: what stocks should be included in the ingested DB. The smaller the universe, the faster the ingestion is. Selecting the universe is completely up to you, but I do suggest to start small when learning how to use the platform. Supported universes:
class Universe(Enum): ALL = "ALL" # The entire ~8000 stocks supported by Alpaca SP100 = "S&P 100" SP500 = "S&P 500" NASDAQ100 = "NASDAQ 100"
Alternatively you could specify a custom asset list inside the
zipline-trader.yaml
file if, for instance you want to ingest a small number of assets. You do thisalpaca: key_id: "<YOUR-KEY>" secret: "<YOUR-SECRET>" base_url: https://paper-api.alpaca.markets custom_asset_list: AAPL, TSLA, GOOG
Please note that:
The assets must be all caps
separated by commas
if
custom_asset_list
is specified thenuniverse
is ignored if present.
you need to define your ZIPLINE_ROOT in an environment variable (This is where the ingested data will be stored). You need this env variable in for every zipline related script you execute (that includes the ingestion process, your research notebooks, and backtests you run) .It should be something like this:
ZIPLINE_ROOT=~/.zipline
note: Your root directory as defined previously is independent from the ZIPLINE_ROOT directory. You could define both in the same location or if you wish to store your DB else where, it’s fine too.note: ~/.zipline means your home directory with .zipline directory in it.note: You could set it as an absolute path too. e.g:ZIPLINE_ROOT=/opt/project/.zipline
It means you could basically put it anywhere you want as long as you always use that as your zipline root.It also means that different bundles could have different locations.By default the bundle ingests 30 days backwards, but you can change that under the
__main__
section ofzipline/data/bundles/alpaca_api.py
.To ingest the bundle you need to run the ingestion script directly. Run this:
cd zipline_trader/ python zipline/data/bundles/alpaca_api.py
Notes¶
You are ready to research, backtest or paper trade using the pipeline functionality.
You should repeat this process daily since every day you will have new price data.
This data doesn’t include Fundamental data, only price data so we’ll need to handle it separately.