1
|
|
|
from __future__ import print_function |
2
|
|
|
from zipline.assets import AssetFinder |
3
|
|
|
|
4
|
|
|
from .classifier import Classifier |
5
|
|
|
from .engine import SimplePipelineEngine |
6
|
|
|
from .factors import Factor, CustomFactor |
7
|
|
|
from .filters import Filter |
8
|
|
|
from .term import Term |
9
|
|
|
from .graph import TermGraph |
10
|
|
|
from .pipeline import Pipeline |
11
|
|
|
from .loaders import USEquityPricingLoader |
12
|
|
|
|
13
|
|
|
|
14
|
|
|
def engine_from_files(daily_bar_path, |
15
|
|
|
adjustments_path, |
16
|
|
|
asset_db_path, |
17
|
|
|
calendar, |
18
|
|
|
warmup_assets=False): |
19
|
|
|
""" |
20
|
|
|
Construct a SimplePipelineEngine from local filesystem resources. |
21
|
|
|
|
22
|
|
|
Parameters |
23
|
|
|
---------- |
24
|
|
|
daily_bar_path : str |
25
|
|
|
Path to pass to `BcolzDailyBarReader`. |
26
|
|
|
adjustments_path : str |
27
|
|
|
Path to pass to SQLiteAdjustmentReader. |
28
|
|
|
asset_db_path : str |
29
|
|
|
Path to pass to `AssetFinder`. |
30
|
|
|
calendar : pd.DatetimeIndex |
31
|
|
|
Calendar to use for the loader. |
32
|
|
|
warmup_assets : bool, optional |
33
|
|
|
Whether or not to populate AssetFinder caches. This can speed up |
34
|
|
|
initial latency on subsequent pipeline runs, at the cost of extra |
35
|
|
|
memory consumption. Default is False |
36
|
|
|
""" |
37
|
|
|
loader = USEquityPricingLoader.from_files(daily_bar_path, adjustments_path) |
38
|
|
|
|
39
|
|
|
if not asset_db_path.startswith("sqlite:"): |
40
|
|
|
asset_db_path = "sqlite:///" + asset_db_path |
41
|
|
|
asset_finder = AssetFinder(asset_db_path) |
42
|
|
|
if warmup_assets: |
43
|
|
|
results = asset_finder.retrieve_all(asset_finder.sids) |
44
|
|
|
print("Warmed up %d assets." % len(results)) |
45
|
|
|
|
46
|
|
|
return SimplePipelineEngine( |
47
|
|
|
lambda _: loader, |
48
|
|
|
calendar, |
49
|
|
|
asset_finder, |
50
|
|
|
) |
51
|
|
|
|
52
|
|
|
|
53
|
|
|
__all__ = ( |
54
|
|
|
'Classifier', |
55
|
|
|
'CustomFactor', |
56
|
|
|
'engine_from_files', |
57
|
|
|
'Factor', |
58
|
|
|
'Filter', |
59
|
|
|
'Pipeline', |
60
|
|
|
'SimplePipelineEngine', |
61
|
|
|
'Term', |
62
|
|
|
'TermGraph', |
63
|
|
|
) |
64
|
|
|
|