public static object eqTimeAdvanceDate( [ExcelArgument(Description = "Date ")] DateTime date, [ExcelArgument(Description = "Calendar (default NYC) ")] string calendar, [ExcelArgument(Description = "Tenor (e.g. '3D' or '2Y') ")] string tenor, [ExcelArgument(Description = "BusinessDayConvention (default ModifiedFollowing) ")] string bdc, [ExcelArgument(Description = "is endofmonth ")] bool eom) { if (ExcelUtil.CallFromWizard()) { return(""); } string callerAddress = ""; callerAddress = ExcelUtil.getActiveCellAddress(); OHRepository.Instance.removeErrorMessage(callerAddress); try { if (date == DateTime.MinValue) { throw new Exception("Date must not be empty. "); } EliteQuant.Date d = EliteQuant.EQConverter.ConvertObject <EliteQuant.Date>(date); if (string.IsNullOrEmpty(calendar)) { calendar = "NYC"; } EliteQuant.Calendar can = EliteQuant.EQConverter.ConvertObject <EliteQuant.Calendar>(calendar); if (string.IsNullOrEmpty(tenor)) { tenor = "1D"; } EliteQuant.Period period = EliteQuant.EQConverter.ConvertObject <EliteQuant.Period>(tenor); if (string.IsNullOrEmpty(bdc)) { bdc = "MF"; } BusinessDayConvention bdc2 = EliteQuant.EQConverter.ConvertObject <BusinessDayConvention>(bdc); Date newday = can.advance(d, period, bdc2, eom); return(newday.serialNumber()); } catch (Exception e) { ExcelUtil.logError(callerAddress, System.Reflection.MethodInfo.GetCurrentMethod().Name.ToString(), e.Message); return(e.Message); } }
public static object eqTimeSchedule( [ExcelArgument(Description = "Start Date ")] DateTime date1, [ExcelArgument(Description = "End Date ")] DateTime date2, [ExcelArgument(Description = "Tenor (e.g. '3D' or '2Y') ")] string tenor, [ExcelArgument(Description = "Calendar (default NYC) ")] string calendar, [ExcelArgument(Description = "BusinessDayConvention (default ModifiedFollowing) ")] string bdc, [ExcelArgument(Description = "DateGenerationRule (default Backward) ")] string rule, [ExcelArgument(Description = "is endofmonth ")] bool eom) { if (ExcelUtil.CallFromWizard()) { return(""); } string callerAddress = ""; callerAddress = ExcelUtil.getActiveCellAddress(); OHRepository.Instance.removeErrorMessage(callerAddress); try { if ((date1 == DateTime.MinValue) || (date2 == DateTime.MinValue)) { throw new Exception("Date must not be empty. "); } Date start = EliteQuant.EQConverter.ConvertObject <Date>(date1); Date end = EliteQuant.EQConverter.ConvertObject <Date>(date2); EliteQuant.Period period = EliteQuant.EQConverter.ConvertObject <EliteQuant.Period>(tenor); if (string.IsNullOrEmpty(calendar)) { calendar = "NYC"; } EliteQuant.Calendar can = EliteQuant.EQConverter.ConvertObject <EliteQuant.Calendar>(calendar); if (string.IsNullOrEmpty(bdc)) { bdc = "MF"; } BusinessDayConvention bdc2 = EliteQuant.EQConverter.ConvertObject <BusinessDayConvention>(bdc); if (string.IsNullOrEmpty(rule)) { rule = "BACKWARD"; } DateGeneration.Rule rule2 = EliteQuant.EQConverter.ConvertObject <DateGeneration.Rule>(rule); Schedule sch = new Schedule(start, end, period, can, bdc2, bdc2, rule2, eom); object[,] ret = new object[sch.size(), 1]; for (uint i = 0; i < sch.size(); i++) { ret[i, 0] = sch.date(i).serialNumber(); } return(ret); } catch (Exception e) { ExcelUtil.logError(callerAddress, System.Reflection.MethodInfo.GetCurrentMethod().Name.ToString(), e.Message); return(""); } }
public static object eqInstIROISSwap( [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 overnight 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 // endOfMonth_(1*Months<=swapTenor && swapTenor<=2*Years ? true : false), bool end_of_month = true; EliteQuant.DayCounter fixeddc = new EliteQuant.Actual360(); if (!indexid.Contains('@')) { indexid = "IDX@" + indexid; } OvernightIndex idx = OHRepository.Instance.getObject <OvernightIndex>(indexid); 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 = idx.fixingDate(sdate); EliteQuant.Date tdate = idx.fixingCalendar().advance(sdate, tenor_); // fixed leg 1 yr. Forward? Schedule fixedsch = new Schedule(sdate, tdate, new Period(1, TimeUnit.Years), idx.fixingCalendar(), idx.businessDayConvention(), idx.businessDayConvention(), DateGeneration.Rule.Forward, end_of_month); OvernightIndexedSwap swap = new OvernightIndexedSwap(ispayer ? _OvernightIndexedSwap.Type.Payer : _OvernightIndexedSwap.Type.Receiver, notional, fixedsch, fixedRate, fixeddc, idx, 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); } catch (Exception e) { ExcelUtil.logError(callerAddress, System.Reflection.MethodInfo.GetCurrentMethod().Name.ToString(), e.Message); return("#EQ_ERR!"); } }