问题
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...
回答1:
The whole formula is here:
http://office.microsoft.com/en-us/excel/HP052093451033.aspx
First match on Google for 'excel yield'.
回答2:
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);
回答3:
First you need an implementation of the PRICE function. YIELD then uses a Newton Solver to solve the PRICE function for the correct yield and a given target price. Code for price function and code for the Newton solver can be found in this similar post: java implementation of excel price,yield functions
回答4:
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.
回答5:
using Excel = Microsoft.Office.Interop.Excel;
Excel.Application xl = new Excel.Application();
Excel.WorksheetFunction wsf = xl.WorksheetFunction;
//static settlementDate
var settlementDate = xl.Evaluate("=DATEVALUE(" + '"' + "9/4/2013" + '"' + ")");
//static maturityDate
var maturityDate = xl.Evaluate("=DATEVALUE("+ '"' +"12/5/2014"+ '"' +")");
var rate = "0.05250";
var priceLevel = "1.04800";
//assuming that redemption is 100, frequency is Quarterly and basis is Actual/365
var resultInPercentage = xl.Evaluate("=YIELD(" + settlementDate + "," + maturityDate + ",.05250,(1.04800*100),100,2,3)") * 100;
来源:https://stackoverflow.com/questions/801859/net-implementation-of-excel-yield-function