google-sheetsgoogle-sheets-formulastockgoogle-finance

GoogleFinance formula to find previous historical trading day of a stock


I have been searching for a solid formula to find stock prices of "previous trading days" of a large batch of historical dates.

The formula I started with:

=googlefinance(A5, "close", B5-1)

where A5 refers to a ticker, and B5 refers to a date in the past.

I get #NA results for previous days that fall on weekends or holidays.

I need a formula that will work reliably for 365 days per year, no matter the day of the week or number of non-trading days prior. I have tried something like this:

=index(googlefinance(A5, "close", (B5-1)-2,2),2,2)

That formula works if the B5 date is the first trading day of the week, but not if it falls anywhere midweek.

I tried using WORKDAY(B5,-1) in a few ways but I realize that function can only calculate a number of workdays, not produce a date.

I need a formula that I do not have to edit and adjust cell by cell.


Solution

  • Here is one way that gives

    Here is how it works:

    screenshot