public static object eqInstIRBasisSwap( [ExcelArgument(Description = "trade id ")] string tradeid, [ExcelArgument(Description = "payer/receiver (1/0) ")] bool ispayer, [ExcelArgument(Description = "notional ")] double notional, [ExcelArgument(Description = "start date ")] DateTime startdate, [ExcelArgument(Description = " (String) forward start month, e.g. 7D, 3M, 7Y ")] string Tenor, [ExcelArgument(Description = "id of base index ")] string baseindexid, [ExcelArgument(Description = "id of basis index ")] string basisindexid, [ExcelArgument(Description = "basis leg spread ")] double spread, [ExcelArgument(Description = "id of discount curve ")] string discountId, [ExcelArgument(Description = "trigger ")] object trigger) { if (ExcelUtil.CallFromWizard()) { return(""); } string callerAddress = ""; callerAddress = ExcelUtil.getActiveCellAddress(); try { Xl.Range rng = ExcelUtil.getActiveCellRange(); // by default // endOfMonth_(1*Months<=swapTenor && swapTenor<=2*Years ? true : false), bool end_of_month = true; EliteQuant.DayCounter fixeddc = new EliteQuant.Actual360(); if (!baseindexid.Contains('@')) { baseindexid = "IDX@" + baseindexid; } IborIndex baseidx = OHRepository.Instance.getObject <IborIndex>(baseindexid); if (!basisindexid.Contains('@')) { basisindexid = "IDX@" + basisindexid; } IborIndex basisidx = OHRepository.Instance.getObject <IborIndex>(basisindexid); if (!discountId.Contains('@')) { discountId = "CRV@" + discountId; } YieldTermStructure discountcurve = OHRepository.Instance.getObject <YieldTermStructure>(discountId); YieldTermStructureHandle dch = new YieldTermStructureHandle(discountcurve); EliteQuant.Period tenor_ = EliteQuant.EQConverter.ConvertObject <EliteQuant.Period>(Tenor); EliteQuant.Date sdate = EliteQuant.EQConverter.ConvertObject <EliteQuant.Date>(startdate); EliteQuant.Date fdate = baseidx.fixingDate(sdate); EliteQuant.Date tdate = baseidx.fixingCalendar().advance(sdate, tenor_); // fixed leg 1 yr. Forward? Schedule basesch = new Schedule(sdate, tdate, baseidx.tenor(), baseidx.fixingCalendar(), baseidx.businessDayConvention(), baseidx.businessDayConvention(), DateGeneration.Rule.Backward, end_of_month); Schedule basissch = new Schedule(sdate, tdate, basisidx.tenor(), basisidx.fixingCalendar(), basisidx.businessDayConvention(), basisidx.businessDayConvention(), DateGeneration.Rule.Backward, end_of_month); //GenericSwap swap = new GenericSwap((ispayer ? _GenericSwap.Type.Payer : _GenericSwap.Type.Receiver), notional, // basesch, baseidx, baseidx.dayCounter(), basissch, basisidx, basisidx.dayCounter(), spread); //DiscountingSwapEngine engine = new DiscountingSwapEngine(dch); //swap.setPricingEngine(engine); //Date refDate = discountcurve.referenceDate(); // Store the futures and return its id //string id = "SWP@" + tradeid; //OHRepository.Instance.storeObject(id, swap, callerAddress); //id += "#" + (String)DateTime.Now.ToString(@"HH:mm:ss"); //return id; return(0); } catch (Exception e) { ExcelUtil.logError(callerAddress, System.Reflection.MethodInfo.GetCurrentMethod().Name.ToString(), e.Message); return("#EQ_ERR!"); } }
public static object eqInstIRVanillaSwap( [ExcelArgument(Description = "trade id ")] string tradeid, [ExcelArgument(Description = "payer/receiver (1/0) ")] bool ispayer, [ExcelArgument(Description = "notional ")] double notional, [ExcelArgument(Description = "fixed rate ")] double fixedRate, [ExcelArgument(Description = "start date ")] DateTime startdate, [ExcelArgument(Description = " (String) forward start month, e.g. 7D, 3M, 7Y ")] string Tenor, [ExcelArgument(Description = "id of libor index ")] string indexid, [ExcelArgument(Description = "floating leg spread ")] double spread, [ExcelArgument(Description = "id of discount curve ")] string discountId, [ExcelArgument(Description = "trigger ")] object trigger) { if (ExcelUtil.CallFromWizard()) { return(""); } string callerAddress = ""; callerAddress = ExcelUtil.getActiveCellAddress(); try { Xl.Range rng = ExcelUtil.getActiveCellRange(); // by default bool end_of_month = true; EliteQuant.DayCounter fixeddc = new EliteQuant.Thirty360(); EliteQuant.Period tenor_ = EliteQuant.EQConverter.ConvertObject <EliteQuant.Period>(Tenor); if (!indexid.Contains('@')) { indexid = "IDX@" + indexid; } IborIndex idx = OHRepository.Instance.getObject <IborIndex>(indexid); if (!discountId.Contains('@')) { discountId = "CRV@" + discountId; } YieldTermStructure discountcurve = OHRepository.Instance.getObject <YieldTermStructure>(discountId); YieldTermStructureHandle dch = new YieldTermStructureHandle(discountcurve); EliteQuant.Date sdate = EliteQuant.EQConverter.ConvertObject <EliteQuant.Date>(startdate); EliteQuant.Date fdate = idx.fixingDate(sdate); EliteQuant.Date tdate = idx.fixingCalendar().advance(sdate, tenor_); Schedule fixedsch = new Schedule(sdate, tdate, new Period(6, TimeUnit.Months), idx.fixingCalendar(), idx.businessDayConvention(), idx.businessDayConvention(), DateGeneration.Rule.Backward, end_of_month); Schedule floatingsch = new Schedule(sdate, tdate, idx.tenor(), idx.fixingCalendar(), idx.businessDayConvention(), idx.businessDayConvention(), DateGeneration.Rule.Backward, end_of_month); VanillaSwap swap = new VanillaSwap(ispayer ? _VanillaSwap.Type.Payer : _VanillaSwap.Type.Receiver, notional, fixedsch, fixedRate, fixeddc, floatingsch, idx, spread, idx.dayCounter()); DiscountingSwapEngine engine = new DiscountingSwapEngine(dch); swap.setPricingEngine(engine); Date refDate = discountcurve.referenceDate(); // Store the futures and return its id string id = "SWP@" + tradeid; OHRepository.Instance.storeObject(id, swap, callerAddress); id += "#" + (String)DateTime.Now.ToString(@"HH:mm:ss"); return(id); } catch (Exception e) { ExcelUtil.logError(callerAddress, System.Reflection.MethodInfo.GetCurrentMethod().Name.ToString(), e.Message); return("#EQ_ERR!"); } }