How to Calculate Linear Regression Lines and Slopes for Stock Prices

Analysts calculate regression lines as part of their stock price analysis.
i Duncan Smith/Photodisc/Getty Images

Sometimes the best way to predict where a stock price is going is to understand where it's been. The linear regression line is an equation that accounts for past performance to predict future stock values. A stock may be overvalued when it falls above the linear regression line and undervalued when it's under the line. The average investor can calculate a stock regression line with basic stock data and spreadsheet software.

Obtain Information

Obtain historical stock price data for the period you want to measure. You can find historical stock data on financial websites, and many companies offer historical stock prices on their investor relations web page. The two key pieces of information you need are the close date and the corresponding adjusted closing stock price. You can obtain closing stock prices on a daily, weekly or monthly basis, depending on how much data you want to work with.

Set up Dates and Prices

Create one column in a spreadsheet for the dates and a second column for stock prices directly to the right. The dates will constitute the X values of your stock graph, and the stock prices will be the Y values. Enter the date and the respective stock price for the time period in descending order. For example, list February 2008 information underneath January 2008 information.

Find Regression Line Slope With Slope Function

The regression line for the stock prices is the line that best approximates the relationship between time and stock price. Most spreadsheet programs contain a slope function that will automatically calculate the regression line slope. The slope function considers the standard deviation of the data, or the amount of variation between the values, and the correlation coefficient, which measures the degree to which the two types of data are related. Highlight all your data, find the "Slope" function in your spreadsheet function library and hit "Enter." The resulting number is the regression line slope.

Find the Y-Intercept and Final Formula

The second part of the regression line formula is the y-intercept. To calculate the y-intercept, use the formula y=mx+b. In this equation, "y" is the mean of the y values, "m" is the slope, "x" is the mean of the x values and "b" is the y-intercept. To calculate the y-intercept, subtract the mean of all the stock prices from the mean of all the dates. Finally, plug the values back into the formula. For example, if you calculated a slope of 1.5 and a y-intercept of 20, the final linear regression formula for the stock is y=1.5x+20.

the nest

×