Exemplo n.º 1
0
        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!");
            }
        }