Google-sheets – Calculating annual return of stocks with Google finance data

google sheets

Below formula returns Annual Return for the year 2016

=INDEX(GOOGLEFINANCE("GOOG","price",date(2016,12,31)),2,2)/INDEX(GOOGLEFINANCE("GOOG","price",date(2016,1,1)),2,2)-1

This works fine for most stocks including GOOG, however it returns the below error for some stocks –

Error
Function INDEX parameter 2 value is 2. Valid values are between 0 and 1 inclusive.

Any guidance will be helpful and much appreciated.

Best Answer

The problem is with the date. 1/1 is New Year's Day, and the markets are closed, therefore the stock price on that day is returning #N/A, which doesn't have an index 2,2.