Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
How do I get the properties of an event at a given time?

I was wondering how can I get he properties of a certain event on a certain day/time (or as close to it as possible). Something like the following but I want to be able to specify date/time.

https://www.quantopian.com/help#api-event-properties

4 responses

One thing you can do is just have a variable that gets set at a certain time. Or, for a more general implementation, you can create a dictionary of times and values. Something like this:

import pandas as pd  
from datetime import date, timedelta

def initialize(context):  
    context.lows = {}

def handle_data(context, data):  
    exchange_time = pd.Timestamp(get_datetime()).tz_convert('US/Eastern')  
    context.lows[exchange_time] = data[sid(24)].low  
    try:  
        log.info(context.lows[exchange_time-timedelta(hours=1)])  
    except:  
        log.info('Algorithm has been running for less than an hour.')  

Does that help?

Disclaimer

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by Quantopian. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. No information contained herein should be regarded as a suggestion to engage in or refrain from any investment-related course of action as none of Quantopian nor any of its affiliates is undertaking to provide investment advice, act as an adviser to any plan or entity subject to the Employee Retirement Income Security Act of 1974, as amended, individual retirement account or individual retirement annuity, or give advice in a fiduciary capacity with respect to the materials presented herein. If you are an individual retirement or other investor, contact your financial advisor or other fiduciary unrelated to Quantopian about whether any given investment idea, strategy, product or service described herein may be appropriate for your circumstances. All investments involve risk, including loss of principal. Quantopian makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances.

Hi Gus, Thanks.
This is very similar to how I ended up working around the problem for now. But I was just curious if there was a direct way to reference the price (and other details) of a security close to a certain time point in the past.

Hello Ro P,

Are you familiar with 'history' (described on the help page)? It provides a trailing window of data for all of the securities in you algo, in a pandas dataframe with datetime stamps. It only runs on minute bars and has a few quirks as implemented presently (be sure to read the help page description carefully). But it works well.

Grant

Thanks Grant. I will familiarize myself with this. I am new and I am in the process of learning. Feedback much appreciated.