Reputation: 29064
Nelson-Siegel is a method used to model interest rates. More info on Nelson-Siegel:http://en.wikipedia.org/wiki/Fixed-income_attribution.
I have written a code like this:
function [ interest ] = Nelson_Siegel(s)
beta0 = 0.0408; beta1 = -0.0396; beta2 = -0.0511; tau= 1.614;
interest = beta0 + beta1*(tau/s)*(1-exp(-s/tau))+beta2*((tau/s)*(1-exp(-s/tau))-exp(-s/tau));
end
The problem is when I input a value of 0, it gives me a value of NaN. It should be equal to 0 instead. Not sure where it is going wrong.
Upvotes: 0
Views: 128
Reputation: 13758
It's because of this term:
T = beta1*(tau/s)*(1-exp(-s/tau))
As s ⇒ 0
, τ/s ⇒ ∞
, and
1-exp(-s/τ) ⇒ 1-e⁰ = 1-1 = 0
Thus:
s ⇒ 0 ∴ T ⇒ β₁·∞·0 ⇒ NaN
since ∞·0
isn't a proper number.
Upvotes: 3