Hi!
I would like to get the current price of a stock s, but when I use
data.current(s, 'price')
it gives me the same value as
data.history(s, 'close', 1, '1d')
== yesterdays close price.
Could someone help me out?
Thanks!
the cat lover
Hi!
I would like to get the current price of a stock s, but when I use
data.current(s, 'price')
it gives me the same value as
data.history(s, 'close', 1, '1d')
== yesterdays close price.
Could someone help me out?
Thanks!
the cat lover
The data.current
method will return the 'current' data. You are using it correctly. It will be the last known minute data which, technically, isn't the current minute data but the data from the previous minute. Logically, it can't be data from the current minute because one would need to look into the future to know what the close price or volume (for example) of the minute would be. Think of it as 'the last known data available to the current minute'.
The issue you bring up is the interpretation of data.history
with a '1d' frequency. The data fetched by this method includes the current days data. The history ends with today. So, the last values (ie indexed at -1) for the open, high, low, close, and volume will be the current days values as of the minute the method was called. So what does this mean?
open: this is the days open price and will be constant throughout the day
high: the days high up through when the method was called
low: the days low up through when the method was called
close: this is the last close of the minute the method was called. This will always equal data.current(s, 'close')
volume: cumulative volume for the day up through when the method was called
To get yesterdays values using data.history
one must use an index of -2. The above values are similar to data.current
but are for the current day and not the current minute. If the data.history
method is called with a '1m' frequency, the latest values (ie indexed at -1) will be identical to those returned by data.current
.
There is another forum post on this which may be helpful (see https://www.quantopian.com/posts/need-some-help-on-custom-filter).
Hope that helps.
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.