public OrnsteinUhlenbeck(double meanReversion, RrFunction drift, RrFunction volatility, double value0) { Value0 = value0; Volatility = volatility; Drift = drift; MeanReversion = meanReversion; }
public Hw1ModelZcRepresentation(Hw1Model hw1Model) : base(hw1Model.Currency) { time = hw1Model.Time; meanReversion = hw1Model.MeanReversion; driftTerm = hw1Model.DriftTerm(); }
public void ProbaMeasure(double lambda, RrFunction sigma, Duration probaMaturity, Duration simulationMaturity, int quadratureNbPoints, double precision) { var refDate = DateTime.Parse("07/06/2009"); var hw1 = new Hw1Model(TimeMeasure.Act365(refDate), Currency.Eur, lambda, sigma); var probaMeasure = new PaymentInfo(hw1.Currency, refDate + probaMaturity); var t = refDate + simulationMaturity; var hw1PathGen = new Hw1ModelPathGeneratorFactory().Build(hw1, null, probaMeasure, new[] { t }); var brownianBridge = BrownianBridge.Create(hw1PathGen.AllSimulatedDates); var hw1Zc = new Hw1ModelZcRepresentation(hw1); var numeraireZc = hw1Zc.Zc(t, probaMeasure.Date, 1.0); Assert.AreEqual(hw1PathGen.AllSimulatedDates.Length, 1); double[] x, w; GaussHermite.GetQuadrature(quadratureNbPoints, out x, out w); double flow = 0.0; for (int i = 0; i < x.Length; i++) { var dw = brownianBridge.PathIncrements(new[] { x[i] }, 1); var ornstein = hw1PathGen.Path(dw).GetProcessValue(0); flow += w[i] * 1.0 / numeraireZc.Eval(ornstein); } var error = Math.Abs(flow - 1.0); Assert.LessOrEqual(error, precision); }
public Hw1Model(ITimeMeasure time, Currency currency, double meanReversion, RrFunction sigma) { Sigma = sigma; MeanReversion = meanReversion; Currency = currency; Time = time; }
public AffineDivCurveUtils(DividendQuote[] dividends, DiscountCurve discountCurve, ITimeMeasure time) { Contract.Requires(EnumerableUtils.IsSorted(dividends.Select(div => div.Date))); if (dividends.Length > 0) { double[] divDates = dividends.Map(div => time[div.Date]); double[] spotYieldGrowths = dividends.Scan(1.0, (prev, div) => prev * (1.0 - div.Yield)); var spotYieldGrowth = new StepFunction(divDates, spotYieldGrowths, 1.0); assetGrowth = t => spotYieldGrowth.Eval(t) / discountCurve.Zc(t); double[] discountedCashs = dividends.Map(div => div.Cash / assetGrowth(time[div.Date])); double[] cashBpvs = discountedCashs.Scan(0.0, (prev, c) => prev + c); cashDivBpv = new StepFunction(divDates, cashBpvs, 0.0); cashBpvIntegral = cashDivBpv.Integral(0.0); double[] squareTimeWeightedCashs = discountedCashs.ZipWith(divDates, (c, t) => c * t * t); squareTimeWeightedCash = new StepFunction(divDates, squareTimeWeightedCashs, 0.0); } else { assetGrowth = t => 1.0 / discountCurve.Zc(t); cashDivBpv = new StepFunction(new[] { 0.0 }, new[] { 0.0 }, double.NaN); cashBpvIntegral = RrFunctions.Zero; squareTimeWeightedCash = new StepFunction(new[] { 0.0 }, new[] { 0.0 }, double.NaN); } }
/// <summary> /// Return local variance at date t given by formula : /// dv/dt /// local variance = ------------------------------------------------------------------------------------ /// (y * (dv/dy) / (2 * v) - 1)^2 + 1/2 * (d^2 v/dy^2) - 1/4 * (1/4 + 1/v) * (dv/dy)^2 /// </summary> /// <param name="t"></param> /// <returns></returns> public RrFunction TimeSlice(double t) { var stepIndex = maturityStepSearcher.LocateLeftIndex(t); RrFunction dVdT = Numerator(t, stepIndex); var denominator = Denominator(t, stepIndex); var localVar = dVdT / denominator; return(localVar); }
public Bergomi2FModel(AssetId asset, DiscreteLocalDividend[] dividends, ITimeMeasure time, RrFunction xi, double k1, double k2, double theta, double nu, double rhoXy, double rhoSx, double rhoSy) : base(asset, dividends, time) { Xi = xi; K1 = k1; K2 = k2; Theta = theta; Nu = nu; RhoXY = rhoXy; RhoSX = rhoSx; RhoSY = rhoSy; }
private static Func <double, double> StepLocalVol(DateTime startDate, DateTime endDate, LocalVolatilityModel model) { var time = model.Time; double start = time[startDate]; double end = time[endDate]; VolatilitySurface volSurface = model.VolSurface; RrFunction stepLocalVariance = volSurface.LocalVariance.TimeAveragedSlice(start, end); var moneyness = model.Moneyness.Moneyness(start); Func <double, double> localVol = logSpot => Math.Sqrt(stepLocalVariance.Eval(moneyness(Math.Exp(logSpot)))); var gridLocalVol = LocalVolDiscretization(localVol, volSurface, 0.5 * (start + end)); return(gridLocalVol.Eval); }
public override RrFunction Mult(RrFunction other) { var cst = other as ConstantRrFunction; if (cst != null) { return(Mult(this, cst)); } var spline = other as SplineInterpoler; if (spline != null) { return(Mult(this, spline)); } return(base.Mult(other)); }
private LocalVariance(double[] maturities, RrFunction[] vs, RrFunction[] dVdYs, RrFunction[] d2Vd2Ys, RrFunction[] dVdTs) { Contract.Requires(maturities.All(t => t > 0.0)); this.maturities = maturities; this.vs = vs; this.dVdYs = dVdYs; this.d2Vd2Ys = d2Vd2Ys; this.dVdTs = dVdTs; maturityStepSearcher = new StepSearcher(maturities); pillarStepIntegrals = new RrFunction[maturities.Length - 1]; // sigma^2 // short local variance = ------------------------------------------- // (y * (dsigma^2/dy) / (2 * sigma^2) - 1)^2 var sigma2 = vs[0] / maturities[0]; shortLocalVar = 0.5 * m * sigma2.Derivative() / sigma2 - 1.0; shortLocalVar = sigma2 / (shortLocalVar * shortLocalVar); }
public static RrFunction IntegratedCovariance(RrFunction instantCovariance, double meanReversion1, double meanReversion2, double startDate = 0.0) { var integratedExpCov = (instantCovariance * RrFunctions.Exp(meanReversion1 + meanReversion2)).Integral(startDate); return(integratedExpCov * RrFunctions.Exp(-(meanReversion1 + meanReversion2))); }
public static RrFunction IntegratedVariance(RrFunction instantVolatility, double meanReversion, double startDate = 0.0) { return(IntegratedCovariance(instantVolatility * instantVolatility, meanReversion, meanReversion, startDate)); }
public static RrFunction IntegratedDrift(RrFunction instantDrift, double meanReversion, double startDate = 0.0) { var integratedExpDrift = (instantDrift * RrFunctions.Exp(meanReversion)).Integral(startDate); return(integratedExpDrift * RrFunctions.Exp(-meanReversion)); }
public BlackScholesModel(ITimeMeasure time, AssetId asset, RrFunction sigma, DiscreteLocalDividend[] dividends) : base(asset, dividends, time) { Sigma = sigma; }
public DiscountCurveFromRate(FinancingId financing, ITimeMeasure time, RrFunction zcRate) : base(time.RefDate, financing) { this.time = time; this.zcRate = zcRate; }