Last active
November 28, 2016 03:30
-
-
Save dat-boris/e15690966e71aaff95f05f9c59934a6f to your computer and use it in GitHub Desktop.
Simple quantopian polyfill to allow recording metrics into dataframe
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
from zipline.api import ( | |
schedule_function, date_rules, time_rules, sid, symbol, | |
set_slippage, slippage, set_commission, commission, | |
get_datetime, order_target_percent, | |
# record, # Replaced below | |
attach_pipeline, | |
order_target, get_open_orders, history | |
) | |
RECORD_DF = pd.DataFrame([]) | |
def record(simulate_datetime=None, **kwargs): | |
""" | |
Use this as a replacement of the record zipline.api | |
:param simulated_datetime: Use set datetime instead of the algorithm datetime | |
""" | |
global RECORD_DF | |
current_date = simulate_datetime or get_datetime() | |
for k,v in kwargs.items(): | |
RECORD_DF.set_value(current_date, k, v) | |
return RECORD_DF |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment