protected override void generateArguments() { double rho = arguments_[0].value(0.0); for (int i = 0; i < size_; ++i) { for (int j = i; j < size_; ++j) { corrMatrix_[i, j] = corrMatrix_[j, i] = Math.Exp(-rho * Math.Abs((double)i - (double)j)); } } pseudoSqrt_ = MatrixUtilitites.pseudoSqrt(corrMatrix_, MatrixUtilitites.SalvagingAlgorithm.Spectral); }
public StochasticProcessArray(List <StochasticProcess1D> processes, Matrix correlation) { processes_ = processes; sqrtCorrelation_ = MatrixUtilitites.pseudoSqrt(correlation, MatrixUtilitites.SalvagingAlgorithm.Spectral); Utils.QL_REQUIRE(processes.Count != 0, () => "no processes given"); Utils.QL_REQUIRE(correlation.rows() == processes.Count, () => "mismatch between number of processes and size of correlation matrix"); for (int i = 0; i < processes_.Count; i++) { processes_[i].registerWith(update); } }
protected override void generateArguments() { double rho = arguments_[0].value(0.0); double beta = arguments_[1].value(0.0); for (int i = 0; i < size_; ++i) { for (int j = i; j < size_; ++j) { corrMatrix_[i, j] = corrMatrix_[j, i] = rho + (1 - rho) * Math.Exp(-beta * Math.Abs((double)i - (double)j)); } } pseudoSqrt_ = MatrixUtilitites.rankReducedSqrt(corrMatrix_, factors_, 1.0, MatrixUtilitites.SalvagingAlgorithm.None); corrMatrix_ = pseudoSqrt_ * Matrix.transpose(pseudoSqrt_); }
public StochasticProcessArray(List <StochasticProcess1D> processes, Matrix correlation) { processes_ = processes; sqrtCorrelation_ = MatrixUtilitites.pseudoSqrt(correlation, MatrixUtilitites.SalvagingAlgorithm.Spectral); if (processes.Count == 0) { throw new ApplicationException("no processes given"); } if (correlation.rows() != processes.Count) { throw new ApplicationException("mismatch between number of processes and size of correlation matrix"); } for (int i = 0; i < processes_.Count; i++) { processes_[i].registerWith(update); } }
public LfmHullWhiteParameterization( LiborForwardModelProcess process, OptionletVolatilityStructure capletVol, Matrix correlation, int factors) : base(process.size(), factors) { diffusion_ = new Matrix(size_ - 1, factors_); fixingTimes_ = process.fixingTimes(); Matrix sqrtCorr = new Matrix(size_ - 1, factors_, 1.0); if (correlation.empty()) { if (!(factors_ == 1)) { throw new ApplicationException("correlation matrix must be given for " + "multi factor models"); } } else { if (!(correlation.rows() == size_ - 1 && correlation.rows() == correlation.columns())) { throw new ApplicationException("wrong dimesion of the correlation matrix"); } if (!(factors_ <= size_ - 1)) { throw new ApplicationException("too many factors for given LFM process"); } Matrix tmpSqrtCorr = MatrixUtilitites.pseudoSqrt(correlation, MatrixUtilitites.SalvagingAlgorithm.Spectral); // reduce to n factor model // "Reconstructing a valid correlation matrix from invalid data" // (<http://www.quarchome.org/correlationmatrix.pdf>) for (int i = 0; i < size_ - 1; ++i) { double d = 0; tmpSqrtCorr.row(i).GetRange(0, factors_).ForEach((ii, vv) => d += vv * tmpSqrtCorr.row(i)[ii]); //sqrtCorr.row(i).GetRange(0, factors_).ForEach((ii, vv) => sqrtCorr.row(i)[ii] = tmpSqrtCorr.row(i).GetRange(0, factors_)[ii] / Math.Sqrt(d)); for (int k = 0; k < factors_; ++k) { sqrtCorr[i, k] = tmpSqrtCorr.row(i).GetRange(0, factors_)[k] / Math.Sqrt(d); } } } List <double> lambda = new List <double>(); DayCounter dayCounter = process.index().dayCounter(); List <double> fixingTimes = process.fixingTimes(); List <Date> fixingDates = process.fixingDates(); for (int i = 1; i < size_; ++i) { double cumVar = 0.0; for (int j = 1; j < i; ++j) { cumVar += lambda[i - j - 1] * lambda[i - j - 1] * (fixingTimes[j + 1] - fixingTimes[j]); } double vol = capletVol.volatility(fixingDates[i], 0.0, false); double var = vol * vol * capletVol.dayCounter().yearFraction(fixingDates[0], fixingDates[i]); lambda.Add(Math.Sqrt((var - cumVar) / (fixingTimes[1] - fixingTimes[0]))); for (int q = 0; q < factors_; ++q) { diffusion_[i - 1, q] = sqrtCorr[i - 1, q] * lambda.Last(); } } covariance_ = diffusion_ * Matrix.transpose(diffusion_); }
public virtual Matrix pseudoSqrt(double t, Vector x = null) { return(MatrixUtilitites.pseudoSqrt(this.correlation(t, x), MatrixUtilitites.SalvagingAlgorithm.Spectral)); }