示例#1
0
 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(MCEuropeanBasketEngine obj) {
   return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
 }
示例#2
0
 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(MCEuropeanBasketEngine obj)
 {
     return((obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr);
 }
示例#3
0
        public static string eqInstSpreadOptionMonteCarlo(
            [ExcelArgument(Description = "id of option to be constructed ")] string ObjectId,
            [ExcelArgument(Description = "Option type (Call/Put) ")] string optype,
            [ExcelArgument(Description = "Spot price leg 1")] double spot1,
            [ExcelArgument(Description = "Spot price leg 2")] double spot2,
            [ExcelArgument(Description = "Strike price ")] double stirkeprice,
            [ExcelArgument(Description = "Expiry Date ")] DateTime exdate,
            [ExcelArgument(Description = "Risk free rate ")] double riskfreerate,
            [ExcelArgument(Description = "Black-Scholes Vol for leg 1 ")] double vol1,
            [ExcelArgument(Description = "Black-Scholes Vol for leg 2 ")] double vol2,
            [ExcelArgument(Description = "correlation between leg 1 and leg 2 ")] double corr,
            [ExcelArgument(Description = "DayCounter ")] string daycounter,
            [ExcelArgument(Description = "Calendar ")] string calendar,
            [ExcelArgument(Description = "Pseudorandom (pr) or lowdiscrepancy (ld) ")] string traits,
            [ExcelArgument(Description = "trigger ")] object trigger)
        {
            if (ExcelUtil.CallFromWizard())
            {
                return("");
            }

            string callerAddress = "";

            callerAddress = ExcelUtil.getActiveCellAddress();

            try
            {
                if (exdate == DateTime.MinValue)
                {
                    throw new Exception("Date must not be empty. ");
                }

                if (ExcelUtil.isNull(daycounter))
                {
                    daycounter = "ACTUAL365";
                }
                if (ExcelUtil.isNull(calendar))
                {
                    calendar = "NYC";
                }
                if (ExcelUtil.isNull(traits))
                {
                    traits = "pr";
                }

                Option.Type optiontype;
                if (optype.ToUpper() == "CALL")
                {
                    optiontype = Option.Type.Call;
                }
                else if (optype.ToUpper() == "PUT")
                {
                    optiontype = Option.Type.Put;
                }
                else
                {
                    throw new Exception("Unknow option type");
                }

                EliteQuant.Calendar   cal          = EliteQuant.EQConverter.ConvertObject <EliteQuant.Calendar>(calendar);
                EliteQuant.DayCounter dc           = EliteQuant.EQConverter.ConvertObject <EliteQuant.DayCounter>(daycounter);
                EliteQuant.Date       maturitydate = EliteQuant.EQConverter.ConvertObject <EliteQuant.Date>(exdate);

                EliteQuant.Date today          = EliteQuant.Settings.instance().getEvaluationDate();
                EliteQuant.Date settlementdate = today;           // T+2
                if (maturitydate.serialNumber() <= today.serialNumber())
                {
                    throw new Exception("Option already expired.");
                }


                YieldTermStructureHandle rTSH = new YieldTermStructureHandle(
                    new FlatForward(settlementdate, riskfreerate, dc));
                BlackVolTermStructureHandle flatVolTSH1 = new BlackVolTermStructureHandle(
                    new BlackConstantVol(settlementdate, cal, vol1, dc));
                BlackVolTermStructureHandle flatVolTSH2 = new BlackVolTermStructureHandle(
                    new BlackConstantVol(settlementdate, cal, vol2, dc));

                Quote       qh1 = new SimpleQuote(spot1);
                Quote       qh2 = new SimpleQuote(spot2);
                QuoteHandle s1  = new QuoteHandle(qh1);
                QuoteHandle s2  = new QuoteHandle(qh2);

                BlackProcess p1 = new BlackProcess(s1, rTSH, flatVolTSH1);
                BlackProcess p2 = new BlackProcess(s2, rTSH, flatVolTSH2);

                StochasticProcessVector spv = new StochasticProcessVector(2);
                spv.Add(p1);
                spv.Add(p2);

                Matrix corrmtrx = new Matrix(2, 2);
                corrmtrx.set(0, 0, 1.0); corrmtrx.set(1, 1, 1.0);
                corrmtrx.set(0, 1, corr); corrmtrx.set(1, 0, corr);
                StochasticProcessArray spa = new StochasticProcessArray(spv, corrmtrx);

                PricingEngine engine = new MCEuropeanBasketEngine(spa, traits, 100, 1, false, true, 5000, 1e-6);

                Payoff payoff1 = new PlainVanillaPayoff(optiontype, stirkeprice);
                Payoff payoff2 = new SpreadBasketPayoff(payoff1);

                Exercise exercise = new EuropeanExercise(maturitydate);

                BasketOption bo = new BasketOption(payoff2, exercise);

                bo.setPricingEngine(engine);

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