views:

478

answers:

4

Excel's add-in named "Analysis ToolPak" provides "Yield" function for calculation of yield on security that pays periodic interest.

Function works well and returns proper data.

My understanding is function base on kind of iteration it is not so easy implement it in my code.

My question is anybody know/seen implementation in C# (eventually other languages) and can share? Or (maybe) some tips how to implement it? Than I can share :)

EDIT:

Thanks all posting me "formula" but this is not fully useful to me.
Please note that MS' formula finds application in 1 case only:
"when there is one coupon period or less until redemption",

otherwise:

"(...) Yield is calculated through a hundred iterations."
and there is no exact formula for that case

I can read equations and implement them (hopefully), but my question was if somebody has or saw already implemented function in programming language.

I'm not lazy but I dont like break down open doors...

A: 

First learn the mathematical formulas needed for your expression. Then if it's needed to be implemented in a enumerable fashion, check out "yield return" and iterators in c#

AZ
You could at least provide a link to a web page that gives the formula, this isn't a helpful answer.
Lazarus
.Net's"yield return" and the financial yeild are completely different. And what Maciej is after is the actual 'mathematical formulas'
MrTelly
i don't know the formula. but as another reply stated it is in the first result on google for "excel yield". I just extrapolated from the OP "base on kind of iteration" hint that the implementation might need iterator functionality. So i provided a direction for that.
AZ
I'm familiar with math equations. If you look at "formula" you will not see iteration in it. Isn't it?
Maciej
+1  A: 

The whole formula is here:

http://office.microsoft.com/en-us/excel/HP052093451033.aspx

First match on Google for 'excel yield'.

leppie
A: 

Here is the formula if you don't want to browse through web pages.

I tried to post the image but I am a new user and it didn't allow me.

Graphic showing formula.

Ian Roke
That's the same image in the page I linked to previously.
leppie
I know I just wanted to show the link in this post but wasn't able to. Users can view the graphic on its own or the full page if they need to understand the reasoning behind it.
Ian Roke
When I say link I mean graphic.
Ian Roke
+1  A: 

Assuming a function which is passed all the variables required for the formula as explained on

http://office.microsoft.com/en-us/excel/HP052093451033.aspx

then

return (((redemption/100 + rate/frequency) - ( par/100 + ( A/E * rate/frequency ))) / (par/100+( A/E * rate/frequency ))) * ((frequency*E)/DSR);
Winston Smith
And if you read it, you would have seen it only works for a subset of inputs, try again!
leppie
How do we calculate those A, E and DSR variables?
Burhan