Interpolating the Treasury yield curve

The following code:

• scrapes current U.S. Treasury yield data from the Treasury's website;
• plots the available data points (from the 1, 2, 3, 5, 7, 10, 20, and 30 year instruments); and
• interpolates & plots a full yield curve from those data points.

The code additionally shows what WolframAlpha outputs for comparison.

years = {1, 2, 3, 5, 7, 10, 20, 30};

StringSplit[
Import[
"https://www.treasury.gov/resource-center/data-chart-center/\
interest-rates/pages/XmlView.aspx?data=yield"
]][[-17 ;;]][[{1, 3, 5, 7, 9, 11, 13, 15}]];
StringDelete[#,
>"] & /@ %;
StringSplit[%, "</d:BC_"];
ToExpression[%[[All, 1]]]*0.01;

yields = Transpose[{years, %}];
curve = ListInterpolation[yields[[All, 2]], years];

Show[{
Plot[curve[x], {x, 1, 30}, PlotRange -> Full,
AxesOrigin -> {1, 0.01}, ImageSize -> 250] ,
ListPlot[yields, PlotStyle -> Red]}]

WolframAlpha["Treasury yields", {{"TreasuryYieldCurve:EconomicData",
1}, "Content"}] Note: WolframAlpha does not appear to have access to the most current available daily data presented on the Treasury site. As of this posting on 8 Feb 2018, it only returns data from 1 Feb 2018.

I doubt that WolframAlpha has applied ListInterpolation. It looks like just connects the data points.

But, the WolframAlpha plot does look more realistic, which got me to wondering.

The Treasury doesn't publish data for every year's yield so one could use them in an interpolation.

I need to make reasonable estimates of yield values at any point along the x axis.

In the plot of the interpolation, neither the peak of the curve between points 5 and 6 nor the dip in the curve between points 6 or 7 correspond to the real world yield curve. Yield curves can go very strange under "Black Swan" market events, but normally (and I use normally guardedly), longer maturity yields will have higher values than shorter maturity yields.

Under that assumption/observation, the WolframAlpha plot looks closer to the real world yield curve but its hardly a curve. Additionally, as I stated above, it doesn't use the most currently available data.

Can I configure the interpolation to more realistically model the yield curve? If not, I'd appreciate other suggestions to do so.

• What about InterpolationOrder -> 1? – C. E. Feb 8 '18 at 18:28
• @C.E. -- I should have but didn't know about that. Write it up and you get the prize. It would probably prove more useful to the larger community it you explained how Ama implements InterpolationOrder. Many thanks. – Jagra Feb 8 '18 at 22:32

Wolfram Alpha uses InterpolationOrder -> 1. There is no special significance behind the curve that you are seeing with the default interpolation order, it is just how it happens to look. Compare with the following:

data = Table[x^3, {x, -1, 1, 0.6}];
interp1 = ListInterpolation[data, {-1, 1}, InterpolationOrder -> 1];
interp2 = ListInterpolation[data, {-1, 1}, InterpolationOrder -> 2];
interp3 = ListInterpolation[data, {-1, 1}, InterpolationOrder -> 3];

GraphicsGrid[{
{Plot[x^3, {x, -1, 1}], Plot[interp1[x], {x, -1, 1}]},
{Plot[interp2[x], {x, -1, 1}], Plot[interp3[x], {x, -1, 1}]}
}] When we use an interpolation order that doesn't match the polynomial order of the underlying curve we get an interpolation that doesn't faithfully recreate it.

With a financial time series such as yours, it is probably best to set the interpolation order to one because it may be the least likely to make us read things from the data which isn't there. Still, others would say that when we have discrete data and we don't know which interpolation is right because of some underlying model, then we shouldn't interpolate at all. In those cases, we should instead just plot the points that we have.