How to calculate Yield using Yield Function by C#

Dear Excel Guruz..
I have to calculate Yield using excel yield function in my C# program.In 
order to do that I have import 
using Microsoft.Office.Core;
using Excel = Microsoft.Office.Interop.Excel;
and write yield calcuation function . My function work fine for office 2007 
but onces I unistall 2007 , my code stopped wokring on any perivious version.

What I have observed my last line i.e used to calculate yield has problem
          result = xl.Evaluate("YIELD(" + days + "," + days1 + "," + rate + 
"," + par + "," + facevalue + "," + frequency + "," + basis + ")");

even though I change my dates arguments , though nothing happens in result.

Help me in this regards 

// ***********************Code*********************************
  Excel.Application xl = new Excel.Application();
            Excel.WorksheetFunction wsf = xl.WorksheetFunction;
            string satelmentdt = dtsatelment.Value.ToString();
            string maturitydt = dtmaturity.Value.ToString();
            dtobjectsatelemnt = DateTime.Parse(satelmentdt.ToString());
            dtobjectmaturity = DateTime.Parse(maturitydt.ToString());
            days = (dtobjectsatelemnt - startdt).Days;
            days1 = (dtobjectmaturity - startdt).Days;
            days = days + 2;
            days1 = days1 + 2;
            string rate = this.rate.Text;
            double par = double.Parse(this.par.Text.ToString());
            double redumptation = 
            string facevalue = "100";
            string frequency = "2";
            string basis = "1";
            object result;

          result = xl.Evaluate("YIELD(" + days + "," + days1 + "," + rate + 
"," + par + "," + facevalue + "," + frequency + "," + basis + ")");

            result.Text = result.ToString();

12/1/2009 9:19:01 AM
excel.programming 6508 articles. 2 followers. Follow

0 Replies

Similar Articles

[PageSpeed] 27


Similar Artilces:

Calculating Taxes and Making calculations
Hello, Kindly plz tell me how do i go about making some small calculations based on my existing data such as how to compute taxes and do other calculations based on some quantitative data. where exactly do i make modifications on my application??? Kindly help me out. Thanks , swati you can add code in javascript behind dropdowns or piclist fields. One example might be a dropdown which has shipping options ie ups, fedex etc. When you choose one it takes the weight of your package (whcih you enter) then calculates a shipping cost. search the archives of this group at and ...

How to Read/Write vsd uses Delphi?
I wana read/write vsd file by Borland Delphi. anyideas? Miles Guo What version of Delphi? Surely you can use the ActiveX control to access the vsd and its objects. Randall Arnold "miles guo" <> wrote in message news:%23f4tOnqHEHA.3376@TK2MSFTNGP09.phx.gbl... >I wana read/write vsd file by Borland Delphi. > anyideas? > > Miles Guo > > On Sat, 10 Apr 2004 11:13:29 +0800, "miles guo" <> wrote: >I wana read/write vsd file by Borland Delphi. >anyideas? -- Regards,...

Defining a variable then using it later
Hi all: First of all I am not a VB expert so please bear with me. I am trying to do the following... I have cell A1 which has a value, and that value changes. When I press a button on that page, I want to do the following: * Take the value in cell A1 * I want to take the value that is in cell A1 and unhide the corresponding sheet with the same value For example: The value in cell A1 = LT5 When the button is pressed the following line is run: Sheets([variable]).Visible = True I am sure this is possible, I just don't know the proper format. Thanks in advance! Hi Copy the fo...

Procedure to calculate distance using latitude/longitude
Does anyone know of a vba procedure for access that will calculate straightline distance using latitude and logitude for 2 points? AJ wrote: > Does anyone know of a vba procedure for access that will calculate > straightline distance using latitude and logitude for 2 points? See: James A. Fortune ...

Using OWA from another Exchange Server
Hi Guys! We have 2 Exchange Servers in the same organization, EXCH1 and EXCH2,OWA is enabled on EXCH1. Both servers have mailboxes. The question is how do I configure users on EXCH2 to logon to their mailboxes using the OWA running on EXCH1.Your response will be most appreciated. We run Exchange Server 2003 SP1 on Windows Server 2003 SP1 -- Buchi "Buchi" <> wrote in message > Hi Guys! > We have 2 Exchange Servers in the same organization, EXCH1 and EXCH2,OWA > is > en...

OT: MFC/C++ vs .Net/C#
Hey gang, I'm only posting this here because I've seen the light after many years of disparaging comments and snarks against .Net in general and specifically. Sorry for the past insinuations and ridicule ... this .net stuff absolutely rocks! ASP.Net is the way web development should've been from the beginning. I'm still hitting bumps in the road with C#, but every time I do it's because I'm trying to force C#/.Net to do things the way they would be done in MFC/C++. Each time I get back on track life is good again. I wish I wouldn't have been a h...

How to calculate age of a person?
Hi, I'm struggling to figure this one out. I have a date column and I'd like to be able to calculate the age without doing it in my head. I've tried to do this but am struggling. Any help will greatly appreciated. Thanks Suzanne Visit and search for DATEDIFF best wishes -- Bernard V Liengme Microsoft Excel MVP remove caps from email "Grd" <> wrote in message > Hi, > > I'm struggling to figure this one out. I have...

using groups in protected worksheet
Hi, I have grouped cells by using data/group and outline/group and after that I have protected the worksheet through tools/protection/protect. Now when I am in protection mode I cannot open (or close) a group. Is it possible to have a worksheet protected but allowing users to open(close) groups? -- lundgrendaniel ------------------------------------------------------------------------ lundgrendaniel's Profile: View this thread: Hi if you protect the sheet vi...

Using schema
I'm having much trouble in relating a xml file with a shema definition in order to validate the xml document and get advantage of the intellisense features of the .net ide. What steps I have to follow? Thanks Hi Mario, Check out : for a complete walkthrough. In short, if you don't have a pre-existing schema, you can just use the "Generate schema" menu option, which will generate an XSD file for you, and also associate your XML file with that XSD. Now, intellisense shou...

EXCEL 2007 Formula to calculate INTEREST only on a 3 month bridge
I am trying to calculate monthly INTEREST ONLY payment on a short term bridge/swing loan. Assuming an interest rate of 2.75%, paid monthly, Also assuming it will be required for a 3-6 month period, amount approx $500,000. Just switched to Excel 2007 but don't seem to be able to calculate using the formula builder. Not sure if it is compounded daily or monthly. You might want to check out the IPMT function. From the XL help file: IPMT(rate,per,nper,pv,fv,type) Rate is the interest rate per period. Per is the period for which you want to find the interest and must...

Due Date Calculated
I need assistance on an expression that allows for the due date of recurring training to be one year from date completed. Details are as follows: I have a form named [frmTRNComplete] based on table named [tblTRNComplete] Form controls are: TRNID (combo box), DateComp (Text Box) , DateNext (text box), Reccuring (check box) I would like the DateNext to be 1 year from DateComp if Reccuring is true and Date next to be blank if Reccuring is false. -- Aloha, Ron A. Ron I'll assume that you want to use the form to calculate the DateNext, and that you are not trying to s...

how to calculate outliers
Google is your friend: - Jon ------- Jon Peltier, Microsoft Excel MVP Tutorials and Custom Solutions Peltier Technical Services, Inc. - _______ "ismhs" <> wrote in message > ...

How to disconnect internet connection using VBA?
I manually connect the internet connection for Excel's macro to run a list of files, in order to retrieve data from external links. Once all files are completed updated, I would like to add coding at the end of process to disconnect the internet connection. Does anyone have any suggestions on how to code VBA macro to disconnect internet connect for macro? Thanks in advance for any suggestions Eric Eric, You have an ongoing thread about this in the microsoft.public.excel.programming newsgroup. Your last post about this *exact* subject was 30 minutes ago ? Be patient ...

Calculated field options???
Here's my Data: Country Status --------- ---------- Canada Green Canada Blue Canada Green Canada Green Canada Blue In my pivot table, 'Country' is an item, and 'Status' is my only data field. What I really need to show in my data area is two column of data, one for 'Green' and one for 'Blue'. I tried creating two 'Calculated' fields with the following formulas, but they don't seem to be working: 'CalculatedField1' = IF((STATUS="Green"),1,0) 'CalculatedF...

How to add formulas together, hours & minutes function.
Hi Group, Please could you give me an all singing, all dancing formula, or an explanation of how to put these together. A1 B1 23:00 07:30 =IF(B1<A1,B1+1,B1)-A1 This gives me the hours and minutes 8:30 in C1 (Format/Custom/HH:MM) One hour needs to be added so... =C1+01:00 gives me 09:30 in D1 (Format/Custom/HH:MM) Then I need it dislayed in decimal format =D1*24 which gives me 9.5 in E1(Format/General) It's not actually set out like that A1 B1 C1 D1, with the result I need in E1, but it makes it easier to explain. It's not urgent, as I already have the calculato...

tenure calculations
how can I format several dates such as 04/19/2003, 04/01/2004, etc. int a yearly average for the employee tenure -- Message posted from right now say I have my yearly figures in i1-i9. The formula I though would work is =today()-average(i1:i9), but how would i format this to give me yearly read out -- Message posted from Hi djackson! One way is to use YEARFRAC with a third argument of 1 to get your tenures in years and fractions of a year and then average the result. However YEARFRAC does produce some annoying but small errors. Y...

Time Sheet Function to Calculate
I am having some trouble trying to establish a formula that will give me the number of hours worked during the day given the start time say 8.30am with an end time of 5.30pm and say 30 minutes for lunch. For this scenario, total working hours would be eight and a half hours but I need Excel to display this result as 8.30 hours (0.30 being the minutes in the half hour) and not 8.50. Can someone suggest what to do? Typically the layout would be Column A - Start Time say 8.30am Column B - Time in minutes spent at lunch say 30 minutes Column C - End Time say 5.30pm. Column D - the calculati...

Formula to calculate time
I was wondering if anybody knows of a formula to allow you to do calculations based on time. In other words, say I want to put a list of songs on a CD and their durations. Then, I want to add up the durations to get the full time of the CD, or my specific play list. So for example, using the information below: Ghostbusters - Ray Parker Jr. --- 5:23 (Just a guess) Phantom of the Opera Overture --- 3:55 (Another guess) Instead of 8:78, I'd want to see 9:18 Can this be done? Any help would be greatly appreciated. Thank you! -- Have a nice day! ~Paul Express Scripts, Charting the futu...

Multiple Use of Product Key
I have recently bought a second laptop and am trying to register Microsoft Office Professional Plus 2007. I bought it as a student from my University. While trying to register on my new laptop, while also keeping my old laptop active, it says my product key is invalid. Anyone know why? Perhaps because you failed to uninstall any trial version first, or the version you purchased, Office Plus is a volume license which is not licensed for two PC's "tony777288" <> wrote in message news:0EC79925-7A11-4DFD-9C2A-152EF6488A04@m...

Hi, I need to transform one xml document into a second xml document. They both have many nodes so xslt works fine, but there is one node I have not figure out how to transform. Here it is: Node in Input File. <FullAddress>JOHN SMITH@19495 BISCAYNE BLVD@MIAMI@FL/33180@USA</FullAddress> The Result should be: <Name>JOHN SMITH</Name> <Address>19495 BISCAYNE BLVD</Address> <City>MIAMI</City> <State>FL</State> <ZipCode>33180</ZipCode> <Country>USA</Country> It seems to me I have to "Split" or "Par...

How to check if mouse wheel has been used, system-wide?
Hi! I have the following task - I need to check time to time if mouse wheel has been used by the user, in ANY application. I have some kind of user activity detector, to do certain actions in application when user is idle for some time. It would be nice to have the ability to check if mouse wheel has been used. I already know how to check for keyboard (GetKeyboardState and compare with previous call's result) and mouse (GetCursorPos and compare with previous call's result). I know how to set up a hook, and can achieve what I need via hook. But, customer says sometimes system runs slo...

Using the registry in Vista.
I haven't started programming to target Vista yet. (First, I need to buy a new computer that has Vista.) Currently, depending on my program, they run on either XP or Server 2003. Can I access the same areas of the registry in Vista? I've been putting everything in local machine. Can I continue to do that? If I can't, what do I do? If I write a service... They start up before a login. Right? So how do I use the registry in that case? >Can I access the same areas of the registry in Vista? You can - if you (the user running your program) has permission to do so. >I&#...

Insert calculated median field in pivottable
Anyone know how to get a median calculation in a pivot table? I've tried inserting a calculated field but it always sums the calculated field. Thanks, Joel Not supported in a pivot -- Regards, Peo Sjoblom (No private emails please) "Joel Schaefer" <> wrote in message news:ev4P0Nk6FHA.2616@TK2MSFTNGP15.phx.gbl... > Anyone know how to get a median calculation in a pivot table? I've tried > inserting a calculated field but it always sums the calculated field. > > Thanks, > > Joel > ...

duplicate resource. type:CURSOR when "Use MFC in a Static Library"
Good day, I have DLL with multiple resource files. When compiled in Debug compiles fine, in Release failes with error: CVTRES : fatal error CVT1100: duplicate resource. type:CURSOR, name:13, language:0x0409 I don't use CURSOR resource in RC files at all. I find out that it's caused by "Use MFC in a Static Library" - Release config with "Use MFC in a Static Library" fails, Release config with "Use MFC in a Shared DLL" works fine. Any hint? Thanks, Arek. ...

how do you use and run xsd.exe
Can not figure out how to use this tool ? Hi George, First of all, I would like to confirm my understanding of your issue. From your description, I understand that you need to know how to use xsd.exe provided by Visual Studio .NET SDK. If there is any misunderstanding, please feel free to let me know. Xsd.exe is the XML Schema Definition tool which generates XML schema or common language runtime classes from XDR, XML, and XSD files, or from classes in a runtime assembly. The file locates at C:\Program Files\Microsoft Visual Studio .NET 2003\SDK\v1.1\Bin You can run xsd.exe directl...