Interpolating when some of the input values are errors

Glove_Man

Well-known Member
Joined
Feb 20, 2005
Messages
582
Hello

I need to do a two-dimensional linear interpolation. Nothing too fancy, except that some of the observations are error values (currently NA(), but I could change that).

This is financial concerning interest rates.

I want to do an interpolation that skips over any missing value on that particular day and uses whatever values are present.

A simplified version of the data looks like this.


21-Apr-2721-Apr-2821-Apr-2921-Apr-31
1-Jan-254.094.09#N/A4.04
2-Jan-254.134.01#N/A4.19
3-Jan-254.144.10#N/A4.11
4-Jan-254.064.15#N/A4.06
5-Jan-254.134.02#N/A4.04
6-Jan-254.094.09#N/A4.02
7-Jan-254.174.014.054.02
8-Jan-254.174.204.124.09
9-Jan-254.054.014.034.02
10-Jan-254.104.014.164.14
11-Jan-254.014.034.154.09
12-Jan-254.084.024.084.05
13-Jan-254.144.104.044.08
14-Jan-254.014.134.004.16
15-Jan-254.024.034.054.00
16-Jan-254.024.024.074.05
17-Jan-254.184.204.064.18


From this data I am trying to extract the 5Y interest rate for each day in January. So for the 1 Jan, the interpolation target is 1 Jan 2030 and the value should be interpolated Apr-28 and Apr-31 data points. Same for 2 January, 3 January up until 6 January, with the target day slowly incrementing up.

However, starting 7 January, we have a new data series, the Apr-29. So from 7 January, when our 5Y target is 7 January 2030, we should now use the Apr-29 and Apr-31 data points as the interpolation.

Is here any way to make that happen easily?

I could write code to incrementally look left and then look right to find the data points, but I have several thousand data points so the sheet would be exceptionally slow. I figured between the new excel functions and the Python inclusions it might be possible to do this in a more sophisticated way.

Thanks in advance.
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
How about ....

Book3
ABCDEFGHIJK
1N60months
2
321 Apr 202721 Apr 202821 Apr 202921 Apr 2031Date1Date2Rate1Rate2Interp
41 Jan 20254.094.09#N/A4.0421 Apr 202821 Apr 20314.094.044.06
52 Jan 20254.134.01#N/A4.1921 Apr 202821 Apr 20314.014.194.11
63 Jan 20254.144.10#N/A4.1121 Apr 202821 Apr 20314.104.114.11
74 Jan 20254.064.15#N/A4.0621 Apr 202821 Apr 20314.154.064.10
85 Jan 20254.134.02#N/A4.0421 Apr 202821 Apr 20314.024.044.03
96 Jan 20254.094.09#N/A4.0221 Apr 202821 Apr 20314.094.024.05
107 Jan 20254.174.014.054.0221 Apr 202921 Apr 20314.054.024.04
118 Jan 20254.174.204.124.0921 Apr 202921 Apr 20314.124.094.11
129 Jan 20254.054.014.034.0221 Apr 202921 Apr 20314.034.024.03
1310 Jan 20254.104.014.164.1421 Apr 202921 Apr 20314.164.144.15
1411 Jan 20254.014.034.154.0921 Apr 202921 Apr 20314.154.094.13
1512 Jan 20254.084.024.084.0521 Apr 202921 Apr 20314.084.054.07
1613 Jan 20254.144.104.044.0821 Apr 202921 Apr 20314.044.084.05
1714 Jan 20254.014.134.004.1621 Apr 202921 Apr 20314.004.164.06
1815 Jan 20254.024.034.054.0021 Apr 202921 Apr 20314.054.004.03
1916 Jan 20254.024.024.074.0521 Apr 202921 Apr 20314.074.054.06
2017 Jan 20254.184.204.064.1821 Apr 202921 Apr 20314.064.184.10
21
Sheet1
Cell Formulas
RangeFormula
G4:G20G4=LARGE(IF(($B$3:$E$3<=EDATE(A4,N))*ISNUMBER(B4:E4),$B$3:$E$3),1)
H4:H20H4=SMALL(IF(($B$3:$E$3>=EDATE(A4,N))*ISNUMBER(B4:E4),$B$3:$E$3),1)
I4:J20I4=INDEX($B4:$E4,MATCH(G4,$B$3:$E$3))
K4:K20K4=I4+(J4-I4)*IF(H4-G4=0,1,(EDATE(A4,N)-G4)/(H4-G4))
Named Ranges
NameRefers ToCells
N=Sheet1!$H$1G4:H20, K4:K20

If you have the latest Excel version, you could do this more succinctly with the newer functions available.

If you have have an older version of Excel, I think you'll need to array enter (CTRL-Shift-Enter) the formulae with LARGE and SMALL functions.
 
Upvote 0
Solution
Sorry for the late reply, thank you very much.

I think there's a small error in your named range N definition. Surely it should be H1?

I used a variant of your approach and it's working well. Thanks.
 
Upvote 0
Great, I'm glad it's working for you.

I think there's a small error in your named range N definition. Surely it should be H1?
Like this (from Post #2)?

1737523059847.png
 
Upvote 0

Forum statistics

Threads
1,225,743
Messages
6,186,777
Members
453,370
Latest member
juliewar

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top