Beispiel #1
0
        public static IValuationFunction ToVf(TradeInfoBase tradeInfo)
        {
            IValuationFunction vf;

            // sean todo // tradeInfo.GetValuationFunction
            if (tradeInfo is BondInfoBase)
            {
                vf = new BondVf((BondInfoBase)tradeInfo);
            }
            else if (tradeInfo is VanillaOptionInfo)
            {
                vf = new VanillaOptionVf((VanillaOptionInfo)tradeInfo);
            }
            else if (tradeInfo is BarrierOptionInfo)
            {
                vf = new BarrierOptionVf((BarrierOptionInfo)tradeInfo);
            }
            else if (tradeInfo is BinaryOptionInfo)
            {
                vf = new BinaryOptionVf((BinaryOptionInfo)tradeInfo);
            }
            else if (tradeInfo is AsianOptionInfo)
            {
                vf = new AsianOptionVf((AsianOptionInfo)tradeInfo);
            }
            else if (tradeInfo is RainbowOptionInfo)
            {
                vf = new RainbowOptionVf((RainbowOptionInfo)tradeInfo);
            }
            else if (tradeInfo is SpreadOptionInfo)
            {
                vf = new SpreadOptionVf((SpreadOptionInfo)tradeInfo);
            }
            else if (tradeInfo is InterestRateSwapInfo)
            {
                vf = new InterestRateSwapVf((InterestRateSwapInfo)tradeInfo);
            }
            else if (tradeInfo is FixedLegInfo)
            {
                vf = new FixedLegVf((FixedLegInfo)tradeInfo);
            }
            else if (tradeInfo is FloatingLegInfo)
            {
                vf = new FloatingLegVf((FloatingLegInfo)tradeInfo);
            }
            else if (tradeInfo is BondFuturesInfo)
            {
                vf = new BondFuturesVf((BondFuturesInfo)tradeInfo);
            }
            else if (tradeInfo is LoanInfo)
            {
                vf = new LoanVf((LoanInfo)tradeInfo);
            }
            else if (tradeInfo is HoldingPeriodInfo)
            {
                vf = new HoldingPeriodVf((HoldingPeriodInfo)tradeInfo);
            }
            else if (tradeInfo is AbsWithRepurchaseInfo)
            {
                vf = new AbsWithRepurchaseVf((AbsWithRepurchaseInfo)tradeInfo);
            }
            else if (tradeInfo is ConvertibleBondInfo)
            {
                vf = new ConvertibleBondVf((ConvertibleBondInfo)tradeInfo);
            }
            else
            {
                throw new PricingLibraryException("Unknowy trade info type");
            }

            return(vf);
        }
        public void CommodityJinTaoBinaryEuropeanOptionTest()
        {
            var strike       = 3100.0;
            var spot         = 2900;
            var expiry       = new Date(2017, 12, 17);
            var valuationDay = "2017-12-01";
            var option       = new BinaryOption(
                new Date(2017, 12, 1),
                expiry,
                OptionExercise.European,
                OptionType.Call,
                strike,
                InstrumentType.CommodityFutures,
                BinaryOptionPayoffType.CashOrNothing,
                2,
                CalendarImpl.Get("chn"),
                new Act365(),
                CurrencyCode.CNY,
                CurrencyCode.CNY,
                new[] { expiry },
                new[] { expiry },
                notional: 1
                );

            var optionInfo = new BinaryOptionInfo(
                tradeId: "",
                valuationParameter: new OptionValuationParameters("Fr007", "diviCurve", "volSurf", "000300.SH"),
                underlyingTicker: "000300.SH",
                strike: strike,
                underlyingInstrumentType: "CommodityFutures",
                optionType: "Call",
                notional: 1,
                startDate: "2017-12-01",
                exerciseDates: "2017-12-17"
                )
            {
                CashOrNothingAmount             = 2,
                BinaryOptionPayoffType          = "CashOrNothing",
                BinaryOptionReplicationStrategy = "Down",
                ReplicationShiftSize            = 2,
            };



            var curveName     = "Fr007";
            var volName       = "volSurf";
            var diviCurveName = "diviCurve";
            var market        = GetMarketJinTao(valuationDay, rate: 0.04, vol: 0.4, dividendRate: 0, curveName: curveName, volName: volName, diviCurveName: diviCurveName, spot: spot);
            var volsurf       = market.GetData <VolSurfMktData>(volName).ToImpliedVolSurface(market.ReferenceDate);
            IMarketCondition marketCondition = new MarketCondition(
                x => x.ValuationDate.Value  = market.ReferenceDate,
                x => x.DiscountCurve.Value  = market.GetData <CurveData>(curveName).YieldCurve,
                x => x.DividendCurves.Value = new Dictionary <string, IYieldCurve> {
                { "", market.GetData <CurveData>(diviCurveName).YieldCurve }
            },
                x => x.SpotPrices.Value = new Dictionary <string, double> {
                { "", spot }
            },
                x => x.VolSurfaces.Value = new Dictionary <string, IVolSurface> {
                { "", volsurf }
            }
                );

            var engine = new AnalyticalBinaryEuropeanOptionEngine();
            var result = engine.Calculate(option, marketCondition, PricingRequest.All);

            Assert.AreEqual(0.401208951727572, result.Pv, 1e-8);
            Assert.AreEqual(0.00230806033816866, result.Delta, 1e-8);
            Assert.AreEqual(7.16979364767667E-06, result.Gamma, 1e-8);
            Assert.AreEqual(0.0105751548032081, result.Vega, 1e-8);
            Assert.AreEqual(-0.0149236357909549, result.Theta, 1e-8);
            Assert.AreEqual(-1.75872031726865E-06, result.Rho, 1e-8);



            var engine2 = new AnalyticalBinaryEuropeanOptionReplicationEngine(2.0, BinaryOptionReplicationStrategy.Down);
            var result2 = engine2.Calculate(option, marketCondition, PricingRequest.All);

            Assert.AreEqual(0.403373182249897, result2.Pv, 1e-7);
            Assert.AreEqual(0.00231550673674974, result2.Delta, 1e-7);
            Assert.AreEqual(7.16340764483903E-06, result2.Gamma, 1e-7);
            Assert.AreEqual(0.0105550810113932, result2.Vega, 1e-7);
            Assert.AreEqual(-0.0149004654797067, result2.Theta, 1e-7);
            Assert.AreEqual(-1.74927811613657E-06, result2.Rho, 1e-7);

            var vfResult = new BinaryOptionVf(optionInfo).ValueTrade(market, PricingRequest.Pv);

            Assert.AreEqual(vfResult.Pv, result2.Pv, 1e-7);
            Assert.AreEqual(result2.Pv > result.Pv, true);
        }