A C++ command-line tool for performing linear regression analysis on stock time series data to calculate beta coefficients between a target ticker and an index ticker.
This project analyzes the relationship between two securities by computing a linear regression on their daily percentage changes. It reads historical bar data from Sierra Chart data files and calculates the slope (beta) and intercept of the regression line, which can be used to understand how a target security moves relative to an index.
- Time Series Data Loading: Parses Sierra Chart
.dly_BarData.txtCSV files containing OHLC (Open, High, Low, Close) data - Percent Change Calculation: Computes daily percentage changes for each security
- Linear Regression: Performs least-squares linear regression using modern C++23 ranges
- Beta Coefficient: Calculates the beta (slope) showing the target's sensitivity to index movements
- Configurable Analysis Period: Analyze any number of recent bars
- C++23 compatible compiler (Visual Studio 2022 or later)
- Sierra Chart data files in the format:
{TICKER}-NQTV.dly_BarData.txt - Data files must be located in:
C:\SierraChart\Data\
- Open
SimpleStockRegression.slnin Visual Studio - Build the solution (Ctrl+Shift+B)
- The executable will be generated in the output directory
reg.exe <TargetTicker> <IndexTicker> <NumBars>
- TargetTicker: The ticker symbol of the security to analyze (e.g.,
AAPL,MSFT) - IndexTicker: The ticker symbol of the index or benchmark (e.g.,
SPX,NDX) - NumBars: Number of most recent daily bars to include in the regression analysis
reg.exe META SPY 252
[META-SPY] y=1.64x+0.006
reg.exe QQQ SPY 31
[QQQ-SPY] y=1.33x+0.002