public InterpolatedSmileSection(double timeToExpiry, List <double> strikes, List <double> stdDevs, double atmLevel, Interpolator interpolator = default(Interpolator), DayCounter dc = null, //Actual365Fixed(), VolatilityType type = VolatilityType.ShiftedLognormal, double shift = 0.0) : base(timeToExpiry, dc ?? new Actual365Fixed(), type, shift) { exerciseTimeSquareRoot_ = Math.Sqrt(exerciseTime()); strikes_ = strikes; stdDevHandles_ = new InitializedList <Handle <Quote> >(stdDevs.Count); vols_ = new InitializedList <double>(stdDevs.Count); // fill dummy handles to allow generic handle-based // computations later on for (int i = 0; i < stdDevs.Count; ++i) { stdDevHandles_[i] = new Handle <Quote>(new SimpleQuote(stdDevs[i])); } atmLevel_ = new Handle <Quote>(new SimpleQuote(atmLevel)); // check strikes!!!!!!!!!!!!!!!!!!!! if (interpolator == null) { interpolator = FastActivator <Interpolator> .Create(); } interpolation_ = interpolator.interpolate(strikes_, strikes_.Count, vols_); }
public IterativeBootstrap() { ts_ = FastActivator <T> .Create(); initialized_ = false; validCurve_ = false; }
public InterpolatedSmileSection(Date d, List <double> strikes, List <Handle <Quote> > stdDevHandles, Handle <Quote> atmLevel, DayCounter dc = null, //Actual365Fixed(), Interpolator interpolator = default(Interpolator), Date referenceDate = null, VolatilityType type = VolatilityType.ShiftedLognormal, double shift = 0.0) : base(d, dc ?? new Actual365Fixed(), referenceDate, type, shift) { exerciseTimeSquareRoot_ = Math.Sqrt(exerciseTime()); strikes_ = strikes; stdDevHandles_ = stdDevHandles; atmLevel_ = atmLevel; vols_ = new InitializedList <double>(stdDevHandles.Count); for (int i = 0; i < stdDevHandles_.Count; ++i) { stdDevHandles_[i].registerWith(update); } atmLevel_.registerWith(update); // check strikes!!!!!!!!!!!!!!!!!!!! if (interpolator == null) { interpolator = FastActivator <Interpolator> .Create(); } interpolation_ = interpolator.interpolate(strikes_, strikes_.Count, vols_); }
public InitializedList(int size) : base(size) { for (int i = 0; i < this.Capacity; i++) { this.Add(default(T) == null ? FastActivator <T> .Create() : default(T)); } }
public XABRCoeffHolder(double t, double forward, List <double?> _params, List <bool> paramIsFixed, List <double?> addParams) { t_ = t; forward_ = forward; params_ = _params; paramIsFixed_ = new InitializedList <bool>(paramIsFixed.Count, false); addParams_ = addParams; weights_ = new List <double>(); error_ = null; maxError_ = null; XABREndCriteria_ = EndCriteria.Type.None; model_ = FastActivator <Model> .Create(); Utils.QL_REQUIRE(t > 0.0, () => "expiry time must be positive: " + t + " not allowed"); Utils.QL_REQUIRE(_params.Count == model_.dimension(), () => "wrong number of parameters (" + _params.Count + "), should be " + model_.dimension()); Utils.QL_REQUIRE(paramIsFixed.Count == model_.dimension(), () => "wrong number of fixed parameters flags (" + paramIsFixed.Count + "), should be " + model_.dimension()); for (int i = 0; i < _params.Count; ++i) { if (_params[i] != null) { paramIsFixed_[i] = paramIsFixed[i]; } } model_.defaultValues(params_, paramIsFixed_, forward_, t_, addParams_); updateModelInstance(); }
public InterpolatedPiecewiseZeroSpreadedTermStructure(Handle <YieldTermStructure> h, List <Handle <Quote> > spreads, List <Date> dates, Compounding compounding = Compounding.Continuous, Frequency frequency = Frequency.NoFrequency, DayCounter dc = default(DayCounter), Interpolator factory = default(Interpolator)) { originalCurve_ = h; spreads_ = spreads; dates_ = dates; times_ = new InitializedList <double>(dates.Count); spreadValues_ = new InitializedList <double>(dates.Count); compounding_ = compounding; frequency_ = frequency; dc_ = dc ?? new DayCounter(); factory_ = factory ?? FastActivator <Interpolator> .Create(); Utils.QL_REQUIRE(!spreads_.empty(), () => "no spreads given"); Utils.QL_REQUIRE(spreads_.Count == dates_.Count, () => "spread and date vector have different sizes"); originalCurve_.registerWith(update); for (int i = 0; i < spreads_.Count; i++) { spreads_[i].registerWith(update); } if (!originalCurve_.empty()) { updateInterpolation(); } }
protected override double integrate(Func <double, double> f, double a, double b) { // start from the coarsest trapezoid... int N = 1; double I = (f(a) + f(b)) * (b - a) / 2.0, newI; // ...and refine it int i = 1; IntegrationPolicy ip = FastActivator <IntegrationPolicy> .Create(); do { newI = ip.integrate(f, a, b, I, N); N *= ip.nbEvalutions(); // good enough? Also, don't run away immediately if (Math.Abs(I - newI) <= absoluteAccuracy() && i > 5) { // ok, exit return(newI); } // oh well. Another step. I = newI; i++; } while (i < maxEvaluations()); Utils.QL_FAIL("max number of iterations reached"); return(0); }
public InterpolatedZeroInflationCurve(Date referenceDate, Calendar calendar, DayCounter dayCounter, Period lag, Frequency frequency, bool indexIsInterpolated, Handle <YieldTermStructure> yTS, List <Date> dates, List <double> rates, Interpolator interpolator = default(Interpolator)) : base(referenceDate, calendar, dayCounter, rates[0], lag, frequency, indexIsInterpolated, yTS) { times_ = new List <double>(); dates_ = dates; data_ = rates; interpolator_ = interpolator ?? FastActivator <Interpolator> .Create(); Utils.QL_REQUIRE(dates_.Count > 1, () => "too few dates: " + dates_.Count); // check that the data starts from the beginning, // i.e. referenceDate - lag, at least must be in the relevant // period KeyValuePair <Date, Date> lim = Utils.inflationPeriod(yTS.link.referenceDate() - this.observationLag(), frequency); Utils.QL_REQUIRE(lim.Key <= dates_[0] && dates_[0] <= lim.Value, () => "first data date is not in base period, date: " + dates_[0] + " not within [" + lim.Key + "," + lim.Value + "]"); // by convention, if the index is not interpolated we pull all the dates // back to the start of their inflationPeriods // otherwise the time calculations will be inconsistent if (!indexIsInterpolated_) { for (int i = 0; i < dates_.Count; i++) { dates_[i] = Utils.inflationPeriod(dates_[i], frequency).Key; } } Utils.QL_REQUIRE(this.data_.Count == dates_.Count, () => "indices/dates count mismatch: " + this.data_.Count + " vs " + dates_.Count); this.times_ = new InitializedList <double>(dates_.Count); this.times_[0] = timeFromReference(dates_[0]); for (int i = 1; i < dates_.Count; i++) { Utils.QL_REQUIRE(dates_[i] > dates_[i - 1], () => "dates not sorted"); // but must be greater than -1 Utils.QL_REQUIRE(this.data_[i] > -1.0, () => "zero inflation data < -100 %"); // this can be negative this.times_[i] = timeFromReference(dates_[i]); Utils.QL_REQUIRE(!Utils.close(this.times_[i], this.times_[i - 1]), () => "two dates correspond to the same time " + "under this curve's day count convention"); } this.interpolation_ = this.interpolator_.interpolate(times_, times_.Count, data_); this.interpolation_.update(); }
public void updateModelInstance() { // forward might have changed Utils.QL_REQUIRE(forward_ > 0.0, () => "forward must be positive: " + forward_ + " not allowed"); modelInstance_ = FastActivator <Model> .Create().instance(t_, forward_, params_); model_ = FastActivator <Model> .Create(); }
public InterpolatedForwardCurve(DayCounter dayCounter, List <Handle <Quote> > jumps = null, List <Date> jumpDates = null, Interpolator interpolator = default(Interpolator)) : base(dayCounter, jumps, jumpDates) { interpolator_ = interpolator ?? FastActivator <Interpolator> .Create(); }
public ParallelEvolver(List <IOperator> L, BoundaryConditionSet bcs) { evolvers_ = new List <IMixedScheme>(L.Count); for (int i = 0; i < L.Count; i++) { evolvers_.Add(FastActivator <Evolver> .Create().factory(L[i], bcs[i])); } }
public MakeMCDiscreteGeometricAPEngine <RNG, S> withTolerance(double tolerance) { Utils.QL_REQUIRE(samples_ == null, () => "number of samples already set"); Utils.QL_REQUIRE(FastActivator <RNG> .Create().allowsErrorEstimate != 0, () => "chosen random generator policy " + "does not allow an error estimate"); tolerance_ = tolerance; return(this); }
public MakeMCHestonHullWhiteEngine <RNG, S> withAbsoluteTolerance(double tolerance) { Utils.QL_REQUIRE(samples_ == null, () => "number of samples already set"); Utils.QL_REQUIRE(FastActivator <RNG> .Create().allowsErrorEstimate != 0, () => "chosen random generator policy does not allow an error estimate"); tolerance_ = tolerance; return(this); }
public FiniteDifferenceModel(object L, object bcs, List <double> stoppingTimes) { evolver_ = (Evolver)FastActivator <Evolver> .Create().factory(L, bcs); stoppingTimes_ = stoppingTimes; stoppingTimes_.Sort(); stoppingTimes_ = stoppingTimes_.Distinct().ToList(); }
public PdeConstantCoeff(GeneralizedBlackScholesProcess process, double t, double x) { PdeClass pde = (PdeClass)FastActivator <PdeClass> .Create().factory(process); diffusion_ = pde.diffusion(t, x); drift_ = pde.drift(t, x); discount_ = pde.discount(t, x); }
public RandomSequenceGenerator(int dimensionality, ulong seed) { dimensionality_ = dimensionality; rng_ = (RNG)FastActivator <RNG> .Create().factory(seed); sequence_ = new Sample <List <double> >(new InitializedList <double>(dimensionality), 1.0); int32Sequence_ = new InitializedList <ulong>(dimensionality); }
public InterpolatedZeroCurve(Date referenceDate, DayCounter dayCounter, List <Handle <Quote> > jumps = null, List <Date> jumpDates = null, Interpolator interpolator = default(Interpolator)) : base(referenceDate, null, dayCounter, jumps, jumpDates) { interpolator_ = interpolator ?? FastActivator <Interpolator> .Create(); }
public void calculate() { base.calculate(requiredTolerance_, requiredSamples_, maxSamples_); results_.value = this.mcModel_.sampleAccumulator().mean(); if (FastActivator <RNG> .Create().allowsErrorEstimate != 0) { results_.errorEstimate = this.mcModel_.sampleAccumulator().errorEstimate(); } }
public InterpolatedForwardCurve(int settlementDays, Calendar calendar, DayCounter dayCounter, List <Handle <Quote> > jumps = null, List <Date> jumpDates = null, Interpolator interpolator = default(Interpolator)) : base(settlementDays, calendar, dayCounter, jumps, jumpDates) { interpolator_ = interpolator ?? FastActivator <Interpolator> .Create(); }
public override Vector values(Vector x) { Vector y = FastActivator <Model> .Create().direct(x, xabr_.coeff_.paramIsFixed_, xabr_.coeff_.params_, xabr_.forward_); for (int i = 0; i < xabr_.coeff_.params_.Count; ++i) { xabr_.coeff_.params_[i] = y[i]; } xabr_.coeff_.updateModelInstance(); return(xabr_.interpolationErrors(x)); }
/*! Protected version for use when descendents don't want to * (or can't) provide the points for interpolation on * construction. */ protected InterpolatedZeroInflationCurve(Date referenceDate, Calendar calendar, DayCounter dayCounter, Period lag, Frequency frequency, bool indexIsInterpolated, double baseZeroRate, Handle <YieldTermStructure> yTS, Interpolator interpolator = default(Interpolator)) : base(referenceDate, calendar, dayCounter, baseZeroRate, lag, frequency, indexIsInterpolated, yTS) { interpolator_ = interpolator ?? FastActivator <Interpolator> .Create(); }
public InterpolatedHazardRateCurve(List <Date> dates, List <double> hazardRates, DayCounter dayCounter, Interpolator interpolator) : base(dates[0], null, dayCounter) { dates_ = dates; if (interpolator == null) { interpolator_ = FastActivator <Interpolator> .Create(); } else { interpolator_ = interpolator; } initialize(); }
public void setInterpolation <Interpolator>(Interpolator i = default(Interpolator)) where Interpolator : class, IInterpolationFactory, new () { localVolInterpol_.Clear(); Interpolator i_ = i ?? FastActivator <Interpolator> .Create(); for (int j = 0; j < times_.Count; ++j) { localVolInterpol_.Add(i_.interpolate( strikes_[j], strikes_[j].Count, localVolMatrix_.column(j))); } notifyObservers(); }
public InterpolatedForwardCurve(List <Date> dates, List <double> forwards, DayCounter dayCounter, List <Handle <Quote> > jumps, List <Date> jumpDates, Interpolator interpolator = default(Interpolator)) : base(dates[0], null, dayCounter, jumps, jumpDates) { times_ = new List <double>(); dates_ = dates; data_ = forwards; interpolator_ = interpolator ?? FastActivator <Interpolator> .Create(); initialize(); }
public InterpolatedDiscountCurve(List <Date> dates, List <double> discounts, DayCounter dayCounter, Calendar calendar = null, List <Handle <Quote> > jumps = null, List <Date> jumpDates = null, Interpolator interpolator = default(Interpolator)) : base(dates[0], calendar, dayCounter, jumps, jumpDates) { times_ = new List <double>(); dates_ = dates; data_ = discounts; interpolator_ = interpolator ?? FastActivator <Interpolator> .Create(); initialize(); }
public InterpolatedZeroCurve(List <Date> dates, List <double> yields, DayCounter dayCounter, Calendar calendar = null, List <Handle <Quote> > jumps = null, List <Date> jumpDates = null, Interpolator interpolator = default(Interpolator), Compounding compounding = Compounding.Continuous, Frequency frequency = Frequency.Annual) : base(dates[0], calendar, dayCounter, jumps, jumpDates) { times_ = new List <double>(); dates_ = dates; data_ = yields; interpolator_ = interpolator ?? FastActivator <Interpolator> .Create(); initialize(compounding, frequency); }
public static Complex modifiedBesselFunction_i_impl <T, I>(double nu, Complex x) where T : Weight <Complex>, new() where I : baseValue <Complex>, new() { if (Complex.Abs(x) < 13.0) { Complex alpha = Complex.Pow(0.5 * x, nu) / GammaFunction.value(1.0 + nu); Complex Y = 0.25 * x * x; int k = 1; Complex sum = alpha, B_k = alpha; while (Complex.Abs(B_k *= Y / (k * (k + nu))) > Complex.Abs(sum) * Const.QL_EPSILON) { sum += B_k; Utils.QL_REQUIRE(++k < 1000, () => "max iterations exceeded"); } return(sum * FastActivator <T> .Create().weightSmallX(x)); } else { double na_k = 1.0, sign = 1.0; Complex da_k = new Complex(1.0, 0.0); Complex s1 = new Complex(1.0, 0.0), s2 = new Complex(1.0, 0.0); for (int k = 1; k < 30; ++k) { sign *= -1; na_k *= (4.0 * nu * nu - (2.0 * (double)k - 1.0) * (2.0 * (double)k - 1.0)); da_k *= (8.0 * k) * x; Complex a_k = na_k / da_k; s2 += a_k; s1 += sign * a_k; } Complex i = FastActivator <I> .Create().value(); return(1.0 / Complex.Sqrt(2 * Const.M_PI * x) * (FastActivator <T> .Create().weight1LargeX(x) * s1 + i * Complex.Exp(i * nu * Const.M_PI) * FastActivator <T> .Create().weight2LargeX(x) * s2)); } }
public static double modifiedBesselFunction_i_impl <T, I>(double nu, double x) where T : Weight <double>, new() where I : baseValue <double>, new() { if (Math.Abs(x) < 13.0) { double alpha = Math.Pow(0.5 * x, nu) / GammaFunction.value(1.0 + nu); double Y = 0.25 * x * x; int k = 1; double sum = alpha, B_k = alpha; while (Math.Abs(B_k *= Y / (k * (k + nu))) > Math.Abs(sum) * Const.QL_EPSILON) { sum += B_k; Utils.QL_REQUIRE(++k < 1000, () => "max iterations exceeded"); } return(sum * FastActivator <T> .Create().weightSmallX(x)); } else { double na_k = 1.0, sign = 1.0; double da_k = 1.0; double s1 = 1.0, s2 = 1.0; for (int k = 1; k < 30; ++k) { sign *= -1; na_k *= (4.0 * nu * nu - (2.0 * k - 1.0) * (2.0 * k - 1.0)); da_k *= (8.0 * k) * x; double a_k = na_k / da_k; s2 += a_k; s1 += sign * a_k; } double i = FastActivator <I> .Create().value(); return(1.0 / Math.Sqrt(2 * Const.M_PI * x) * (FastActivator <T> .Create().weight1LargeX(x) * s1 + i * Math.Exp(i * nu * Const.M_PI) * FastActivator <T> .Create().weight2LargeX(x) * s2)); } }
public InterpolatedHazardRateCurve(List <Date> dates, List <double> hazardRates, DayCounter dayCounter, Calendar cal = null, List <Handle <Quote> > jumps = null, List <Date> jumpDates = null, Interpolator interpolator = default(Interpolator)) : base(dates[0], cal, dayCounter, jumps, jumpDates) { dates_ = dates; times_ = new List <double>(); data_ = hazardRates; if (interpolator == null) { interpolator_ = FastActivator <Interpolator> .Create(); } else { interpolator_ = interpolator; } initialize(); }
public InterpolatedCPICapFloorTermPriceSurface(double nominal, double startRate, Period observationLag, Calendar cal, BusinessDayConvention bdc, DayCounter dc, Handle <ZeroInflationIndex> zii, Handle <YieldTermStructure> yts, List <double> cStrikes, List <double> fStrikes, List <Period> cfMaturities, Matrix cPrice, Matrix fPrice) : base(nominal, startRate, observationLag, cal, bdc, dc, zii, yts, cStrikes, fStrikes, cfMaturities, cPrice, fPrice) { interpolator2d_ = FastActivator <Interpolator2D> .Create(); performCalculations(); }