Hi There. Any idea how in Python can I get least squares linear regression?
For EMA there is self.EMA but how can I import/get LSLR ?
QUANTCONNECT COMMUNITY
Hi There. Any idea how in Python can I get least squares linear regression?
For EMA there is self.EMA but how can I import/get LSLR ?
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.
Vladimir
from scipy import stats
slope, corr = stats.linregress(x, y)[0], stats.linregress(x, y)[2]
Crypto Hai
Vladimir But how to use it in onData function? How to feed it also data?
Crypto Hai
Ok I found this https://www.quantconnect.com/lean/documentation/topic28935.html
(LeastSquaresMovingAverage Class). Any help if that could be loaded into python's OnData and use ?
Vladimir
I used it for Andreas Clenow Momentum here
The link you send me is C# version.
Crypto Hai
Thank you for your answers Vladimir . I have found suddenly this
self.LSMA("SPY", 9, Resolution.Hour) and itworked. But I am unsure it delivers the same values like linereg function in tradingview ..
Vladimir
Crypto Hai,
There are 5 outputs in stats.linregress
Slope
Intercept
Correlation coefficient
Two-sided p-value
Standard error
Can you discribe how you are going to use "Least squares linear regression"?
Crypto Hai
In tradingview there is a function linereg
linreg = intercept + slope * (length - 1 - offset), where length is the y argument, offset is the z argument, intercept and slope are the values calculated with the least squares method on source series (x argument).
linreg(source, length, offset) → series[float]
I need exactly the same values for each tick. Do you think it's achievable?
Vladimir
slope, intercept = stats.linregress(x, y)[0], stats.linregress(x, y)[1]
Vladimir
Crypto Hai,
If you're still struggling with linreg, here's the ScipyStatsLinearRegression.
Crypto Hai
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.
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!