Exemplo n.º 1
0
        public static string eqIRCurveLiborBasisSwapHelper(
            [ExcelArgument(Description = "(String) id of rate helper object ")] String ObjectId,
            [ExcelArgument(Description = "(String) base leg (usually USDLIB3M) ")] String baseLeg,
            [ExcelArgument(Description = "(String) basis leg (USDLIB1M, USDLIB6M, etc) ")] String basisLeg,
            [ExcelArgument(Description = "(double) basis spread ")] double basis,
            [ExcelArgument(Description = "(String) basis swap tenor (1Y, 2Y, etc) ")] String tenor,
            [ExcelArgument(Description = "Discount Curve (USDLIB3M or USDOIS) ")] String discount,
            [ExcelArgument(Description = "trigger ")] object trigger)
        {
            if (ExcelUtil.CallFromWizard())
            {
                return("");
            }

            string callerAddress = ExcelUtil.getActiveCellAddress();

            try
            {
                // use default value. Eonia and ois has same convention
                if (!baseLeg.Contains('@'))
                {
                    baseLeg = "IDX" + baseLeg;
                }
                EliteQuant.IborIndex baseidx  = OHRepository.Instance.getObject <EliteQuant.IborIndex>(baseLeg);
                EliteQuant.IborIndex basisidx = null;
                switch (basisLeg.ToUpper())
                {
                case "USDLIB1M":
                    basisidx = new EliteQuant.USDLibor(new EliteQuant.Period(1, EliteQuant.TimeUnit.Months));
                    break;

                case "USDLIB6M":
                    basisidx = new EliteQuant.USDLibor(new EliteQuant.Period(6, EliteQuant.TimeUnit.Months));
                    break;

                case "USDLIB12M":
                    basisidx = new EliteQuant.USDLibor(new EliteQuant.Period(12, EliteQuant.TimeUnit.Months));
                    break;

                default:
                    break;
                }

                EliteQuant.YieldTermStructure       curve = null;
                EliteQuant.YieldTermStructureHandle yth   = null;

                if (!discount.Contains('@'))
                {
                    discount = "CRV@" + discount;
                }
                if (!ExcelUtil.isNull(discount))
                {
                    curve = OHRepository.Instance.getObject <EliteQuant.YieldTermStructure>(discount);
                    yth   = new EliteQuant.YieldTermStructureHandle(curve);
                }

                EliteQuant.QuoteHandle basis_ = new EliteQuant.QuoteHandle(new EliteQuant.SimpleQuote(basis));
                EliteQuant.Period      tenor_ = EliteQuant.EQConverter.ConvertObject <EliteQuant.Period>(tenor);

                // arithmetic average, not compounded. USBG
                EliteQuant.RateHelper rh = new EliteQuant.IBORBasisRateHelper(2, tenor_, basis_, baseidx, basisidx, yth);

                string id = "RHBAS@" + ObjectId;
                OHRepository.Instance.storeObject(id, rh, callerAddress);
                return(id + "#" + DateTime.Now.ToString("HH:mm:ss"));
            }
            catch (Exception e)
            {
                ExcelUtil.logError(callerAddress, System.Reflection.MethodInfo.GetCurrentMethod().Name.ToString(), e.Message);
                return("#EQ_ERR!");
            }
        }
Exemplo n.º 2
0
        public static string eqIRCurveLinearZero(
            [ExcelArgument(Description = "(String) id of curve (USDOIS, USDLIB3M) ")] string ObjectId,
            [ExcelArgument(Description = "array of rate helpers ")] object[] ratehelpers,
            [ExcelArgument(Description = "Interpolation Method (default LogLinear) ")] string interp,
            [ExcelArgument(Description = "trigger ")] object trigger)
        {
            if (ExcelUtil.CallFromWizard())
            {
                return("");
            }

            string callerAddress = ExcelUtil.getActiveCellAddress();

            Xl.Range rng = ExcelUtil.getActiveCellRange();

            try
            {
                string interpmethod;
                if (ExcelUtil.isNull(interp))
                {
                    interpmethod = "LOGLINEAR";
                }
                else
                {
                    interpmethod = interp.ToUpper();
                }

                EliteQuant.RateHelperVector rhv = new EliteQuant.RateHelperVector();

                EliteQuant.Date        today = EliteQuant.Settings.instance().getEvaluationDate();
                List <EliteQuant.Date> dates = new List <EliteQuant.Date>();
                dates.Add(today);       // today has discount 1

                foreach (var rid in ratehelpers)
                {
                    if (ExcelUtil.isNull(rid))
                    {
                        continue;
                    }

                    try
                    {
                        EliteQuant.RateHelper rh = OHRepository.Instance.getObject <EliteQuant.RateHelper>((string)rid);
                        rhv.Add(rh);
                        dates.Add(rh.latestDate());
                    }
                    catch (Exception)
                    {
                        // skip null instruments
                    }
                }

                // set reference date to today. or discount to 1
                EliteQuant.YieldTermStructure yth = new EliteQuant.PiecewiseLogLinearDiscount(today, rhv, dc_act_360);

                EliteQuant.DateVector   dtv   = new EliteQuant.DateVector();
                EliteQuant.DoubleVector discv = new EliteQuant.DoubleVector();
                foreach (var dt in dates)
                {
                    double disc = yth.discount(dt);
                    dtv.Add(dt);
                    discv.Add(disc);
                }

                // reconstruct the discount curve
                // note that discount curve is LogLinear
                EliteQuant.YieldTermStructure yth2 = null;
                yth2 = new EliteQuant.DiscountCurve(dtv, discv, dc_act_360, ObjectId.Contains("OIS") ? cal_usd : cal_usd_gbp);

                if (!ObjectId.Contains('@'))
                {
                    ObjectId = "CRV@" + ObjectId;
                }

                //string id = "IRCRV@" + ObjectId;
                string id = ObjectId;
                OHRepository.Instance.storeObject(id, yth2, callerAddress);
                return(id + "#" + DateTime.Now.ToString("HH:mm:ss"));
            }
            catch (Exception e)
            {
                ExcelUtil.logError(callerAddress, System.Reflection.MethodInfo.GetCurrentMethod().Name.ToString(), e.Message);
                return("#EQ_ERR!");
            }
        }
Exemplo n.º 3
0
        public static string eqIRCurveSwapRateHelper(
            [ExcelArgument(Description = "(String) id of rate helper object ")] String ObjectId,
            [ExcelArgument(Description = "(double) quote of swap rate ")] double quote,
            [ExcelArgument(Description = "(String) forward start month, e.g. 7D, 3M ")] String Tenor,
            [ExcelArgument(Description = " spread ")] double spread,
            [ExcelArgument(Description = " name of swap curve(USDLIB3M, USDLIB1M, USDLIB6M, USDLIB12M) ")] string idx,
            [ExcelArgument(Description = " id of discount curve (USDOIS) ")] string discount,
            [ExcelArgument(Description = "trigger ")] object trigger)
        {
            if (ExcelUtil.CallFromWizard())
            {
                return("");
            }

            string callerAddress = ExcelUtil.getActiveCellAddress();

            try
            {
                // use default value
                EliteQuant.IborIndex idx_usdlibor = null;

                EliteQuant.QuoteHandle rate_  = new EliteQuant.QuoteHandle(new EliteQuant.SimpleQuote(quote));
                EliteQuant.Period      tenor_ = EliteQuant.EQConverter.ConvertObject <EliteQuant.Period>(Tenor);

                if (ExcelUtil.isNull(spread))
                {
                    spread = 0.0;
                }
                EliteQuant.QuoteHandle spread_ = new EliteQuant.QuoteHandle(new EliteQuant.SimpleQuote(spread));

                EliteQuant.RateHelper rh = null;

                if (ExcelUtil.isNull(idx))
                {
                    idx_usdlibor = new EliteQuant.USDLibor(new EliteQuant.Period(3, EliteQuant.TimeUnit.Months));
                }
                else
                {
                    switch (idx)
                    {
                    case "USDLIB1M":
                        idx_usdlibor = new EliteQuant.USDLibor(new EliteQuant.Period(1, EliteQuant.TimeUnit.Months));
                        break;

                    case "USDLIB6M":
                        idx_usdlibor = new EliteQuant.USDLibor(new EliteQuant.Period(6, EliteQuant.TimeUnit.Months));
                        break;

                    case "USDLIB12M":
                        idx_usdlibor = new EliteQuant.USDLibor(new EliteQuant.Period(12, EliteQuant.TimeUnit.Months));
                        break;

                    default:
                        idx_usdlibor = new EliteQuant.USDLibor(new EliteQuant.Period(3, EliteQuant.TimeUnit.Months));
                        break;
                    }
                }

                if (ExcelUtil.isNull(discount))
                {
                    rh = new EliteQuant.SwapRateHelper(rate_, tenor_,
                                                       cal_usd_gbp, EliteQuant.Frequency.Semiannual, bdc_usd, dc_30_360, idx_usdlibor);
                }
                else
                {
                    if (!discount.Contains('@'))
                    {
                        discount = "CRV@" + discount;
                    }

                    EliteQuant.YieldTermStructure       curve = OHRepository.Instance.getObject <EliteQuant.YieldTermStructure>(discount);
                    EliteQuant.YieldTermStructureHandle yth   = new EliteQuant.YieldTermStructureHandle(curve);
                    rh = new EliteQuant.SwapRateHelper(rate_, tenor_,
                                                       cal_usd_gbp, EliteQuant.Frequency.Semiannual, bdc_usd, dc_30_360,
                                                       idx_usdlibor, spread_, new EliteQuant.Period(0, EliteQuant.TimeUnit.Days), yth);
                }

                string id = "RHSWP@" + ObjectId;
                OHRepository.Instance.storeObject(id, rh, callerAddress);
                return(id + "#" + DateTime.Now.ToString("HH:mm:ss"));
            }
            catch (Exception e)
            {
                ExcelUtil.logError(callerAddress, System.Reflection.MethodInfo.GetCurrentMethod().Name.ToString(), e.Message);
                return("#EQ_ERR!");
            }
        }