How to Calculate Linear Regression Lines and Slopes for Stock Prices

by Stephanie Ellen ; Updated April 19, 2017
Linear regression can help you see trends in stock market prices.

Linear regression is a statistical method for finding the best-fit line of a data series. In stock trading, linear regression is sometimes called the time series forecast indicator. If you want to find the best-fit line for a series of stock data, you can use linear regression to do so. Performing linear regression is very challenging by hand, but you can use Microsoft Excel to perform the analysis in seconds.

Step 1

Launch Microsoft Excel. A new worksheet opens.

Step 2

Type your data into the worksheet in two columns. Place one set of data –for example, stock prices – into column A, starting in cell A1 and working down the column. Place the other set of data – for example, days that the stocks achieved the prices in column A – into column B, starting in cell B1 and then working down the column.

Step 3

Click the "Data" tab on the ribbon and then click "Data Analysis."

Step 4

Click "Regression."

Step 5

Type the location for the data in column B into the "Input Y range" box. For example, if your data is in cells A1 through A20, type "A1:A20" (without the quotation marks) into the box.

Step 6

Type the location for the data in column A into the "Input X range" box. For example, if your data is in cells B1 through B20, type "B1:B20" into the box.

Step 7

Type a confidence level into the "Confidence Level" box. For example, if you want the confidence level of your results to be 90 percent, type ".90" into the box.

Step 8

Click the "New Worksheet" button to make your results appear on a new worksheet or type a range of cells into the "Output Range" text box to have the results output on the same worksheet.

Step 9

Click "OK" to have Excel perform the regression analysis.


  • The more data you type into the worksheet, the more accurate your results will be. For example, three days of stock market data won't give you an accurate picture of trends, but several years of data will.

Items you will need

  • Microsoft Excel (Excel Starter is free with Windows)
  • Stock market historical data

About the Author

Stephanie Ellen teaches mathematics and statistics at the university and college level. She coauthored a statistics textbook published by Houghton-Mifflin. She has been writing professionally since 2008. Ellen holds a Bachelor of Science in health science from State University New York, a master's degree in math education from Jacksonville University and a Master of Arts in creative writing from National University.

Photo Credits

  • Thinkstock/Comstock/Getty Images