New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Interactive conveniences #836
Changes from all commits
f169bb0
ac7b44a
7aa04a2
5d8a915
0b2787a
01b820d
f1d33ae
6672542
26cef8d
121632e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,63 @@ | ||
from __future__ import print_function | ||
from zipline.assets import AssetFinder | ||
|
||
from .classifier import Classifier | ||
from .engine import SimplePipelineEngine | ||
from .factors import Factor, CustomFactor | ||
from .filters import Filter | ||
from .term import Term | ||
from .graph import TermGraph | ||
from .pipeline import Pipeline | ||
from .loaders import USEquityPricingLoader | ||
|
||
|
||
def engine_from_files(daily_bar_path, | ||
adjustments_path, | ||
asset_db_path, | ||
calendar, | ||
warmup_assets=False): | ||
""" | ||
Construct a SimplePipelineEngine from local filesystem resources. | ||
|
||
Parameters | ||
---------- | ||
daily_bar_path : str | ||
Path to pass to `BcolzDailyBarReader`. | ||
adjustments_path : str | ||
Path to pass to SQLiteAdjustmentReader. | ||
asset_db_path : str | ||
Path to pass to `AssetFinder`. | ||
calendar : pd.DatetimeIndex | ||
Calendar to use for the loader. | ||
warmup_assets : bool, optional | ||
Whether or not to populate AssetFinder caches. This can speed up | ||
initial latency on subsequent pipeline runs, at the cost of extra | ||
memory consumption. Default is False | ||
""" | ||
loader = USEquityPricingLoader.from_files(daily_bar_path, adjustments_path) | ||
|
||
if not asset_db_path.startswith("sqlite:"): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. does it need to be sqlite? the backend supports any sqldb no? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe this is better as:
|
||
asset_db_path = "sqlite:///" + asset_db_path | ||
asset_finder = AssetFinder(asset_db_path) | ||
if warmup_assets: | ||
results = asset_finder.retrieve_all(asset_finder.sids) | ||
print("Warmed up %d assets." % len(results)) | ||
|
||
return SimplePipelineEngine( | ||
lambda _: loader, | ||
calendar, | ||
asset_finder, | ||
) | ||
|
||
|
||
__all__ = [ | ||
__all__ = ( | ||
'Classifier', | ||
'CustomFactor', | ||
'engine_from_files', | ||
'Factor', | ||
'Filter', | ||
'Pipeline', | ||
'SimplePipelineEngine', | ||
'Term', | ||
'TermGraph', | ||
] | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from .equity_pricing_loader import USEquityPricingLoader | ||
|
||
__all__ = ['USEquityPricingLoader'] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
from zipline.utils.input_validation import expect_types, optional | ||
|
||
from .term import Term | ||
from .term import Term, AssetExists | ||
from .filters import Filter | ||
from .graph import TermGraph | ||
|
||
|
@@ -145,3 +145,22 @@ def to_graph(self, screen_name, default_screen): | |
columns[screen_name] = screen | ||
|
||
return TermGraph(columns) | ||
|
||
def show_graph(self, format='svg'): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added an explicit There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. kk |
||
""" | ||
Render this Pipeline as a DAG. | ||
|
||
Parameters | ||
---------- | ||
format : {'svg', 'png', 'jpeg'} | ||
Image format to render with. Default is 'svg'. | ||
""" | ||
g = self.to_graph('', AssetExists()) | ||
if format == 'svg': | ||
return g.svg | ||
elif format == 'png': | ||
return g.png | ||
elif format == 'jpeg': | ||
return g.jpeg | ||
else: | ||
raise ValueError("Unknown graph format %r." % format) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is this not the repr? Same above
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had it as the repr originally, but that's really annoying if you have a list of these or something. Too much text I think.