/// <summary> /// Calculates the value of a Bond under the Pelsser model. /// </summary> /// <param name='dynamic'> /// The simulated process. /// </param> /// <param name='dates'> /// The vector of reference dates. /// </param> /// <param name='i'> /// The index at which the state variables must be sampled. /// </param> /// <param name='t'> /// The date in years/fractions at at which the state variables must be sampled. /// </param> /// <param name='s'> /// The maturity of the bond. /// </param> /// <returns>The value of the bound at index i using the Pelsser model.</returns> public double Bond(IReadOnlyMatrixSlice dynamic, double[] dates, int i, double t, double s) { // Handles special case. if (t == s) { return(1); } // Get the value of the short rate. double y = Math.Sqrt(dynamic[i, 0]) - this.alphaT0[i]; PelsserKey k = new PelsserKey(t, s); PelsserCache cachedValue = null; lock (this.cache) { if (this.cache.ContainsKey(k)) { cachedValue = this.cache[k]; } else { cachedValue = new PelsserCache(t, s, this); // Insert the value in the cache. this.cache.Add(k, cachedValue); } } double v = Math.Exp(cachedValue.A - y * cachedValue.B - (y * y) * cachedValue.CtT0); return(v); }
/// <summary> /// Calculates the value of a Bond under the Pelsser model. /// </summary> /// <param name='dynamic'> /// The simulated process. /// </param> /// <param name='dates'> /// The vector of reference dates. /// </param> /// <param name='i'> /// The index at which the state variables must be sampled. /// </param> /// <param name='t'> /// The date in years/fractions at at which the state variables must be sampled. /// </param> /// <param name='s'> /// The maturity of the bond. /// </param> /// <returns>The value of the bound at index i using the Pelsser model.</returns> public double Bond(IReadOnlyMatrixSlice dynamic, double[] dates, int i, double t, double s) { // Handles special case. if (t == s) return 1; // Get the value of the short rate. double y = Math.Sqrt(dynamic[i, 0]) - this.alphaT0[i]; PelsserKey k = new PelsserKey(t, s); PelsserCache cachedValue = null; lock (this.cache) { if (this.cache.ContainsKey(k)) cachedValue = this.cache[k]; else { cachedValue = new PelsserCache(t, s, this); // Insert the value in the cache. this.cache.Add(k, cachedValue); } } double v = Math.Exp(cachedValue.A - y * cachedValue.B - (y * y) * cachedValue.CtT0); return v; }
/// <summary> /// Checks if the provided <see cref="PelsserKey"/> object is equivalent /// to this object. /// </summary> /// <param name="obj">True if the two objects are equivalent.</param> /// <returns>True if the two <see cref="PelsserKey"/> objects are equivalent.</returns> public bool Equals(PelsserKey obj) { return(obj.t == this.t && obj.s == this.s); }
/// <summary> /// Checks if the provided <see cref="PelsserKey"/> object is equivalent /// to this object. /// </summary> /// <param name="obj">True if the two objects are equivalent.</param> /// <returns>True if the two <see cref="PelsserKey"/> objects are equivalent.</returns> public bool Equals(PelsserKey obj) { return obj.t == this.t && obj.s == this.s; }