Buy or Sell? Stock Investment Strategy with Logistic Regression

In Chapter 3 of Data Analytics for Finance Using Python, we move from predicting exact prices to making a much simpler, but arguably more important, decision: Should I buy or sell?

This is where Logistic Regression comes in. Don’t let the name “regression” fool you—this is actually a classification tool. It’s designed to give you a binary answer: 0 or 1, Yes or No, Sell or Buy.

The Logic

The basic rule for the model is simple:

  • If today’s predicted price is higher than yesterday’s, the variable is 1 (Buy).
  • If it’s lower, the variable is 0 (Sell).

The independent variables the authors used were the standard Open, Close, High, and Low prices.

How it Performed

When they ran the numbers on MRF stock, some interesting things popped up:

  • The “High” variable was actually insignificant. With a p-value of 0.418, it didn’t really help the model predict much.
  • The “Low” variable was key. It had a p-value of 0.013, making it a strong predictor for the buy/sell decision.

Measuring Success

You can’t just look at the raw results; you need to see how often the model was actually right. This is done with a Confusion Matrix.

  • Accuracy: 88%
  • Recall: 89% (meaning it’s good at catching the “Buy” signals)
  • Precision: 90% (meaning when it says “Buy,” it’s usually right)

And that’s why it matters. An 88% accuracy rate is pretty impressive for a simple model. It shows that even with “basic” supervised learning, you can build a strategy that’s more reliable than just flipping a coin.

But here’s the thing: market conditions change. A model that works for MRF might not work for a tech startup. You always have to keep testing.

Next: Stock Decisions with Gaussian Naive Bayes | Previous: Predicting Stock Prices with ARIMA

About

About BookGrill.net

BookGrill.net is a technology book review site for developers, engineers, and anyone who builds things with code. We cover books on software engineering, AI and machine learning, cybersecurity, systems design, and the culture of technology.

Know More