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

Mr. Snrub

Board Regular
Joined
May 22, 2005
Messages
147
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

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
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.
 
Upvote 0

Forum statistics

Threads
1,214,920
Messages
6,122,279
Members
449,075
Latest member
staticfluids

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
Back
Top