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

📄 l2nx.java

📁 金融资产定价,随机过程,MONTE CARLO 模拟 JAVA 程序和文档资料
💻 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*//* * L2NX.java * * Created on May 23, 2002, 6:04 PM */package Examples.QuasiMonteCarlo;import com.skylit.io.EasyReader;import Statistics.*;import QuasiRandom.*;import Market.*;import Options.*;import Graphics.*;import IO.*;/** Class computes the L2 discrepancy of the Sobol and Niederreiter Xing *  sequences in dimensions 4-20 and writes the result to the file *  "L2D.txt". Warning: this takes a while. * * @author  Michael J. Meyer */public class L2NX {       public static final int N=16383;   public static void main(String[] args)   throws java.io.IOException   {              // file writer to write in columns of fixed width w      final int w=35;                     // width of output columns      String fileName="L2D.txt";          // output file      FixedFieldWidthFileWriter       fout=new FixedFieldWidthFileWriter(fileName,w);      fout.write("L2 DISCREPANCIES OF SOBOL AND NX SEQUENCES:\n\n\n");      // main loop over dimensions      for(int dim=4;dim<21;dim++){                 System.out.println("dim="+dim);                LowDiscrepancySequence       ss=new Sobol(dim), nxs=new NX(dim);            // the low discrepancy points      double[][] rss=new double[N][dim];   // Sobol      double[][] rnxs=new double[N][dim];  // Niederreiter-Xing            fout.write("DIMENSION="+dim+":\n\n");            // NXT POINTS            // fill the point array with NX points      for(int n=0;n<N;n++)ss.nextPoint(rss[n]);      for(int n=0;n<N;n++)nxs.nextPoint(rnxs[n]);            // compute the L2-discrepancy      computeL2Discrepancy      (N,rss,ss,"Sobol",rnxs,nxs,"NX",fout);            } // end main loop            fout.close();      System.out.println("Finished, results in file L2D.txt");         } // end main         /** Compute the L2-discrepancies of the low discrepancy sequence     *  S at points N=2^n-1, n=9,10,...,15 and print a report to the screen.    */      public static void computeL2Discrepancy   (double[][] r, int N, LowDiscrepancySequence S)   {             // recursive computation, report progress       LoopStatus loopStatus=new LoopStatus();      long before=System.currentTimeMillis();             // we print the discrepamcies at values n=2^m-1 starting with n=511      int twopower=512;            double T_N=0;                           for(int n=0;n<N;n++)      {          T_N=S.L2_discrepancy(n,r,T_N);          if(n==(twopower-2))          {               System.out.println("n="+(n+1)+",  T_n="+T_N);              twopower*=2;          }                    // progress report, triangular nature of the main sum          if(n%150==149)          loopStatus.progressReport(n*(n-1)/2,N*(N-1)/2,149*148/2+1,before);       }            long after=System.currentTimeMillis(),           time=after-before;      System.out.println("\n\nTime: "+time);         } // end computeL2Discrepancy      /** Compute the L2-discrepancies of the low discrepancy sequences     *  X,Y at points N=2^n-1, n=9,10,...,15 and print a report to the file    *  L2D.txt.    */   public static void computeL2Discrepancy   (int N, double[][] rx, LowDiscrepancySequence X, String Xseq,           double[][] ry, LowDiscrepancySequence Y, String Yseq,    FixedFieldWidthFileWriter fout)    throws java.io.IOException   {             // recursive computation, report progress       LoopStatus loopStatus=new LoopStatus();      long before=System.currentTimeMillis();             // we print the discrepamcies at values n=2^m-1 starting with n=511      int twopower=512;            double xT_N=0, yT_N=0;                           for(int n=0;n<N;n++)      {          xT_N=X.L2_discrepancy(n,rx,xT_N);          yT_N=Y.L2_discrepancy(n,ry,yT_N);          if(n==(twopower-2))          {               fout.writeField("n="+n+":",10);              fout.writeField(Xseq+": T_n="+xT_N);              fout.writeField(Yseq+": T_n="+yT_N);              fout.write("\n");              twopower*=2;          }                    // progress report, triangular nature of the main sum          if(n%150==149)          loopStatus.progressReport(n*(n-1)/2,N*(N-1)/2,149*148/2+1,before);       }            long after=System.currentTimeMillis(),           time=after-before;      fout.write("\nTime (secs): "+time/1000+"\n\n\n");         } // end computeL2Discrepancy                 } // end L2NX    

⌨️ 快捷键说明

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