-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Added loaders parameter to run_algorithm() in run_algo.py #2199
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
Closed
Closed
Changes from 13 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
d523c83
Added ability to use a custom loader in run_algorithm()
calmitchell617 2a8018b
run_algorithm() can now accept an optional dictionary of PipelineLoaders
calmitchell617 d1e96b4
ignoring vscode setting json file
calmitchell617 bc0ca30
removed vscode json settings
calmitchell617 4579095
ignore gitignore
calmitchell617 c4dd280
removed gitignore
calmitchell617 db45582
added gitignore back
calmitchell617 ef6c860
changed some formatting
calmitchell617 3bfeb7b
changed formatting
calmitchell617 9451c4e
formatting
calmitchell617 67ee985
formatting
calmitchell617 01e3ef9
sorry for all these formatting changes
calmitchell617 339923b
just trying to keep consistent with what was already here
calmitchell617 ebcf747
changed language to show that this argument is for loading dataframes
calmitchell617 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -76,3 +76,5 @@ TAGS | |
| .ipynb_checkpoints/ | ||
|
|
||
| .gdb_history | ||
|
|
||
| .vscode | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -71,7 +71,8 @@ def _run(handle_data, | |
| print_algo, | ||
| metrics_set, | ||
| local_namespace, | ||
| environ): | ||
| environ, | ||
| loaders): | ||
| """Run a backtest for the given algorithm. | ||
|
|
||
| This is shared between the cli and :func:`zipline.run_algo`. | ||
|
|
@@ -168,9 +169,12 @@ def _run(handle_data, | |
| def choose_loader(column): | ||
| if column in USEquityPricing.columns: | ||
| return pipeline_loader | ||
| raise ValueError( | ||
| "No PipelineLoader registered for column %s." % column | ||
| ) | ||
| elif column in loaders: | ||
| return loaders[column] | ||
| else: | ||
| raise ValueError( | ||
| "No PipelineLoader registered for column %s." % column | ||
| ) | ||
| else: | ||
| env = TradingEnvironment(environ=environ) | ||
| choose_loader = None | ||
|
|
@@ -285,7 +289,8 @@ def run_algorithm(start, | |
| default_extension=True, | ||
| extensions=(), | ||
| strict_extensions=True, | ||
| environ=os.environ): | ||
| environ=os.environ, | ||
| loaders=None): | ||
| """Run a trading algorithm. | ||
|
|
||
| Parameters | ||
|
|
@@ -344,6 +349,9 @@ def run_algorithm(start, | |
| environ : mapping[str -> str], optional | ||
| The os environment to use. Many extensions use this to get parameters. | ||
| This defaults to ``os.environ``. | ||
| loaders : iterable{PipelineLoader}, optional | ||
|
Contributor
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. the docstring and parameter name don't match here. |
||
| A dictionary containing custom loaders to include data from external sources | ||
| in a pipeline. | ||
|
|
||
| Returns | ||
| ------- | ||
|
|
@@ -396,4 +404,5 @@ def run_algorithm(start, | |
| metrics_set=metrics_set, | ||
| local_namespace=False, | ||
| environ=environ, | ||
| loaders=loaders | ||
| ) | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 think this will crash in the current implementation if the user doesn't supply any custom loaders (because
loaderswill be None, socolumn in loaderswill barf).