Esempio n. 1
0
        public static object eqCurveIRGetDiscountFactor(
            [ExcelArgument(Description = "curve id ")] string ObjectId,
            [ExcelArgument(Description = "tenors ")] DateTime dt,
            [ExcelArgument(Description = "trigger ")] object trigger)
        {
            if (ExcelUtil.CallFromWizard())
            {
                return("");
            }

            string callerAddress = ExcelUtil.getActiveCellAddress();

            try
            {
                Xl.Range rng = ExcelUtil.getActiveCellRange();

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

                YieldTermStructureHandle curve = OHRepository.Instance.getObject <YieldTermStructureHandle>(ObjectId);
                Date refDate = curve.referenceDate();

                Date   dt2      = EliteQuant.EQConverter.ConvertObject <Date>(dt);
                double discount = curve.discount(dt2);

                return(discount);
            }
            catch (Exception e)
            {
                ExcelUtil.logError(callerAddress, System.Reflection.MethodInfo.GetCurrentMethod().Name.ToString(), e.Message);
                return("#EQ_ERR!");
            }
        }
Esempio n. 2
0
        public static object eqInstCommodityFuture(
            [ExcelArgument(Description = "id of instrument ")] string ObjectId,
            [ExcelArgument(Description = "name of instrument ")] string name,       // given by user, could be the same as objectid
            [ExcelArgument(Description = "buy/sell (1/-1) ")] int buysell,
            [ExcelArgument(Description = "trade price ")] double tradePrice,
            [ExcelArgument(Description = "trade quantity ")] double quantity,
            [ExcelArgument(Description = "start date ")] DateTime startdate,
            [ExcelArgument(Description = "end date ")] DateTime enddate,
            [ExcelArgument(Description = "id of commodity index ")] string indexid,
            [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();
                CommodityIndexExt        idx           = OHRepository.Instance.getObject <CommodityIndexExt>(indexid);
                YieldTermStructureHandle discountcurve = OHRepository.Instance.getObject <YieldTermStructureHandle>(discountId);
                Date refDate = discountcurve.referenceDate();

                EliteQuant.Date sd = EliteQuant.EQConverter.ConvertObject <EliteQuant.Date>(startdate);
                EliteQuant.Date ed = EliteQuant.EQConverter.ConvertObject <EliteQuant.Date>(enddate);

                PricingPeriodExt pp = new PricingPeriodExt(sd, ed, sd, quantity);         // pay at start date
                EnergyFutureExt  ef = new EnergyFutureExt(buysell, pp, tradePrice, idx, name, discountcurve);

                // Store the futures and return its id
                string id = "Fut@" + ObjectId;
                OHRepository.Instance.storeObject(id, ef, 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!");
            }
        }
Esempio n. 3
0
        public static object eqInstCommodityVanillaSwap(
            [ExcelArgument(Description = "id of instrument ")] string ObjectId,
            [ExcelArgument(Description = "name of instrument ")] string name,
            [ExcelArgument(Description = "payer/receiver (1/0) ")] bool payer,
            [ExcelArgument(Description = "trade price ")] double fixedPrice,
            [ExcelArgument(Description = "trade quantity ")] double[] quantities,
            [ExcelArgument(Description = "start date ")] object[] startdates,
            [ExcelArgument(Description = "end date ")] object[] enddates,
            [ExcelArgument(Description = "id of commodity index ")] string indexid,
            [ExcelArgument(Description = "id of discount curve ")] string discountId,
            [ExcelArgument(Description = "trigger ")] object trigger)
        {
            if (ExcelUtil.CallFromWizard())
            {
                return("");
            }

            string callerAddress = "";

            callerAddress = ExcelUtil.getActiveCellAddress();

            try
            {
                //bool ispayer = string.Compare(payer.ToUpper(), "PAYER") == 0 ? true : false;
                bool ispayer = payer;
                if (startdates.Length != enddates.Length)
                {
                    return("size mismatch");
                }

                Xl.Range                 rng           = ExcelUtil.getActiveCellRange();
                CommodityIndexExt        idx           = OHRepository.Instance.getObject <CommodityIndexExt>(indexid);
                YieldTermStructureHandle discountcurve = OHRepository.Instance.getObject <YieldTermStructureHandle>(discountId);
                Date refDate = discountcurve.referenceDate();

                PricingPeriodExts pps = new PricingPeriodExts(startdates.Length);

                for (int i = 0; i < startdates.Length; i++)
                {
                    if (ExcelUtil.isNull(startdates[i]))
                    {
                        continue;
                    }

                    //EliteQuant.Date sd = Conversion.ConvertObject<EliteQuant.Date>((DateTime)startdates[i], "date");
                    //EliteQuant.Date ed = Conversion.ConvertObject<EliteQuant.Date>((DateTime)enddates[i], "date");
                    Date sd = new Date(Convert.ToInt32(startdates[i]));
                    Date ed = new Date(Convert.ToInt32(enddates[i]));

                    PricingPeriodExt pp = new PricingPeriodExt(sd, ed, sd, quantities[i]);
                    pps.Add(pp);
                }

                EnergyVanillaSwapExt evs = new EnergyVanillaSwapExt(ispayer, fixedPrice, idx, pps, name, discountcurve, discountcurve,
                                                                    Frequency.Monthly, new NullCalendar());

                // Store the futures and return its id
                string id = "Swp@" + ObjectId;
                OHRepository.Instance.storeObject(id, evs, 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!");
            }
        }
Esempio n. 4
0
        public static object eqInstCommodityBasisSwap(
            [ExcelArgument(Description = "id of instrument ")] string ObjectId,
            [ExcelArgument(Description = "name of instrument ")] string name,
            [ExcelArgument(Description = "trade quantity ")] double[] quantities,
            [ExcelArgument(Description = "start date ")] object[] startdates,
            [ExcelArgument(Description = "end date ")] object[] enddates,
            [ExcelArgument(Description = "payCoeff ")] double[] payCoeff,
            [ExcelArgument(Description = "recCoeff ")] double[] recCoeff,
            [ExcelArgument(Description = "paySpread ")] double[] paySprd,
            [ExcelArgument(Description = "recSpread ")] double[] recSprd,
            [ExcelArgument(Description = "id of pay leg index ")] string payeridxid,
            [ExcelArgument(Description = "id of rec leg index ")] string recidxid,
            [ExcelArgument(Description = "id of pay leg discount curve ")] string paydiscountId,
            [ExcelArgument(Description = "id of rec leg discount curve ")] string recdiscountId,
            [ExcelArgument(Description = "trigger ")] object trigger)
        {
            if (ExcelUtil.CallFromWizard())
            {
                return("");
            }

            string callerAddress = "";

            callerAddress = ExcelUtil.getActiveCellAddress();

            try
            {
                if (startdates.Length != enddates.Length)
                {
                    return("size mismatch");
                }

                Xl.Range                 rng              = ExcelUtil.getActiveCellRange();
                CommodityIndexExt        payeridx         = OHRepository.Instance.getObject <CommodityIndexExt>(payeridxid);
                CommodityIndexExt        recidx           = OHRepository.Instance.getObject <CommodityIndexExt>(recidxid);
                YieldTermStructureHandle paydiscountcurve = OHRepository.Instance.getObject <YieldTermStructureHandle>(paydiscountId);
                YieldTermStructureHandle recdiscountcurve = OHRepository.Instance.getObject <YieldTermStructureHandle>(recdiscountId);
                Date refDate = paydiscountcurve.referenceDate();

                PricingPeriodExts pps = new PricingPeriodExts(startdates.Length);

                for (int i = 0; i < startdates.Length; i++)
                {
                    //EliteQuant.Date sd = Conversion.ConvertObject<EliteQuant.Date>((DateTime)startdates[i], "date");
                    //EliteQuant.Date ed = Conversion.ConvertObject<EliteQuant.Date>((DateTime)enddates[i], "date");
                    Date sd = new Date(Convert.ToInt32(startdates[i]));
                    Date ed = new Date(Convert.ToInt32(enddates[i]));

                    PricingPeriodExt pp = new PricingPeriodExt(sd, ed, sd, quantities[i], payCoeff[i], recCoeff[i], paySprd[i], recSprd[i]);
                    pps.Add(pp);
                }

                EnergyBasisSwapExt ebs = new EnergyBasisSwapExt(payeridx, recidx, pps, name, paydiscountcurve, recdiscountcurve, Frequency.Monthly, new NullCalendar());

                // Store the futures and return its id
                string id = "Swp@" + ObjectId;
                OHRepository.Instance.storeObject(id, ebs, 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!");
            }
        }