Reputation: 29064
I need to solve this equation to find the value of Y, given that I have all other parameters.
The function is:
I have implemented the function this way.
f = @(x)-bond_price - accruedinterest + (principal/(1+x/200)^(N-1+(differenceindays/E)) + symsum((couponrate/2)/(1+x/200)^(k-1+(differenceindays/E)),k,2,N) + (couponrate/2)/((1+x/200)^(differenceindays/E)));
yield = fzero(f,0);
Error that I get is: Undefined function or variable 'k'.
btw how to find the solution such it is equal to zero?
Not sure whether I am implementing it right. Need some guidance.
Upvotes: 0
Views: 902
Reputation: 18484
You can probably replace symsum
with sum
and do something like this:
differenceindays = ...
E = ...
bond_price = ...
accruedinterest = ...
principal = ...
couponrate = ...
N = 100;
k = 2:N;
DSC_E = differenceindays/E;
f = @(x)-bond_price-accruedinterest+principal./(1+x/200).^(N-1+DSC_E) ...
+sum(0.5*couponrate./(1+x/200).^(k-1+DSC_E)) ...
+0.5*couponrate./(1+x/200).^DSC_E;
I also removed a bunch of superfluous parentheses to improve readability. This should work with fzero
(assuming that the equation has one or more roots as written). But of course we can't test it because it's all unknown variables.
Upvotes: 1