/// <summary> /// Initialize a new SinglePathGenerator with constant drift and variance. /// </summary> /// <remarks> /// The initial time is assumed to be zero and must /// <b>not</b> be included in the passed SparseVector. /// </remarks> /// <param name="generator">The generator.</param> /// <param name="drift"> /// Constant drift of the Brownian random walks. /// </param> /// <param name="variance"> /// Constant variance. /// </param> /// <param name="times"> /// A <see cref="SparseVector"/> of explicitly specified times at which the /// path will be sampled. /// The initial time is assumed to be zero and must /// <b>not</b> be included in the passed SparseVector. /// </param> public SinglePathGenerator(IContinuousRng generator, double drift, double variance, SparseVector times) : base(new SparseVector(1, drift), times) { if (variance < 0.0) { throw new ArgumentException("TODO: Variance can not be negative."); } ArrayGenerator = new RandomArrayGenerator(generator, TimeDelays * variance); }
/// <overloads> /// Initialize a new SinglePathGenerator. /// </overloads> /// <summary> /// Initialize a new SinglePathGenerator with constant drift and variance, /// sampled at the given number of equal time steps. /// </summary> /// <param name="generator">The generator.</param> /// <param name="drift"> /// Constant drift of the Brownian random walks. /// </param> /// <param name="variance"> /// Constant variance. /// </param> /// <param name="time"> /// Time span which is sampled in <paramref name="timeSteps"/> equal time steps. /// </param> /// <param name="timeSteps"> /// Number of equal time steps at which the path will be sampled. /// </param> public SinglePathGenerator(IContinuousRng generator, double drift, double variance, double time, int timeSteps) : base(new SparseVector(1, drift), time, timeSteps) { if (variance < 0.0) { throw new ArgumentException("TODO: Variance can not be negative."); } ArrayGenerator = new RandomArrayGenerator(generator, new SparseVector(TimeSteps, variance * time / TimeSteps)); }
private void InitializeGenerator(IContinuousRng generator, Matrix covariance) { SparseVector diagonal = covariance.Diagonal; if (Count != diagonal.Length) { throw new ArgumentException("TODO: Covariance matrix does not match number of assets"); } if (diagonal.Min() < 0.0) { throw new ArgumentException("TODO: Covariance matrix contains negative variance."); } ArrayGenerator = new RandomArrayGenerator(generator, covariance); }
/// <summary> /// Initialize a new SinglePathGenerator with a zero drift and time dependent path. /// </summary> /// <remarks> /// The initial time is assumed to be zero and must /// <b>not</b> be included in the passed SparseVector. /// </remarks> /// <param name="generator">The generator.</param> /// <param name="variance"> /// A <see cref="SparseVector"/> of time-dependent variances. /// </param> /// <param name="times"> /// A <see cref="SparseVector"/> of explicitly specified times at which the /// path will be sampled. /// The initial time is assumed to be zero and must /// <b>not</b> be included in the passed SparseVector. /// </param> public SinglePathGenerator(IContinuousRng generator, SparseVector variance, SparseVector times) : base(1, times.Length) { if (times[0] < 0.0) { throw new ArgumentException("TODO: First time can not be negative (times[0] must be >= 0.0)."); } if (variance.Length != TimeSteps) { throw new ArgumentException("TODO: Size mismatch between variance and time SparseVectors."); } Times = times; TimeDelays = AdjacentDifference(times); Drift[0] = new SparseVector(times.Length); ArrayGenerator = new RandomArrayGenerator(generator, TimeDelays * variance); }