📄 factorloading.java
字号:
/* WARANTY NOTICE AND COPYRIGHTThis program is free software; you can redistribute it and/ormodify it under the terms of the GNU General Public Licenseas published by the Free Software Foundation; either version 2of the License, or (at your option) any later version.This program is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See theGNU General Public License for more details.You should have received a copy of the GNU General Public Licensealong with this program; if not, write to the Free SoftwareFoundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.Copyright (C) Michael J. Meyermatmjm@mindspring.comspyqqqdia@yahoo.com*//* * FactorLoading.java * * Created on August 25, 2002, 2:44 PM */package Libor.LiborProcess;import LinAlg.*;import ArrayClasses.*;/** <p>This class provides access to the factor loadings <code>nu_i(s)</code> * in the form of the Libor volatilities <code>sigma_i(t)</code> and * correlations <code>rho_ij</code>. With <code>t<T</code> continuous times, * set</p> * <p> * <center> * <code>cv_ij(s)=sigma_i(s)sigma_j(s)rho_ij=nu_i(s).nu_j(s)<code> * </center> * and * <center> * <code>CV_ij(t,T)=integral_t^T cv_ij(s)ds =<log(L_i),log(L_j)>_t^T<code> * </center> * </p> * <p>and let <code>CV(t,T)</code> be the matrix</p> * <p> * <center> * <code>CV(p,n,t,T)=( CV_ij(t,T) )_{p<=i,j<n}).</code> * </center> * </p> * <p>This matrix is called the <i>(log Libor) covariation matrix</i> on * the interval <code>[t,T]</code>. The Cholesky root of this matrix is used * in the simulation of the time step t->T for the Libors * <code>L_p,L_{p+1},...,L_{n-1}</code></p> * * <p><b><a name="logcvm">Covariation matrix array.</a></b> * Since we simulate Libor paths with time steps <code>T_t->T_{t+1}</code> * (ie. from one reset time to the next) we need the array <code>CV[]</code> * of matrices <code>CV[t]=CV(t+1,n,T_t,T_{t+1}), t=0,1,...,n-2.</code> * We also need the * corresponding array <code>L[]</code> of Cholesky roots <code>L[t]</code> * of <code>CV[t]</code>.</p> * * <p>These arrays are path independent and hence are best precomputed and * stored in advance of any Libor path simulation. Only the upper triangular * half of the matrices <code>CV[t]</code> is used and the matrices * <code>L[t]</code> are lower triangular.</p> * * <p>Consequently the array <code>CV[]</code> is allocated as a * {@link ArrayClasses.UTRMatrixArray} * (stores the upper half of each matrix <code>CV[t]</code>) * while the array <code>L[]</code> is allocated as a * {@link ArrayClasses.LTRMatrixArray} * (stores the lower half of each matrix <code>L[t]</code>).</p> * * <p>These structures expose references to the underlying raw java data array * so access to the data is possible without accessor functions (speed).</p> * * <p>The class <code>FactorLoading</code> has abstract methodes to compute * various covariation integrals (which obviously depend on the concrete * volatility and correlation structure) and uses these to compute the various * matrices and matrix arrays and allocates the matrix arrays needed for path * simulation.</p> * * <p><b>Concrete subclass:</b> the subclass {@link CS_FactorLoading} implements * a volatility and correlation structure dependoing on five parameters * following ideas of B. Coffey and J. Shoenmakers.</p> * * * @author Michael J. Meyer */public abstract class FactorLoading { int n; // number of forward Libors (includes L_0(t)). double[] Tc; // tenor structure Tc[t]=T_t /** The array of log Libor covariation matrices. */ UTRMatrixArray covariationMatrices; /** The array of Cholesky roots of the log Libor covariation matrices. */ LTRMatrixArray choleskyRoots; /******************************************************************************* * * ACCESSORS * ******************************************************************************/ /** Number <code>n</code> of forward Libors including <code>L_0</code>. */ public int getDimension(){ return n; } /** Array <code>Tc</code> of continuous Libor reset times * <code>Tc[j]=T_j</code>. */ public double[] getTenorStructure(){ return Tc; } /** The <a href=#logcvm>array of covariation matrices</a>. */ public UTRMatrixArray getCovariationMatrixArray() { return covariationMatrices; } /** The <a href=#logcvm>array of covariation matrices</a>. */ public LTRMatrixArray getCholeskyRootArray() { return choleskyRoots; } /******************************************************************************* * * CONSTRUCTOR * ******************************************************************************/ /**<p>The covariation and Cholesky root sequence arrays can be allocated * but must be initialized from the concrete subclasses once all the * structures necessary to compute the integrals are in place.</p> * * @param n dimension of Libor process * @param Tc tenor structure array */ public FactorLoading(int n, double[] Tc) { this.n=n; this.Tc=Tc; covariationMatrices=new UTRMatrixArray(n); choleskyRoots=new LTRMatrixArray(n); } /******************************************************************************* * * CORRELATIONS, VOLATILITIES, LOG-COVARIATION INTEGRALS * ******************************************************************************/ /** Instantaneous correlation <code>rho_ij</code> of log-Libor increments for * <code>0<=i,j<n</code>. This includes <code>L_0</code> and so takes * the view that all Libors live to the horizon. * See document <i>LiborProcess.ps.</i></p> * * @param i index of forward Libor <code>L_i(t)</code>, * <code>0<=i<n</code>. * @param j index of forward Libor <code>L_j(t)</code>, * <code>0<=j<n</code>. */ public abstract double rho(int i, int j); /** Volatility <code>sigma_i(t)</code> of forward Libor <code>L_i(t)</code> * See document LiborProcess.ps * *@param i index of forward Libor <code>L_i(t)</code>. *@param t current <i>continuous</i> time. */ public abstract double sigma(int i, double t); /** The integral<br> * <code>integral_t^T sigma_i(s)sigma_j(s)rho_ijds= * <log(L_i),log(L_j)>_t^T * </code><br> * neeeded for the distribution of time step increments. * See document <i>LiborProcess.ps</i> * *@param i index of forward Libor <code>L_i(t)</code> *@param j index of forward Libor <code>L_j(t)</code> */ public abstract double integral_sgi_sgj_rhoij(int i, int j, double t, double T); /** String containing a message indicating what type of facto loading * it is, all the parameter values. */ public abstract String toString(); /******************************************************************************* * * LOG-COVARIATION MATRICES AND CHOLESKY ROOTS * ******************************************************************************/ /** <p>The <a name="log-covariation-matrix">matrix</a> of covariations * <code><log(L_i),log(L_j)>_{T_t}^{T_{t+1}}</code> * <p> * <center> * <code>CV(t)=( integral_{T_t}^{T_{t+1}}cv_ij(s)ds )_{i,j=t+1}^{n-1}</code> * </center> * where * <center> * <code>cv_ij(s)=sigma_i(s)sigma_j(s)rho_ij=nu_i(s).nu_j(s).</code> * </center> * </p> * <p>The Cholesky root of this matrix is needed to drive the time step * <code>t->t+1</code> of the Libors <code>(L_{t+1},...,L_{n-1})</code>.</p> * * <p>WARNING: index shift to zero based matrix indices * <code>(i,j)->(i-t-1,j-t-1)</code>.</p> * *@param t discrete time (continuous time <code>T_t</code>). */ public ColtMatrix logCovariationMatrix(int t) { int size=n-t-1; // matrix size double[][] cv=new double[size][size]; for(int i=0;i<size;i++) for(int j=0;j<=i;j++){ double cv_ij=integral_sgi_sgj_rhoij(i+t+1,j+t+1,Tc[t],Tc[t+1]); cv[i][j]=cv_ij; cv[j][i]=cv_ij; } return new ColtMatrix(cv); }// end logCovariationMatrix /** The <a name="cholesky-root">Cholesky root</a> of the * {@link #logCovariationMatrix} * This matrix is needed to drive the time step <code>t->t+1</code> * of the Libors <code>(L_{t+1},...,L_{n-1})</code>. * *@param t beginning of time interval (time step). */ public ColtMatrix logCovariationCholeskyRoot(int t) { return logCovariationMatrix(t).choleskyRoot(); } /** <p>The <code>n by n</code> matrix of instantaneous log-Libor * correlations <code>(rho_ij)_{0<=i,j<n}</code>. Note that this * includes Libor <code>L_0</code> ie. we are taking the view here that * all Libors live to the horizon. Otherwise <code>L_0</code> would be a * constant and correlations with <code>L_0</code> undefined. * See document <i>LiborProcess.ps</i>.</p> */ public ColtMatrix rho() { ColtMatrix rho=new ColtMatrix(n,n); for(int i=0;i<n;i++) for(int j=0;j<n;j++)rho.setQuick(i,j,rho(i,j)); return rho; } /** <p>The matrix of log-Libor covariations * <code><log(L_i),log(L_j)>_t^T</code> on the interval * <code>[t,T]</code></p> * <p> * <center> * <code>CV(p,q,t,T)=( integral_t^T cv_ij(s)ds )_{i,j=p}^{q-1}</code> * </center> * where * <center> * <code>cv_ij(s)=sigma_i(s)sigma_j(s)rho_ij=nu_i(s).nu_j(s).</code> * </center> * </p> * * <p>WARNING: index shift to zero based matrix indices * <code>(i,j)->(i-p,j-p)</code>.</p> * * @param p Libors <code>L_j, j=p,...,q-1.</code> * @param p Libors <code>L_j, j=p,...,q-1.</code> * @param t time interval <code>[t,T]</code>, continuous time. * @param T time interval <code>[t,T]</code>, continuous time. */ public ColtMatrix logCovariationMatrix(int p,int q, double t, double T) { int size=q-p; // matrix size double[][] cv=new double[size][size]; for(int i=0;i<size;i++) for(int j=0;j<=i;j++){ double cv_ij=integral_sgi_sgj_rhoij(i+p,j+p,t,T); cv[i][j]=cv_ij; cv[j][i]=cv_ij; } return new ColtMatrix(cv); }// end logCovariationMatrix /** <p>The Cholesky root of * {@link #logCovariationMatrix(int,int,double,double)}.</p> * * @param p Libors <code>L_j, j=p,...,q-1.</code> * @param p Libors <code>L_j, j=p,...,q-1.</code> * @param t time interval <code>[t,T]</code>, continuous time. * @param T time interval <code>[t,T]</code>, continuous time. */ public ColtMatrix logCovariationCholeskyRoot(int p,int q, double t, double T) { return logCovariationMatrix(p,q,t,T).choleskyRoot(); } } // end FactorLoading
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -