Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Same Day Pricing Data Availability for Algorithms

Hi Everyone,

I'm relatively new to Quantopian and have spent the last month performing research creating an algorithm that implements close-to-close strategy. My algorithm re-balances 20 minutes before close.

I've got it working pretty well but I'm missing the last important part... I need to get the most recent pricing available for "today" (the day that the my algorithm is being run) for my pipeline. I need this in order to get the best estimate of the close-close return for that day since I won't be able to get the actual close-close return since it'll re-balance before close.

For example: Running my pipeline in the notebook research environment on at 3:40pm on 5/11/2020, is there a way for me to retrieve pricing that same day closest to 3:40pm (whether it's at 12,1,2,3pm).

And if i'm running my algorithm in the backtest environment - collect the pricing at a specific time on the current day the back test is simulating.

Summary of my question: How often is pricing data available from the current date/time? and how to retrieve that data for that specific time closest to 3:40pm?

Can anyone provide suggestions or point me in the right direction?
I apologize if this question is unclear.
Thank you,

2 responses

I actually believe the code below may help solve my issue. Would this work the way I described previously? If yes, in the case of backtesting, would I have to call this function using a separate schedule function or call this function in my rebalance function that is already being called at 3:40pm?

def before_trading_start(context, data):  
    # Get a dataframe of our pipe data.  
    context.output = pipeline_output('my_pipe')  


def enter_buy_sell_orders(context, data):  
    # Get the current prices for all stocks returned by our pipe (ie context.output.index)  
    # Add those prices as a new column named 'current_price' in 'context.data'  
    context.output['current_price'] = data.current(context.output.index, 'price')

    # Do any logic you wish on any of the columns in the pipe dataframe output  
     stocks_to_buy = context.output.query('current_price < yesterday_close').head(TARGET_STOCKS).index  

Would appreciate any feedback.