I need to compute annual mean interest rates from public data. FRED mortgage rate data (available here: https://fred.stlouisfed.org/series/MORTGAGE30US) when downloaded as an Excel file, Imports as pairs {date,rate} thus
The data available from Fred is 1971 to the present; I am only interested in 1990-2021, inclusive. This code works fine to create a 1670 obs dataset for the 32 year period of interest
intDates = Select[intRates[[All, 1]],DateObject[{1989, 12, 31, 0, 0, 0}] < # < DateObject[{2022, 1, 1, 0, 0, 0}] &];
intVals = intRates[[980 ;; 2649]][[All, 2]];
intData = Transpose[{intDates, intVals}];
intData // Length
Problemo: 1670/52 is not an integer. BECAUSE, the Fed produces a value weekly on the same day and some years have 52 readings and some have 53. I would rather not arbitrarily drop data. In my segment of time there are 6 years with 53 readings. One would think, since the code above works fine, this code...
tbl = Transpose[Table[{i, i + 2}, {i, 1989, 2020}]];
reads = MapThread[
Select[intRates[[All, 1]],
DateObject[{#1, 12, 31, 0, 0, 0}] < # <
DateObject[{#2, 1, 1, 0, 0, 0}]] &, tbl];
Length[#]&/@reads
...would also, where the strategy is to measure the read count for each year with a year being defined as a period greater than New Year's Eve from the prior year and less than New Year's Day of the following year. But something about DateObject does not cooperate.
I am more than happy to upload my Excel file but have been unable to locate the mechanism for doing so. Once I get past the DateObject problem in MapThread[Select...] I may be over the hump.