A C++ console app that loads historical market data, trains Linear Regression and Decision Tree regressors, compares performance (MSE), and supports interactive predictions.
- C++17 (or newer) compiler (g++, clang++, or MSVC)
- CMake (recommended) if building with CMake
From the project root, compile with:
g++ main.cpp LinearRegression.cpp DecisionTree.cpp -o mainRun the program:
- macOS/Linux:
./main
- Windows (MinGW):
.\main.exe
When you start the executable, you’ll see prompts:
- Pick dataset type:
Would you like to load an ETF(1), or Stock(2): - Enter the file name (just the file name, not the path), for example:
Which specific entry would you like to load (which .txt file): aaap.us.txt
If the file exists under /ETFs or /Stocks (root-level), the app will load data, split 80% train / 20% test, and scale features. Then you’ll get a menu:
===============================
Stock Price Prediction System
===============================
1. Train Linear Regression
2. Train Decision Tree
3. Compare Performance
4. Predict using Linear Regression
5. Predict using Decision Tree
6. Exit
If you want to run the Python Data Visualization File run:
py DataVisualization.py
(Or something else depening on the OS and Version)
The app expects, at minimum, the following fields per row (your loader must parse them accordingly):
-
Features (in order):
- Bias term
1.0(added in code where applicable) open(double)high(double)low(double)volume(int)openInt(int)
- Bias term
-
Target:
close(double)
The loader:
- Reads a
.txtfile intostd::vector<stockDataPoint> - Splits data into 80% train / 20% test
- Scales train/test consistently
- Extracts feature matrix and target vector as needed
Output: When you choose Compare Performance, the app writes a CSV:
mse_results.csv
Model,MSE
LinearRegression,<value>
DecisionTree,<value>
Below are the primary, user-facing functions exposed in each .cpp file used by the program.
int main()- Handles user prompts (ETF vs Stock, file name)
- Loads, splits (80/20), and scales data
- Menu loop to:
- Train Linear Regression
- Train Decision Tree
- Compare model performance (MSE) on the test set and export to
mse_results.csv - Predict using either model by entering feature values
void trainLinearRegression(const std::vector<stockDataPoint>& trainingData, double learningRate, int maxIterations);- Trains a linear regression model via gradient descent (configurable
learningRateandmaxIterations).
- Trains a linear regression model via gradient descent (configurable
double predict(const std::vector<double>& features) const;- Predicts the close price for a single feature vector.
double MSE(const std::vector<double>& predictions, const std::vector<double>& actual) const;- Computes Mean Squared Error.
void train(const std::vector<std::vector<double>>& features, const std::vector<double>& targets);- Trains a regression decision tree.
double predict(const std::vector<double>& features) const;- Predicts the close price for a single feature vector.
std::vector<double> predictBatch(const std::vector<std::vector<double>>& features) const;- Batch predictions, used during evaluation.
- Roshan Patel, Mahtih Allu, Saisathvik Bandarupalli