Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
using data.history for momentum algo - error when determining price change for n days

Hello,

i am trying to get 42 days price change for two assets using date.history - VTV and TIP

but prices at the close of the day are incorrect

the price of VTV for "2020-08-25 00:00:00 0000" is 106.392, and should be 107 (from Yahoo Finance)

2020-10-22 17:30 PRINT ('--rebalance date--: ', Timestamp('2020-10-22 10:30:00-0400', tz='US/Eastern'))
2020-10-22 17:30 PRINT ----
2020-10-22 17:30 PRINT ('calculate perfomance for ticker: ', Equity(25909 [VTV]), ' and period', 42)
2020-10-22 17:30 PRINT ('earliest price: ', 106.392, Timestamp('2020-08-25 00:00:00+0000', tz='UTC', offset='C'))
2020-10-22 17:30 PRINT ('curPrice: ', 107.0, Timestamp('2020-10-22 00:00:00+0000', tz='UTC', offset='C'))
2020-10-22 17:30 PRINT ('calculate perfomance for ticker: ', Equity(25801 [TIP]), ' and period', 42)
2020-10-22 17:30 PRINT ('earliest price: ', 125.839, Timestamp('2020-08-25 00:00:00+0000', tz='UTC', offset='C'))
2020-10-22 17:30 PRINT ('curPrice: ', 125.81, Timestamp('2020-10-22 00:00:00+0000', tz='UTC', offset='C'))
2020-10-22 17:30 PRINT ('absmomPerc :', 0.56822429906542438)
2020-10-22 17:30 PRINT ('cashPerc :', -0.023050631905251064)

I ask you to help with the algo, thanks

4 responses

There will often be a discrepancy between Quantopian close prices and other sources. Quantopian uses the last traded price as the close price for a security. This is the last price at which a 'typical' order filled. It does not include final auction orders. Yahoo, and other sources, use end-of-day (EOD) prices which do include these final auction orders.

There is a little more detail in this post.

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.

Dan, thank you! Code is correct?

The code looks good. What's being calculated is the percent change from the close 42 trading days ago to the close of the current bar (ie the minute bar at market open+1 hour). To get the change to yesterday's close, using the data.history method, then select the 2nd from the last (not the last) value . Like this

# To get yesterdays close either of these will work  
absmom1[momPeriod-2]  
absmom1[-2]

I made some changes to the printing but basically the same as the original algo.

Thanks, Dan