Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
How to get TimeStamps for history in CustomFactor

The historical data inputs in a CustomFactor are of type np.ndarray, this makes it difficult to combine them with other timeseries data that was calculated outside the pipeline (essentially because of alignment).

Is there any way I can get timestamps for the historical data in the pipeline, e.g. via some clever calendar calculations using the today input as a starting point? I'd like to create a pd.Series or a pd.DataFrame indexed by the timestamp.

An example use case is e.g. to combine futures data with equity data.

3 responses

Hi Ivory Ant, have you got the problem solved? I have just started using the Quantopian :)

Thanks~~

No sorry, if I remember correctly I abandoned the whole thing because of other problems with mixing futures and stocks. Maybe something with the pipeline, can't really remember.

Thanks Ivory, i am using the following approach:

from zipline.utils.calendars import get_calendar

def get_trading_index(today, num_days):  
    up2today = get_calendar('NYSE').schedule[:today]  
    return up2today.iloc[len(up2today)-num_days:len(up2today)].index  

The returned index is well-aligned as checked in the reseach environment :)