// Add fixed coupon bond to the dictionary string ICalculator.LoadBondFixedCouponSerialLoadBondFixedCoupon(string idCode, double Today, double StartDateBond, double EndDateBond, double Coupon, string BondFixedCouponType, string FileFullPath) { // for details of inputs refer to comments on BondDBR,BondBTAN,BondBTP classes // as example, I decide to use only 3 type of bond DBR,BTAN,BTP (arbitrary strings) BaseBond bond = null; if (BondFixedCouponType == "DBR") // BondDBR { bond = new BondDBR(new Date(Today), new Date(StartDateBond), new Date(EndDateBond), Coupon); } else if (BondFixedCouponType == "BTAN") // BondBTAN { bond = new BondBTAN(new Date(Today), new Date(StartDateBond), new Date(EndDateBond), Coupon); } else if (BondFixedCouponType == "BTP") // BondBTP { bond = new BondBTP(new Date(Today), new Date(StartDateBond), new Date(EndDateBond), Coupon); } else if (BondFixedCouponType == "BOT") // BondBOT { bond = new BondBOT(new Date(Today), new Date(StartDateBond), new Date(EndDateBond)); } else { return("Bond not recognized"); // if not managed } try { if (BondDictionarySerial.ContainsKey(idCode) == true) // check if idCode is in dictionary { BondDictionarySerial[idCode] = bond; // if true, updates it } else { BondDictionarySerial.Add(idCode, bond); // if false, adds it } return("Loaded @ " + DateTime.Now.ToString()); // return time of last load } catch (Exception e) { return((string)e.ToString()); } }
// will return yield on BondBTP according to given Freq, DayCount, compounding double ICalculator.BondBTPYield(double Today, double StartDateBond, double EndDateBond, double Coupon, double CleanPrice, int Freq, string DayCount, string Compounding) { // Freq, DayCount, compounding refer to yield calculation // make it volatile if (m_xlApp != null) { m_xlApp.Volatile(true); } // initialise the bond BondBTP b = new BondBTP(new Date(Today), new Date(StartDateBond), new Date(EndDateBond), Coupon); // Parse enum Type Dc dc = (Dc)Enum.Parse(typeof(Dc), DayCount); Compounding comp = (Compounding)Enum.Parse(typeof(Compounding), Compounding); // return the yield return(b.Yield(CleanPrice, Freq, dc, comp)); }
// will return some descriptive data on BondBTP as example double[,] ICalculator.BondBTPData(double Today, double StartDateBond, double EndDateBond, double Coupon, double CleanPrice) { // make it volatile if (m_xlApp != null) { m_xlApp.Volatile(true); } // initialise the bond BondBTP b = new BondBTP(new Date(Today), new Date(StartDateBond), new Date(EndDateBond), Coupon); // will return column with 6 element double[,] outPut = new double[6, 1]; outPut[0, 0] = b.GetSettlementDate().SerialValue; // settlement date of the bond outPut[1, 0] = b.GetLastCouponDate().SerialValue; // last coupon date of the bond outPut[2, 0] = b.GetNextCouponDate().SerialValue; // next coupon date of the bond outPut[3, 0] = b.GetCurrentCoupon(); // current coupon rate outPut[4, 0] = b.DirtyPrice(CleanPrice); // dirty price of the bond outPut[5, 0] = b.AccruedInterest(); // accrued interest of the bond as amount return(outPut); // here output }