Skip to content

mahithallu/Project2DSA

Repository files navigation

Stock Price Predictor

A C++ console app that loads historical market data, trains Linear Regression and Decision Tree regressors, compares performance (MSE), and supports interactive predictions.


Requirements

  • C++17 (or newer) compiler (g++, clang++, or MSVC)
  • CMake (recommended) if building with CMake

Build & Run

From the project root, compile with:

g++ main.cpp LinearRegression.cpp DecisionTree.cpp -o main

Run the program:

  • macOS/Linux:
    ./main
  • Windows (MinGW):
    .\main.exe

Using the Program

When you start the executable, you’ll see prompts:

  1. Pick dataset type:
    Would you like to load an ETF(1), or Stock(2):
    
  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)

🔎 Data & Features

The app expects, at minimum, the following fields per row (your loader must parse them accordingly):

  • Features (in order):

    1. Bias term 1.0 (added in code where applicable)
    2. open (double)
    3. high (double)
    4. low (double)
    5. volume (int)
    6. openInt (int)
  • Target: close (double)

The loader:

  • Reads a .txt file into std::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>

Main Files & Key Functions

Below are the primary, user-facing functions exposed in each .cpp file used by the program.

main.cpp

  • 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

LinearRegression.cpp

  • void trainLinearRegression(const std::vector<stockDataPoint>& trainingData, double learningRate, int maxIterations);
    • Trains a linear regression model via gradient descent (configurable learningRate and maxIterations).
  • 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.

DecisionTree.cpp

  • 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.

Contributors

  • Roshan Patel, Mahtih Allu, Saisathvik Bandarupalli

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •