/// <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));
 }
 /// <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);
 }
示例#3
0
        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);
        }
示例#4
0
 /// <summary>
 /// different averages, different variances, covariance
 /// </summary>
 /// <param name="generator"></param>
 /// <param name="covariance"></param>
 public RandomArrayGenerator(
     IContinuousRng generator, Matrix covariance)
 {
     if (covariance.RowCount != covariance.ColumnCount)
     {
         throw new ArgumentException("TODO: Covariance matrix must be square.");
     }
     if (covariance.RowCount == 0)
     {
         throw new ArgumentException("TODO: Null covariance matrix given.");
     }
     Count           = covariance.RowCount;
     _generator      = generator;
     _sqrtCovariance = Matrix.Sqrt(covariance);
 }
示例#5
0
 /// <summary>
 /// equal average, different variances, no covariance
 /// </summary>
 /// <param name="generator"></param>
 /// <param name="variance"></param>
 public RandomArrayGenerator(
     IContinuousRng generator, SparseVector variance)
 {
     Count      = variance.Length;
     _generator = generator;
     // TODO: replace by VML equiv. and check return
     // status for exceptions
     _sqrtVariance = SparseVector.Sqrt(variance);
     for (int i = 0; i < _sqrtVariance.Length; i++)
     {
         if (variance[i] < 0.0)
         {
             throw new ArgumentOutOfRangeException(nameof(generator));
         }
     }
 }
 /// <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);
 }
示例#7
0
 /// <summary>
 /// Initialize a new MultiPathGenerator with constant drifts and variances.
 /// </summary>
 /// <summary>
 /// Initialize a new MultiPathGenerator which samples at explicitly specified times.
 /// </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"></param>
 /// <param name="drifts">
 /// A <see cref="SparseVector"/> of constant drifts - one for each single asset.
 /// </param>
 /// <param name="covariance">
 /// A covariance <see cref="Matrix"/> which encapsulates the relations between
 /// the diffusion components of the single assets.
 /// </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 MultiPathGenerator(IContinuousRng generator,
                           SparseVector drifts, Matrix covariance, SparseVector times)
     : base(drifts, times)
 {
     InitializeGenerator(generator, covariance);
 }