I have two time-series, A and B. The time series have different lengths and different dates and different frequencies.
The core issue is that I want to find the dates between the two time series that overlap.
This is easy enough to do, but there's a twist.
Imagine time series A has a value on 01/01/2020 and series B has a value on 02/01/2020. These are only one day apart, and UNLESS there's a better candidate (e.g. if B ALSO has a value on 01/01/02020), I want to just include this one.
So, really the twist consists of a "lag" of, say, 5 days. Then what I want to do is the following:
- Consider all date in time series A.
- For each such date, find the corresponding date in time series B.
- For each date for which a match in B was NOT found, set a lag = 1 day, and search in B again.
- Repeat step 3 with lag = 2, 3, ..., 5 days.
- Return a new times series C, which consists of the dates of A and the values of B, found by matching using the above procedure.