public EnergyFutureExt(int buySell, PricingPeriodExt PricingPeriodExt, double tradePrice, CommodityIndexExt index, string commodityName, YieldTermStructureHandle discountTermStructure) : this(NQuantLibcPINVOKE.new_EnergyFutureExt(buySell, PricingPeriodExt.getCPtr(PricingPeriodExt), tradePrice, CommodityIndexExt.getCPtr(index), commodityName, YieldTermStructureHandle.getCPtr(discountTermStructure)), true)
 {
     if (NQuantLibcPINVOKE.SWIGPendingException.Pending)
     {
         throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve();
     }
 }
        public PricingPeriodExt pricingPeriod()
        {
            PricingPeriodExt ret = new PricingPeriodExt(NQuantLibcPINVOKE.EnergyFutureExt_pricingPeriod(swigCPtr), true);

            if (NQuantLibcPINVOKE.SWIGPendingException.Pending)
            {
                throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve();
            }
            return(ret);
        }
Esempio n. 3
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!");
            }
        }
 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(PricingPeriodExt obj)
 {
     return((obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr);
 }
Esempio n. 5
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. 6
0
        public static object eqInstDisplayEnergySwap(
            [ExcelArgument(Description = "id of energy ")] string ObjectId,
            [ExcelArgument(Description = "trigger ")] object trigger)
        {
            if (ExcelUtil.CallFromWizard())
            {
                return("");
            }

            string callerAddress = "";

            callerAddress = ExcelUtil.getActiveCellAddress();

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

                EnergyCommodityExt inst = OHRepository.Instance.getObject <EnergyCommodityExt>(ObjectId);
                if (inst.GetType() == typeof(EnergyFutureExt))
                {
                    PricingPeriodExt pp = (inst as EnergyFutureExt).pricingPeriod();

                    object[,] ret = new object[2, 10];
                    ret[0, 0]     = "PayDate"; ret[0, 1] = "Quantity"; ret[0, 2] = "PayCoeff"; ret[0, 3] = "RecCoeff";
                    ret[0, 4]     = "PaySprd"; ret[0, 5] = "RecSprd";
                    ret[0, 6]     = "PayDelta"; ret[0, 7] = "DiscountedPayDelta";
                    ret[0, 8]     = "RecDelta"; ret[0, 9] = "DiscountedRecDelta";

                    ret[1, 0] = pp.paymentDate().serialNumber();
                    ret[1, 1] = pp.quantity();
                    ret[1, 2] = pp.payCoeff();
                    ret[1, 3] = pp.recCoeff();
                    ret[1, 4] = pp.paySpread();
                    ret[1, 5] = pp.recSpread();
                    ret[1, 6] = pp.getuPayDelta();
                    ret[1, 7] = pp.getdPayDelta();
                    ret[1, 8] = pp.getuRecDelta();
                    ret[1, 9] = pp.getdRecDelta();

                    return(ret);
                }
                else
                {
                    double            npv = inst.NPV();
                    PricingPeriodExts pps = (inst as EnergySwapExt).pricingPeriods();

                    object[,] ret = new object[pps.Count + 1, 10];

                    ret[0, 0] = "PayDate"; ret[0, 1] = "Quantity"; ret[0, 2] = "PayCoeff"; ret[0, 3] = "RecCoeff";
                    ret[0, 4] = "PaySprd"; ret[0, 5] = "RecSprd";
                    ret[0, 6] = "PayDelta"; ret[0, 7] = "DiscountedPayDelta";
                    ret[0, 8] = "RecDelta"; ret[0, 9] = "DiscountedRecDelta";
                    for (int i = 0; i < pps.Count; i++)
                    {
                        ret[i + 1, 0] = pps[i].paymentDate().serialNumber();
                        ret[i + 1, 1] = pps[i].quantity();
                        ret[i + 1, 2] = pps[i].payCoeff();
                        ret[i + 1, 3] = pps[i].recCoeff();
                        ret[i + 1, 4] = pps[i].paySpread();
                        ret[i + 1, 5] = pps[i].recSpread();
                        ret[i + 1, 6] = pps[i].getuPayDelta();
                        ret[i + 1, 7] = pps[i].getdPayDelta();
                        ret[i + 1, 8] = pps[i].getuRecDelta();
                        ret[i + 1, 9] = pps[i].getdRecDelta();
                    }

                    return(ret);
                }
            }
            catch (Exception e)
            {
                ExcelUtil.logError(callerAddress, System.Reflection.MethodInfo.GetCurrentMethod().Name.ToString(), e.Message);
                return("#EQ_ERR!");
            }
        }
Esempio n. 7
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!");
            }
        }