Created
November 20, 2016 03:36
-
-
Save dat-boris/e63f403e48d7898f84817271a1eb6fba to your computer and use it in GitHub Desktop.
`pipeline_line` output replacement
This file contains 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
# see | |
# * https://www.quantopian.com/research/notebooks/201610-Female-CEO/1106-Alpha-confirmation.ipynb | |
# * https://www.quantopian.com/posts/running-pipeline-backtest-in-reserach | |
last_pipeline_index = None | |
pipeline_data = None | |
def get_new_data(t, pipeline_name): | |
start_date = t | |
end_date = t+INCREASE_DELTA | |
print "WARNING: Getting next date: {} - {}".format(start_date, end_date) | |
return run_pipeline( | |
pipe, | |
start_date=start_date, | |
end_date=end_date | |
) | |
def pipeline_output(pipeline_name): | |
global pipeline_data, last_pipeline_index | |
t = get_datetime().date() | |
# initialization with the pipeline_data | |
if pipeline_data is None: | |
pipeline_data = get_new_data(t, pipeline_name) | |
return pipeline_output(pipeline_name) | |
# now check the pipeline_flow | |
try: | |
output = pipeline_data.loc[t] | |
last_pipeline_index = pipeline_data.index.get_loc(t) | |
except KeyError as e: | |
# if date is outside pipeline_data | |
last_date_of_df = max(pipeline_data.index.get_level_values(0)) | |
if t > last_date_of_df.date(): | |
pipeline_data = get_new_data(t, pipeline_name) | |
return pipeline_output(pipeline_name) | |
else: | |
print "WARNING: Cannot find pipeline data on date: {}, last date: {}".format(t, last_pipeline_index) | |
# if we cannot find the specific date in pipeline, use last date | |
output = pipeline_data.irow(last_pipeline_index).reset_index(level=0, drop=True) | |
return output |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment