zipline是quantopion贡献的一个股票开源回测框架,我在windows 7环境尝试使用yahoo bundle时,报错
- sqlite3.OperationalError: unable to open database file
调查了原因,是由于源码中使用"working_file", 会占用sqlite3要使用文件的句柄,导致sqllite3无法使用所需文件,
```
adjustment_db_writer = SQLiteAdjustmentWriter(
stack.enter_context(working_file(
adjustment_db_path(name, timestr, environ=environ),
)).path,
BcolzDailyBarReader(daily_bars_path),
bundle.calendar,
overwrite=True,
)
```
working_file的功能是先创建临时文件供使用,并在__exit__时,如果未发生异常,则将临时文件最终移动到希望的位置,这样的好处是如果zipline ingest没有成功,则目标目录不会产生脏文件。
完美的处理此问题需要修改不少源码,现在zipline社区里已经有人动手在修改此bug,在修复前,临时的处理方法为,将源码修改为直接使用目标目录,
```
adjustment_db_writer = SQLiteAdjustmentWriter(
str(adjustment_db_path(name, timestr, environ=environ)),
BcolzDailyBarReader(daily_bars_path),
bundle.calendar,
overwrite=True,
)
```
另外,想要使用yahoo bundle,需要在目标目录的extension.py中增加如下代码,
```
from zipline.data.bundles import yahoo_equities, register, unregister
symbols = (
'AAPL',
'IBM',
'MSFT',
)
register('my_bundle', yahoo_equities(symbols))
```
zipline ingest yahoo bundle, 报错-sqlite3.OperationalError unable to open databas
猜你喜欢
转载自linc09.iteye.com/blog/2306281
今日推荐
周排行