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

📄 l2discrepancy.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*//* * L2Discrepancy.java * * Created on April 26, 2002, 5:51 PM */package Examples.QuasiMonteCarlo;import com.skylit.io.EasyReader;import Statistics.*;import QuasiRandom.*;import Market.*;import Options.*;import Graphics.*;/** <p>Computes L2-discrepancies both using the recursive and explicit *  formulas. Tests if these formulas agree.</p> * * @author  Michael J. Meyer */public class L2Discrepancy {        public static void main(String[] args)   {      int  dim,           N;      String str=null;            // read dimension and number of Monte Carlo runs:      EasyReader io=new EasyReader();            // main loop, terminates when progress bar is closed      while(true){                System.out.print      ("\n\n\nComputing the L2-discrepancy.\n\n"+       "Halton (1), Sobol (2), Uniform (3)\n"+       "Enter choice: ");            int sequence=io.readInt();            System.out.print("Enter dimension: ");      dim=io.readInt();            System.out.print("Enter number of points: ");      N=io.readInt();            LowDiscrepancySequence S=null;            switch(sequence)      {          case 1: S=new Halton(dim);                  str="Halton sequence";                  break;                    case 2: S=new Sobol(dim);                  str="Sobol sequence";                   break;                            case 3: S=new Uniform(dim);                  str="Uniform sequence";             } // end switch                            // allocate and fill the point array      double[][] r=new double[N][dim];           for(int n=0;n<N;n++)S.nextPoint(r[n]);      double T_N=0;                                 System.out.println("\n\nL2-DISCREPANCY, "+str+":\n");            // recursive computation, report progress       LoopStatus loopStatus=new LoopStatus();      long before=System.currentTimeMillis();      int loops=0;      for(int n=0;n<N;n++)      {          T_N=S.L2_discrepancy(n,r,T_N);          if(n%1000==0)          System.out.println("n="+(n+1)+", recursive  T_n="+T_N);          // progress report, triangular nature of the main sum          loops++;          if(loops%150==149)          loopStatus.progressReport(loops,N*(N-1)/2,15,before);       }            long after=System.currentTimeMillis(),           time=after-before;      System.out.println("\n\nRecursive  T_"+N+" = "+T_N+                         "\nTime: "+time);                // direct computation      before=System.currentTimeMillis();      T_N=S.L2_discrepancy(N,r);      after=System.currentTimeMillis();      time=after-before;      System.out.println("\n\nDirect  T_"+N+" = "+T_N+                         "\nTime: "+time);                } // end main loop               } // end main              } // end SobolPointDiscrepancy

⌨️ 快捷键说明

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