The issue is that if you use GOOGLEFINANCE
with a date the market was closed the formula returns #N/A
. In your example both 2016/12/31 and 2016/1/1 were dates when the market was closed.
The only way I've been able to solve it so far is by using GOOGLEFINANCE
to return prices in a range around the specified date and then use QUERY
to return the last one prior to the specified date like this:
=QUERY(GOOGLEFINANCE("GOOG","Close",DATE(2016,12,31)-5,6),"select Col2 where Col1 <= date '2015-01-01' order by Col1 desc limit 1",False)
So to get the annual return for GOOG on 2016, enter GOOG on cell G3 and 2016 in cell G2 and use:
=QUERY(GOOGLEFINANCE(G3,"Close",DATE(G2,12,31)-5,6),"select Col2 where Col1 <= date '"&TEXT(DATE(G2,12,31), "YYYY-MM-DD")&"' order by Col1 desc limit 1",False)/QUERY(GOOGLEFINANCE(G3,"Close",DATE(G2,1,1)-5,6),"select Col2 where Col1 < date '"&TEXT(DATE(G2,1,1), "YYYY-MM-DD")&"' order by Col1 desc limit 1",False)-1
See this google sheet for more clarity and also this other question here in Stack Exchange in case someone comes up with a better solution as this is remarkably long for something that should be simpler.