How to use a Linear Regression model for backtesting? #274
Unanswered
helloworldnoob
asked this question in
Q&A
Replies: 1 comment
-
You can still use the example in the documentation. Since you have it trained, pass it to the part it uses the results: # Forecast the next movement
X = get_X(self.data.df.iloc[-1:])
forecast = self.clf.predict(X)[0] You can also refractor the example to use linear regression to train a subset of the data to check your understanding. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I just cant seem to figure it out how to code the Strategy Class right now. There is no need for me to train the model inside the function, as seen here: https://kernc.github.io/backtesting.py/doc/examples/Trading%20with%20Machine%20Learning.html
I want to plug in my already trained model, and use the model against the test dataset, and see all those lovely stats that this module provides :)
What is the correct method for coding the Strategy class so that:
Sorry if this question is elsewhere, I couldn't see it.
For reference, I am coming from backtesting my model with borrowed and edited code (without any modules), the way I have been backtesting from start to finish in a flow type of way is as so:
[LOAD data, add data, clean data]
[Select the Features and Target for model]
[Split into train & test]
[Create, fit model]
[Simulate trading positions in the dataframe from the x_test predictions, if prediction >0 ['Position']column =1]
[Function with for loop, if,elif statements, calcuating metrics from trades]
[printout results]
Super confused on how to get up and running correctly with this module, any help is as always appreciated.
Beta Was this translation helpful? Give feedback.
All reactions