Hi, I was wondering if you could help me with the regression algorithm.
What is the trade logic out of the below algorithm.
How are you using the intercept.
Is trade logic based on a prediction?
QUANTCONNECT COMMUNITY
Hi, I was wondering if you could help me with the regression algorithm.
What is the trade logic out of the below algorithm.
How are you using the intercept.
Is trade logic based on a prediction?
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.
Daniel Chen
Hi Andrew,
Thank you for your interest in this algorithm. We only use the slope, not the intercept term, for creating trading signals. Generally speaking, we use the slope to model the price trend of this equity. The detailed trading logic is as follows: (1) Get the slope of the linear model on the historical open prices for each symbol, (2) If the slope is over the buy threshold, then we enter the long position for this stock; if the slope is smaller than the liquidate threshold, then we just liquidate this stock. Besides, the weights for the stocks in the portfolio are equal. Hope it helps!
Andrew Czeizler
Hi Daniel!
Sincere thanks for the reply. Appreciate the support.
I have a couple of question regarding the structure of the algorithm.
- As it is a regression what values are you regressing againest.
- How is the data broken up. Do you regress(train) againest previous data and then predict into the future.
- Is the lookup back period the training period?
- Do you invest 100% per trade.
- There is minute and daily resolution in the algorithm. what is the purpose of the two different time scales.
Thankyou,Best,AndrewDouglas Stridsberg
Hi Andrew,
All of the answers to your questions can be found by actually reading the code:
Each symbol is given a weight of 1 / len(self.symbols) [line #101], meaning that in this case, yes, 100% is allocated to SPY, but if you were to extend the algorithm to more symbols, they would all be equal weighted.
Y are historical daily prices [line #63] and X is a matrix of 1s [line #65], meaning all prices are equally weighted.
All historical prices from self.lookback ago up to today are used to train the model up to today [line #45]. The model is retrained every day, 28 minutes after the market opens [line #39].
Yes. You can see self.lookback is used as the lookback parameter in the self.History call [line #45].
This one admittedly cannot be found directly by reading the code - my guess is that the minute subscription is used so that training and trading can happen at 28 and 30 minutes after market open respectively. With only daily resolution, the algorithm would only be run once a day and this kind of retraining would not be possible.
Andrew Czeizler
Hi Douglas!
Thank you :)!
was very clear.
I am not sure about the detail of the regression. So are we regressing againest previous price data, with the model? The way I read your answer is that we are regressing a column of price data to a column of one's which does not make much sense?
Many thanks
Kind regards,
Andrew
Douglas Stridsberg
Hi Andrew - from what I can tell, what's being done is a simple least-squares regression of price versus time (essentially like plotting the timeseries in Excel and doing "Add Trendline"). Then, the slope is being divided by the intercept and the resulting variable is called "slope" (not something I would personally agree with, but I didn't write the algo).
Daniel can fill in if this is not what's being done.
The column of ones indicates the weights that each price receives. If they're all 1s, all prices receive the same weight.
A few google searches for "sklearn linear regression examples" can point you to other examples of this regression, which might be helpful to see.
Andrew Czeizler
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!