⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 liborprocess.java

📁 金融资产定价,随机过程,MONTE CARLO 模拟 JAVA 程序和文档资料
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
                                 X0[i][t+1]=Math.exp(Y0[i][t+1]); }                  } // end X0path                                    // X1-DYNAMICS (predictor-corrector)                                     if(X1path){            // predicted drift step vector for Y^1(t)=log(X^1(t))            for(int j=q+1;j<n;j++) F[j]=alpha[j]+beta[j]*Y1[j][t];            for(int i=q;i<n;i++){                               m[i]=-0.5*C[i-t-1][0];                for(int j=i+1;j<n;j++)m[i]-=F[j]*C[i-t-1][j-i];             } // end predicted drift                    // compute predicted Libors            for(int i=q;i<n;i++){ Y1[i][t+1]=Y1[i][t]+m[i]+V[i];                                  X1[i][t+1]=Math.exp(Y1[i][t+1]); }                    // add the corrected drift step vector to the predicted one            // and average the two            for(int j=q+1;j<n;j++) F[j]=alpha[j]+beta[j]*Y1[j][t+1];            for(int i=q;i<n;i++){                            m[i]-=0.5*C[i-t-1][0];               for(int j=i+1;j<n;j++)m[i]-=F[j]*C[i-t-1][j-i];                            // average               m[i]/=2;            }             // recompute the Libors with new drift step            for(int i=q;i<n;i++){ Y1[i][t+1]=Y1[i][t]+m[i]+V[i];                                  X1[i][t+1]=Math.exp(Y1[i][t+1]); }           } // end X1 step                          // X-DYNAMICS (predictor-corrector)                                     if(Xpath){            // predicted drift step vector for Y^1(t)=log(X^1(t))            for(int j=q+1;j<n;j++) F[j]=1-1/(1+X[j][t]);            for(int i=q;i<n;i++){                               m[i]=-0.5*C[i-t-1][0];                for(int j=i+1;j<n;j++){ m[i]-=F[j]*C[i-t-1][j-i]; }            } // end predicted drift                    // compute predicted Libors            for(int i=q;i<n;i++){ Y[i][t+1]=Y[i][t]+m[i]+V[i];                                  X[i][t+1]=Math.exp(Y[i][t+1]); }                    // add the corrected drift step vector to the predicted one            // and average the two            for(int j=q+1;j<n;j++) F[j]=1-1/(1+X[j][t+1]);            for(int i=q;i<n;i++){                            m[i]-=0.5*C[i-t-1][0];               for(int j=i+1;j<n;j++){ m[i]-=F[j]*C[i-t-1][j-i]; }                           // average               m[i]/=2;            }             // recompute the Libors with new drift step            for(int i=q;i<n;i++){ Y[i][t+1]=Y[i][t]+m[i]+V[i];                                  X[i][t+1]=Math.exp(Y[i][t+1]); }          } // end X step           }  // end timeStep               /** <p>Evolves the full set of Libors from discrete time       *  <code>t</code> to time <code>t+1</code> in a single time step.</p>      *      * <p> Assumes that the array Z of driving Wiener increments has been      * filled with new values. See document       * <i>LiborProcessImplementation.ps</i></p>      *      * @param t current discrete time (continuous time <code>T_t</code>).      */     public void timeStep     (int t, boolean Xpath, boolean X0path, boolean X1path)     { timeStep(t,t+1,Xpath,X0path,X1path); }              /******************************************************************************* * *                     PATH GENERATION * ******************************************************************************/                   /** Computes a full Libor path from time zero to the horizon.      *  Moves only the X-Libor path.      */     public void newPath()     {         newWienerIncrements(0,n-1);         for(int t=0;t<n-1;t++)timeStep(t,true,false,false);     }               /** Computes a full Libor path from time zero to the horizon.      *  Moves every path for which the flag is set to true.      *      * @param Xpath move the X-dynamics.      * @param X0path move the X0-dynamics.      * @param X1path move the X1-dynamics.      */     public void newPath     (boolean Xpath, boolean X0path, boolean X1path)     {         newWienerIncrements(0,n-1);         for(int t=0;t<n-1;t++)timeStep(t,Xpath,X0path,X1path);     }          /** <p>Path of Libors      *  <p>      *  <center>      *  <code>      *  t\in[0,T] -&gt (L_p(t),L_{p+1}(t),...,L_{n-1}(t))      *  </code>      *  </center>      *  </p>      *  ie. the Libors <code>L_j(t), j&gt=p</code> are computed from      *  discrete time <code>t=0</code> to discrete time <code>t=T</code>.      *      * @param T discrete time up to which Libors are computed.      * @param p Libors evolved are <code>L_j, j=p,p+1,...,n-1.</code>      */     public void newPath(int T, int p)     {         newWienerIncrements(0,T);         for(int t=0;t<T;t++)timeStep(t,p,true,false,false);     }               /** <p>Path of Libors      *  <p>      *  <center>      *  <code>      *  t\in[0,T] -&gt (L_p(t),L_{p+1}(t),...,L_{n-1}(t))      *  </code>      *  </center>      *  </p>      *  ie. the Libors <code>L_j(t), j&gt=p</code> are computed from      *  discrete time <code>t=0</code> to discrete time <code>t=T</code>.      *      * @param T discrete time up to which Libors are computed.      * @param p Libors evolved are <code>L_j, j=p,p+1,...,n-1.</code>      * @param Xpath move the X-dynamics.      * @param X0path move the X0-dynamics.      * @param X1path move the X1-dynamics.      */     public void newPath     (int T, int p, boolean Xpath, boolean X0path, boolean X1path)     {         newWienerIncrements(0,T);         for(int t=0;t<T;t++)timeStep(t,p,Xpath,X0path,X1path);     }     /** <p>Path of Libors      *  <p>      *  <center>      *  <code>      *  s\in[t,T] -&gt (L_p(s),L_{p+1}(s),...,L_{n-1}(s))      *  </code>      *  </center>      *  </p>      *  ie. continues an existing Libor path from time <code>t</code>      *  to time <code>T</code>. Only the Libors <code>L_j(t), j&gt=p</code>       *  are computed forward. Of ourse this assumes that these Libors have      *  been computed up to time <code>t</code>. Moves only the X-dynamics.      *  </p>      *      * <p>Conditions the state at time <code>T</code> on the state at time      * <code>t</code>.</p>      *      * @param t time of branching.      * @param p only <code>L_j, j=p,p+1,...,n-1</code> computed forward.      */     public void newPathSegment(int t, int T, int p)     {         newWienerIncrements(t,T);         for(int k=t;k<T;k++)timeStep(k,p,true,false,false);     }               /** <p>Special case of {@link #newPathSegment(int,int,int)}.      *  All Libors still alive at time <code>t</code> computed forward.      *  Conditions the state at time <code>T</code> on the state at time      *  <code>t</code>.</p>      *      * @param t path segment starts.      * @param T path segment stops.      */     public void newPathSegment(int t, int T)     {         newPathSegment(t,T,t+1);     }               /** <p>Path of Libors      *  <p>      *  <center>      *  <code>      *  s\in[t,T] -&gt (L_p(s),L_{p+1}(s),...,L_{n-1}(s))      *  </code>      *  </center>      *  </p>      *  ie. continues an existing Libor path from time <code>t</code>      *  to time <code>T</code>. Only the Libors <code>L_j(t), j&gt=p</code>       *  are computed forward. Of ourse this assumes that these Libors have      *  been computed up to time <code>t</code>.</p>      *      * <p>Conditions the state at time <code>T</code> on the state at time      * <code>t</code>.</p>      *      * @param t time of branching.      * @param p only <code>L_j, j=p,p+1,...,n-1</code> computed forward.      * @param Xpath move the X-dynamics.      * @param X0path move the X0-dynamics.      * @param X1path move the X1-dynamics.         */     public void newPathSegment     (int t, int T, int p, boolean Xpath, boolean X0path, boolean X1path)     {         newWienerIncrements(t,T);         for(int k=t;k<T;k++)timeStep(k,p,Xpath,X0path,X1path);     }               /** <p>Special case of       *  {@link #newPathSegment(int,int,int,boolean,boolean,boolean)}.      *  All Libors still alive at time <code>t</code> computed forward.      *  Conditions the state at time <code>T</code> on the state at time      *  <code>t</code>.</p>      *      * @param t path segment starts.      * @param T path segment stops.      */     public void newPathSegment     (int t, int T, boolean Xpath, boolean X0path, boolean X1path)     {         newPathSegment(t,T,t+1,Xpath,X0path,X1path);     }                         /** <p>Computes a full Libor path from time <code>t</code> to the time       *  the <code>s</code> the trigger <code>stop</code> triggers a stop or      *  to time <code>s=n-1</code> if no stop is triggered.      *  Moves only the X-Libor path.       *  Triggers must trigger no later than time <code>s=n</code>.</p>      *      * @param stop trigger triggering the stop.      * @returns first time <code>t<&lt;s&lt n</code> where <code>stop</code>      * is triggered or <code>s=n</code> if the the trigger event never occurs.      */     public int newPathSegment(int t, Trigger stop)     {         newWienerIncrements(t,n-1);         int s=t;         while(!stop.isTriggered(t,s)&&(s<n-1))         { timeStep(s,true,false,false); s++; }                  if(s<n-1)return s;         else if(stop.isTriggered(t,s))return n-1;         else return n;     }               /******************************************************************************* * *                                    ACCESSORS * ******************************************************************************/                 /** Libor <code>L_j(t)</code>, value in current path.      *      * @param t time.      */     public double L(int j, int t){ return X[j][t]/delta[j]; }          /** Gaussian Libor <code>L^0_j(t)</code>, value in current path.      *      * @param j Libor index.      * @param t time.      */     public double L0(int j, int t){ return X0[j][t]/delta[j]; }          /** Gaussian Libor <code>L^1_j(t)</code>, value in current path.      *      * @param j Libor index.      * @param t time.      */     public double L1(int j, int t){ return X1[j][t]/delta[j]; }          /** X-Libor <code>X_j(t)=delta_jL_j(t)</code>, value in current path.      *      * @param j Libor index.      * @param t time.      */     public double X(int j, int t){ return X[j][t]; }          /** Gaussian X-Libor <code>X^0_j(t)</code>, value in current path.      *      * @param j Libor index.      * @param t time.      */     public double X0(int j, int t){ return X0[j][t]; }          /** Gaussian X-Libor <code>X^1_j(t)</code>, value in current path.      *      * @param j Libor index.      * @param t time.      */     public double X1(int j, int t){ return X1[j][t]; }               /******************************************************************************* * *              LIBOR VOLATILITIES, LIBORS AS RANDOM VARIABLES * ******************************************************************************/                 /** Annualized volatility of <code>L_i</code>      *      * @param i Libor index.      */     public double vol(int i)     {         double T=Tc[i],                sgsquare=factorLoading.integral_sgi_sgj_rhoij(i,i,0,T)/T;         return Math.sqrt(sgsquare);     }          /** Libor <code>L_j(T_j)</code> as a random variable.      *      * @param j Libor index.      */     public RandomVariable L(final int j)     {         return new RandomVariable(){                          public double getValue(int t)             {                 newPathSegment(t,j,j); return L(j,j);             }         }; // end return new              } // end L          /** log-Gaussians Libor <code>L^0_j(T_j)</code> as a random variable.      *      * @param j Libor index.      */     public RandomVariable L0(final int j)     {         return new RandomVariable(){                          public double getValue(int t)             {                 newPathSegment(t,j,j); return L0(j,j);             }         }; // end return new              } // end L0               /** log-Gaussian Libor <code>L^1_j(T_j)</code> as a random variable.      *      * @param j Libor index.      */     public RandomVariable L1(final int j)     {         return new RandomVariable(){                          public double getValue(int t)             {                 newPathSegment(t,j,j); return L1(j,j);             }         }; // end return new              } // end L1               /** Log-Libor <code>log(L_j(T_j))</code> as a random variable.      *      * @param j Libor index.      */     public RandomVariable logL(final int j)     {         return new RandomVariable(){                          public double getValue(int t)             {                 newPathSegment(t,j,j); return Math.log(L(j,j));             }         }; // end return new              } // end logL               /** Gaussian log-Libor <code>log(L^0_j(T_j))</code> as a random variable.      *      * @param j Libor index.      */     public RandomVariable logL0(final int j)     {         return new RandomVariable(){                          public double getValue(int t)             {                 newPathSegment(t,j,j); return Math.log(L0(j,j));             }         }; // end return new              } // end logL0               /** Gaussian log-Libor <code>log(L^1_j(T_j))</code> as a random variable.      *      * @param j Libor index.      */     public RandomVariable logL1(final int j)     {         return new RandomVariable(){

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -