LEAN is the open source
algorithmic trading engine powering QuantConnect. Founded in 2013 LEAN has been built by a
global community of 80+ engineers and powers more than a dozen hedge funds today.
Alpha League Competition: $1,000 Weekly Prize Pool
Qualifying Alpha Streams Reentered Weekly Learn
more
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 QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect 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. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
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 QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect 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. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
Alexandre Catarino
,
We can accomplish that in two lines! Use the Identity indicator helper to get the previous day information automatically:
// Define the field:
private Identity _prevClose;
// In Initialize:
_prevClose = Identity("SPY", Resolution.Daily, Field.Close);
0
Jared Broad
,
Just a note; "Identity" provides the current value. Assuming you have lower resolution (say minute) data flowing through the algorithm the code above will work as the daily close is only passed in at the end of the day. If your algorithm has only daily data this won't work as all the daily bars will be synchronized and arrive at midnight.
There currently isn't an explicit "yesterday's close" property but its easy to get by a simple variable. If there's enough demand we can add a helper to achieve this.
0
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 QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect 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. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
Herman Ho
948
,
Cool, so to clarify:
Identity("SPY", Resolution.Daily, Field.Close);
but SPY would be subscribed at the minute resolution, that would indeed return previous close price?
0
Alexandre Catarino
,
Yes. As long as the resolution of the data we subscribed is lower than the Identity indicator resolution, this approach works.
Here is yet another approach:
// Define the field:
private decimal _prevClose;
// Sets up the field when the day ends
public override void OnEndOfDay()
{
_prevClose = Securities["SPY"].Close;
}
0
Herman Ho
948
,
I see, thanks! In live, to get the prev close I assume need to run it with some warm up then?
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 QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect 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. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
Loading...
To unlock posting to the community forums please complete at least 30% of Boot Camp. You can
continue your Boot Camp training progress from the terminal. We
hope to see you in the community soon!