STOCKHISTORY() function is not returning a consistent number of rows for all stocks.

Mr. Snrub

Board Regular
Joined
May 22, 2005
Messages
143
Office Version
  1. 365
Platform
  1. Windows
I have a spreadsheet with the first column as a Date field and the rest of the columns are ticker symbols for different stocks, like so:

Date:
Code:
=INDEX(STOCKHISTORY("AAPL", "12/31/2015", "09/06/2021",0,0),,1)

AAPL:
Code:
=STOCKHISTORY("AAPL", "12/31/2015", "09/06/2021",0,0,1)

PINS:
Code:
=STOCKHISTORY("PINS", "12/31/2015", "09/06/2021",0,0,1)

ROKU:
Code:
=STOCKHISTORY("ROKU", "12/31/2015", "09/06/2021",0,0,1)

The problem is that the STOCKHISTORY() function is not returning a consistent number of rows for each stock. AAPL returns all expected rows, but ROKU only returns 991 rows (it IPO'ed in 9/28/2017). The PINS formula only returns 601 rows, since it IPO'ed in 4/18/2019. So for example the very first row that I'm seeing looks like this:

DateAAPLPINSROKU
12/31/201526.3224.4023.50

The PINS and ROKU values are completely incorrect, since they reflect the stock price on their IPO dates instead of 12/31/2015. Is there any way to ensure that all formulas will return the same number of rows so I don't have to also return the DATE field for every single stock? For all dates that don't have data, I'd be fine with just an NA() error for all dates before the IPO date.
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.

Oaktree

MrExcel MVP
Joined
Jun 20, 2002
Messages
8,027
Office Version
  1. 365
I think you've sort of answered your own question as to why it's dangerous to pull values without their corresponding dates. It's much safer to pull the date/value pairs for each ticker, then use a flurry of VLOOKUPs (or similar) to create your consolidated table with all tickers' values.
 
Learn Excel from Bill Jelen

Understanding data is crucial, and the easiest place to start is with Microsoft Excel.

Forum statistics

Threads
1,151,492
Messages
5,764,686
Members
425,230
Latest member
DzOus

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top