Data Bundles
A data bundle is a collection of pricing data, adjustment data, and an asset database. Bundles allow us to preload all of the data we will need to run backtests and store the data for future runs.
数据包是定价数据,调整数据和资产数据库的集合。 Bundles允许我们预先加载所有需要运行回测的数据并存储数据以供将来运行。
Discovering Available Bundles发现可用的捆绑包
Zipline comes with a few bundles by default as well as the ability to register new bundles. To see which bundles we have available, we may run the bundles
command, for example:
Zipline默认带有几个捆绑包以及注册新捆绑包的功能。 要查看我们可用的捆绑包,我们可以运行捆绑命令,例如:
1
2
3
4
5
6
|
$ zipline bundles
my-custom-bundle 2016-05-05 20:35:19.809398
my-custom-bundle 2016-05-05 20:34:53.654082
my-custom-bundle 2016-05-05 20:34:48.401767
quandl <no ingestions>
quantopian-quandl 2016-05-05 20:06:40.894956
|
The output here shows that there are 3 bundles available: 这里的输出显示有3个可用包:
my-custom-bundle
(added by the user)quandl
(provided by zipline)quantopian-quandl
(provided by zipline)
The dates and times next to the name show the times when the data for this bundle was ingested. We have run three different ingestions for my-custom-bundle
. We have never ingested any data for the quandl
bundle so it just shows <no ingestions>
instead. Finally, there is only one ingestion for quantopian-quandl
.
名称旁边的日期和时间显示摄取这个包的数据的时间。对 my-custom-bundle
有三种不同的提示。我们从来没有摄入任何quandl包的数据,所以它只是显示<no ingestions>。最后,Quantopian-quandl只有一次摄取。
Ingesting Data
The first step to using a data bundle is to ingest the data. The ingestion process will invoke some custom bundle command and then write the data to a standard location that zipline can find. By default the location where ingested data will be written is $ZIPLINE_ROOT/data/<bundle>
where by default ZIPLINE_ROOT=~/.zipline
. The ingestion step may take some time as it could involve downloading and processing a lot of data. You’ll need a Quandl API key to ingest the default bundle. This can be run with:
使用数据包的第一步是摄取数据。摄入过程将调用一些自定义捆绑命令,然后将数据写入zipline可以找到的标准位置。默认情况下,写入数据的位置是$ ZIPLINE_ROOT / data / <bundle>,默认情况下ZIPLINE_ROOT =〜/ .zipline。摄取步骤可能需要一些时间,因为它可能涉及下载和处理大量数据。您需要一个Quandl API密钥来获取默认包。这可以通过以下方式运行:
$ QUANDL_API_KEY=<yourkey> zipline ingest [-b <bundle>]
where <bundle>
is the name of the bundle to ingest, defaulting to quandl
. 其中<bundle>是要摄取的包的名称,默认为quandl。
Old Data
When the ingest
command is used it will write the new data to a subdirectory of $ZIPLINE_ROOT/data/<bundle>
which is named with the current date. This makes it possible to look at older data or even run backtests with the older copies. Running a backtest with an old ingestion makes it easier to reproduce backtest results later.
当使用ingest
命令时,它会将新数据写入到以当前日期命名的$ ZIPLINE_ROOT / data / <bundle>的子目录中。这使得可以查看较旧的数据,甚至可以使用较旧的副本进行反向测试。使用旧的服务运行回测可以更容易地在以后重新生成回测结果。
One drawback of saving all of the data by default is that the data directory may grow quite large even if you do not want to use the data. As shown earlier, we can list all of the ingestions with the bundles command. To solve the problem of leaking old data there is another command: clean
, which will clear data bundles based on some time constraints.
默认情况下保存所有数据的一个缺点是,即使您不想使用数据,数据目录也可能变得非常大。如前所示,我们可以使用bundles命令列出所有的提示。为了解决泄露旧数据的问题,还有另外一个命令:clean,它将根据一些时间限制清除数据包。
For example:
# clean everything older than <date>
$ zipline clean [-b <bundle>] --before <