public void CheckZeroVolForward(AssetMarket assetMkt) { var zcCurve = assetMkt.RiskFreeDiscount; var market = new Market(new[] { zcCurve }, new[] { assetMkt }); var zeroVol = new MapRawDatas <DateOrDuration, double>(new[] { new DateOrDuration(assetMkt.RefDate) }, new[] { 0.0 }); var blackScholesDesc = new BlackScholesModelDescription(assetMkt.Asset.Name, zeroVol, true); var mcConfig = new MonteCarloConfig(1, RandomGenerators.GaussianSobol(SobolDirection.Kuo3)); var blackScholesModel = ModelFactory.Instance.Build(blackScholesDesc, market); var fwdDates = new[] { Duration.Month, 6 * Duration.Month, Duration.Year, 2 * Duration.Year, 5 * Duration.Year } .Map(d => assetMkt.RefDate + d); IProduct fwdLeg = ForwardLeg(fwdDates); PriceResult priceResult = (PriceResult)McPricer.WithDetails(mcConfig).Price(fwdLeg, blackScholesModel, market); double[] fwds = priceResult.Details.Map(kv => kv.Item3.Value); var assetFwdCurve = assetMkt.Forward(); double[] refFwds = fwdDates.Map(d => assetFwdCurve.Fwd(d) * zcCurve.Zc(d)); foreach (var i in Enumerable.Range(0, fwdDates.Length)) { var err = Math.Abs(fwds[i] / refFwds[i] - 1.0); Assert.LessOrEqual(err, 20.0 * DoubleUtils.MachineEpsilon); } }
public override IModelDescription Calibrate(BlackScholesModelCalibDesc bsDesc, Market market) { AssetMarket assetMkt = market.AssetMarketFromName(bsDesc.Asset); var volSurface = assetMkt.VolSurface(); var forwardCurve = assetMkt.Forward(); var optionPricer = BlackScholesWithDividendOption.Build(assetMkt.Spot, assetMkt.Dividends, assetMkt.RiskFreeDiscount, assetMkt.Time); var calibMaturities = bsDesc.CalibrationMaturities.Map(d => d.ToDate(assetMkt.RefDate)); var calibStrikes = bsDesc.CalibrationStrikes; var calibDates = assetMkt.Time[calibMaturities]; double[] targetPrices = new double[calibDates.Length]; double[] optionTypes = new double[calibDates.Length]; for (int i = 0; i < calibMaturities.Length; i++) { var targetVol = volSurface.Volatility(calibDates[i], calibStrikes[i]); var optionType = (calibStrikes[i] > forwardCurve.Fwd(calibMaturities[i])) ? 1.0 : -1.0; targetPrices[i] = optionPricer.Price(calibDates[i], calibStrikes[i], targetVol, optionType); optionTypes[i] = optionType; } var calibratedVols = optionPricer.CalibrateVol(calibDates, targetPrices, bsDesc.CalibrationStrikes, optionTypes); var sigma = new MapRawDatas <DateOrDuration, double>(bsDesc.CalibrationMaturities, calibratedVols); return(new BlackScholesModelDescription(bsDesc.Asset, sigma, bsDesc.WithDivs)); }
public Bergomi2FModelDescription(string asset, bool withDivs, MapRawDatas <DateOrDuration, double> sigma, double k1, double k2, double theta, double nu, double rhoXy, double rhoSx, double rhoSy) { Asset = asset; WithDivs = withDivs; Sigma = sigma; K1 = k1; K2 = k2; Theta = theta; Nu = nu; RhoXY = rhoXy; RhoSX = rhoSx; RhoSY = rhoSy; Asset = asset; }
public ICalibrationDescription Build(object[,] bag) { var assetName = bag.ProcessScalarString("Asset"); var withDivs = !bag.Has("WithDivs") || bag.ProcessScalarBoolean("WithDivs"); var calibDatas = bag.ProcessTimeMatrixDatas("CalibDate"); if (calibDatas.HasCol("Sigma")) { var sigmaValues = calibDatas.GetColFromLabel("Sigma"); var sigma = new MapRawDatas <DateOrDuration, double>(calibDatas.RowLabels, sigmaValues); var bsDescription = new BlackScholesModelDescription(assetName, sigma, withDivs); return(new ExplicitCalibration <BlackScholesModelDescription>(bsDescription)); } var calibStrikes = calibDatas.GetColFromLabel("Strike"); return(new BlackScholesModelCalibDesc(assetName, withDivs, calibDatas.RowLabels, calibStrikes)); }
private static RrFunction BuildXi(MapRawDatas <DateOrDuration, double> sigma, ITimeMeasure time) { var matVars = EnumerableUtils.For(0, sigma.Pillars.Length, i => { var mat = time[sigma.Pillars[i].ToDate(time.RefDate)]; var variance = sigma.Values[i] * sigma.Values[i] * mat; return(new { Mat = mat, Variance = variance }); }).OrderBy(t => t.Mat).ToArray(); if (!DoubleUtils.EqualZero(matVars.First().Mat)) { matVars = matVars.Concat(new[] { new { Mat = 0.0, Variance = 0.0 } }) .OrderBy(t => t.Mat).ToArray(); } var varianceFunc = RrFunctions.LinearInterpolation(matVars.Map(t => t.Mat), matVars.Map(t => t.Variance), 0.0, double.NaN); return(varianceFunc.Derivative()); }
public ICalibrationDescription Build(object[,] bag) { string assetName = bag.ProcessScalarString("Asset"); bool withDivs = !bag.Has("WithDivs") || bag.ProcessScalarBoolean("WithDivs"); var calibDatas = bag.ProcessTimeMatrixDatas("Date"); var sigmaValues = calibDatas.GetColFromLabel("Sigma"); var sigma = new MapRawDatas <DateOrDuration, double>(calibDatas.RowLabels, sigmaValues); double k1 = bag.ProcessScalarDouble("K1"); double k2 = bag.ProcessScalarDouble("K2"); double theta = bag.ProcessScalarDouble("Theta"); double nu = bag.ProcessScalarDouble("Nu"); double rhoXY = bag.ProcessScalarDouble("RhoXY"); double rhoSX = bag.ProcessScalarDouble("RhoSX"); double rhoSY = bag.ProcessScalarDouble("RhoSY"); Bergomi2FModelDescription b2FDescription = new Bergomi2FModelDescription(assetName, withDivs, sigma, k1, k2, theta, nu, rhoXY, rhoSX, rhoSY); return(new ExplicitCalibration <Bergomi2FModelDescription>(b2FDescription)); }
public static RrFunction ToStepFunction(this MapRawDatas <DateOrDuration, double> rawDatasFunc, ITimeMeasure time) { var abscissae = rawDatasFunc.Pillars.Map(d => time[d.ToDate(time.RefDate)]); return(new StepFunction(abscissae, rawDatasFunc.Values, rawDatasFunc.Values.First())); }
public Hw1ModelDescription(Currency currency, double meanReversion, MapRawDatas <DateOrDuration, double> sigma) { Sigma = sigma; MeanReversion = meanReversion; Currency = currency; }
public BlackScholesModelDescription(string asset, MapRawDatas <DateOrDuration, double> sigma, bool withDivs) { Sigma = sigma; WithDivs = withDivs; Asset = asset; }