Esempio n. 1
0
 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(GenericSwap obj)
 {
     return((obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr);
 }
        public static object eqInstDisplayIRSwap(
            [ExcelArgument(Description = "id of IR Swap ")] string tradeid,
            [ExcelArgument(Description = "id of discount curve ")] string discountId,
            [ExcelArgument(Description = "trigger ")] object trigger)
        {
            if (ExcelUtil.CallFromWizard())
            {
                return("");
            }

            string callerAddress = "";

            callerAddress = ExcelUtil.getActiveCellAddress();

            object[,] ret;
            try
            {
                Xl.Range rng = ExcelUtil.getActiveCellRange();


                if (!tradeid.Contains('@'))
                {
                    tradeid = "SWP@" + tradeid;
                }

                if (!discountId.Contains('@'))
                {
                    discountId = "CRV@" + discountId;
                }
                YieldTermStructure discountcurve = OHRepository.Instance.getObject <YieldTermStructure>(discountId);
                Date asofdate = Settings.instance().getEvaluationDate();

                GenericSwap inst = OHRepository.Instance.getObject <GenericSwap>(tradeid);

                int rows = Math.Max(inst.firstLegInfo().Count, inst.secondLegInfo().Count);
                ret = new object[rows, 20];     // 10 cols each leg
                for (int i = 0; i < rows; i++)
                {
                    for (int j = 0; j < 20; j++)
                    {
                        ret[i, j] = "";         // initialization. null will be posted as 0; so explicitly set it to ""
                    }
                }

                // first leg
                string[] s;
                DateTime startdate, enddate, paymentdate, resetdate;
                double   balance = 0, rate = 0, spread = 0, payment = 0, discount = 0, pv = 0;
                for (int i = 0; i < inst.firstLegInfo().Count; i++)
                {
                    s           = inst.firstLegInfo()[i].Split(',');
                    startdate   = EliteQuant.EQConverter.DateToDateTime(new Date(Convert.ToInt32(s[0])));
                    enddate     = EliteQuant.EQConverter.DateToDateTime(new Date(Convert.ToInt32(s[1])));
                    paymentdate = EliteQuant.EQConverter.DateToDateTime(new Date(Convert.ToInt32(s[2])));
                    resetdate   = (s[3] == "") ? DateTime.MinValue : EliteQuant.EQConverter.DateToDateTime(new Date(Convert.ToInt32(s[3])));
                    balance     = Convert.ToDouble(s[4]);
                    rate        = Convert.ToDouble(s[5]);
                    spread      = Convert.ToDouble(s[6]);
                    payment     = Convert.ToDouble(s[7]);

                    // today's cashflow is not included
                    if (EliteQuant.EQConverter.DateTimeToDate(paymentdate).serialNumber() <= asofdate.serialNumber())
                    {
                        discount = 0.0;
                    }
                    else
                    {
                        discount = discountcurve.discount(EliteQuant.EQConverter.DateTimeToDate(paymentdate));
                    }

                    pv = payment * discount;

                    // and return the matrix to vba
                    ret[i, 0] = (object)startdate;
                    ret[i, 1] = (object)enddate;
                    ret[i, 2] = (object)paymentdate;
                    ret[i, 3] = (s[3] == "") ? "":(object)resetdate;
                    ret[i, 4] = (object)(balance == 0 ? "" : (object)balance);
                    ret[i, 5] = (object)(rate == 0 ? "" : (object)rate);
                    ret[i, 6] = (object)(spread == 0 ? "" : (object)spread);
                    ret[i, 7] = (object)(payment == 0 ? "" : (object)payment);
                    ret[i, 8] = (object)(discount == 0 ? "" : (object)discount);
                    ret[i, 9] = (object)(pv == 0 ? "" : (object)pv);
                }
                for (int i = 0; i < inst.secondLegInfo().Count; i++)
                {
                    s           = inst.secondLegInfo()[i].Split(',');
                    startdate   = EliteQuant.EQConverter.DateToDateTime(new Date(Convert.ToInt32(s[0])));
                    enddate     = EliteQuant.EQConverter.DateToDateTime(new Date(Convert.ToInt32(s[1])));
                    paymentdate = EliteQuant.EQConverter.DateToDateTime(new Date(Convert.ToInt32(s[2])));
                    resetdate   = (s[3] == "") ? DateTime.MinValue : EliteQuant.EQConverter.DateToDateTime(new Date(Convert.ToInt32(s[3])));
                    balance     = Convert.ToDouble(s[4]);
                    rate        = Convert.ToDouble(s[5]);
                    spread      = Convert.ToDouble(s[6]);
                    payment     = Convert.ToDouble(s[7]);

                    // today's cashflow is not included
                    if (EliteQuant.EQConverter.DateTimeToDate(paymentdate).serialNumber() <= asofdate.serialNumber())
                    {
                        discount = 0.0;
                    }
                    else
                    {
                        discount = discountcurve.discount(EliteQuant.EQConverter.DateTimeToDate(paymentdate));
                    }

                    pv = payment * discount;

                    // and return the matrix to vba
                    ret[i, 10] = (object)startdate;
                    ret[i, 11] = (object)enddate;
                    ret[i, 12] = (object)paymentdate;
                    ret[i, 13] = (s[3] == "") ? "" : (object)resetdate;
                    ret[i, 14] = (object)(balance == 0 ? "" : (object)balance);
                    ret[i, 15] = (object)(rate == 0 ? "" : (object)rate);
                    ret[i, 16] = (object)(spread == 0 ? "" : (object)spread);
                    ret[i, 17] = (object)(payment == 0 ? "" : (object)payment);
                    ret[i, 18] = (object)(discount == 0 ? "" : (object)discount);
                    ret[i, 19] = (object)(pv == 0 ? "" : (object)pv);
                }

                return(ret);
            }
            catch (Exception e)
            {
                ExcelUtil.logError(callerAddress, System.Reflection.MethodInfo.GetCurrentMethod().Name.ToString(), e.Message);
                return("#EQ_ERR!");
            }
        }