public void MoneynessDeltaTest() { var startDate = new Date(2018, 03, 02); var maturityDate = new Date(2018, 04, 27); var call = new VanillaOption(startDate, maturityDate, OptionExercise.American, OptionType.Call, 1.05, InstrumentType.Stock, CalendarImpl.Get("chn"), new Act365(), CurrencyCode.CNY, CurrencyCode.CNY, new[] { maturityDate }, new[] { maturityDate }, 12, null, null, 0, true, 8000); #region construct market var historiclIndexRates = HistoricalDataLoadHelper.HistoricalIndexRates; var curveConvention = new CurveConvention("fr007CurveConvention", "CNY", "ModifiedFollowing", "Chn", "Act365", "Continuous", "CubicHermiteMonotic"); var fr007CurveName = "Fr007"; var fr007RateDefinition = new[] { new RateMktData("1D", 0.05, "Spot", "None", fr007CurveName), new RateMktData("5Y", 0.05, "Spot", "None", fr007CurveName), }; var dividendCurveName = "Dividend"; var dividendRateDefinition = new[] { new RateMktData("1D", 0, "Spot", "None", dividendCurveName), new RateMktData("5Y", 0, "Spot", "None", dividendCurveName), }; var curveDefinition = new[] { new InstrumentCurveDefinition(fr007CurveName, curveConvention, fr007RateDefinition, "SpotCurve"), new InstrumentCurveDefinition(dividendCurveName, curveConvention, dividendRateDefinition, "SpotCurve"), }; var volSurf = new[] { new VolSurfMktData("VolSurf", 0.3), }; var marketInfo = new MarketInfo("tmpMarket", "2018-03-02", curveDefinition, historiclIndexRates, null, null, volSurf); QdpMarket qdpMarket; MarketFunctions.BuildMarket(marketInfo, out qdpMarket); var valuationDate = new Date(2018, 3, 2); //flat vol surface var surface1 = qdpMarket.GetData <VolSurfMktData>("VolSurf").ToImpliedVolSurface(valuationDate); // market with flat vol surface var market = new MarketCondition( x => x.ValuationDate.Value = valuationDate, x => x.DiscountCurve.Value = qdpMarket.GetData <CurveData>("Fr007").YieldCurve, x => x.DividendCurves.Value = new Dictionary <string, IYieldCurve> { { "", qdpMarket.GetData <CurveData>("Dividend").YieldCurve } }, x => x.VolSurfaces.Value = new Dictionary <string, IVolSurface> { { "", surface1 } }, x => x.SpotPrices.Value = new Dictionary <string, double> { { "", 8000 } } ); //a real vol surface, same as stock 600000 of 2018-03-02 in OTC system var maturities = new Date[] { (new Term("1W")).Next(startDate), (new Term("2W")).Next(startDate), (new Term("1M")).Next(startDate) }; var strikes = new double[] { 0.9, 0.95, 1.0, 1.05, 1.1 }; var vols = new double[3, 5]; for (var i = 0; i < vols.GetLength(0); ++i) { for (var j = 0; j < vols.GetLength(1); ++j) { vols[i, j] = 0.3; } } vols[2, 2] = 0.4; var surface2 = new ImpliedVolSurface(valuationDate, maturities, strikes, vols, Interpolation2D.BiLinear); // market with flat vol surface var market2 = new MarketCondition( x => x.ValuationDate.Value = valuationDate, x => x.DiscountCurve.Value = qdpMarket.GetData <CurveData>("Fr007").YieldCurve, x => x.DividendCurves.Value = new Dictionary <string, IYieldCurve> { { "", qdpMarket.GetData <CurveData>("Dividend").YieldCurve } }, x => x.VolSurfaces.Value = new Dictionary <string, IVolSurface> { { "", surface2 } }, x => x.SpotPrices.Value = new Dictionary <string, double> { { "", 8000 } } ); #endregion var engine = new AnalyticalVanillaEuropeanOptionEngine(); //result of a flat vol surface of 0.3, which is the same as pricing result in OTC-926 var result = engine.Calculate(call, market, PricingRequest.All); //result of real vol surface, which is the same as scenario analysis in OTC-926 var result2 = engine.Calculate(call, market2, PricingRequest.All); }
public static VolSurfMktData ToVolSurfMktData(this ImpliedVolSurface volSurface, string id) { return(new VolSurfMktData(id, volSurface.RowGrid, volSurface.ColGrid, volSurface.ValueOnGrids, volSurface.getInterpolationMethod(), volSurface.getVolSurfaceType())); }