📄 optionalsamplingtest.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*//* * OptionalSamplingTest.java * * Created on January 18, 2001, 4:25 AM */ package Examples.Probability;import Statistics.*;import Processes.*;import java.lang.Math.*; /** <p>We set up a symmetric random walk X (a martingale) and check the Optional * Sampling Theorem (E(X_Tau)=X_0) for a hitting time Tau (the first exit time * from the interval [-20,20]). We then load the odds unfavourably to obtain a * supermartingale and check the Optional Sampling Theorem * (E(X_Tau)<=X_0) again.</p> * * @author Michael J. Meyer */public class OptionalSamplingTest{ public static void main(String[] args) { String message; message="Checking the Optional Sampling theorem for a random\n"+ "walk W starting at zero sampled at the first exit time\n"+ "from [-20,+20] (patience, large sample):\n\n"; System.out.println(message); int T=2000000; //time steps to horizon double W_0=0.0; //initial value /** First let us throw a fair coin (martingale): */ SymmetricRandomWalk W=new SymmetricRandomWalk(T,W_0); //the set (-oo,-20)U(20,oo) as a local class Region_1D I=new Region_1D(){ public boolean isMember(double x) { return ((x>20)||(x<-20)); } }; //end I //first exit time from [-20,20]: final StoppingTime tau=new HittingTime_1D(W,I); //the random walk sampled at tau RandomVariable W_tau=W.sampledAt(tau); //Monte Carlo mean, sample size 300000 double E=W_tau.expectation(300000); //cut this down to 5 decimals E=1.0*Math.round(10000*E)/10000; message="Fair odds (martingale case): 0=W(0)=E(W_tau)="+E+"\n"; System.out.println(message); /** Now we change the odds to 0.49/0.51 (supermartingale): */ BiasedRandomWalk X=new BiasedRandomWalk(T,W_0,0.49); final StoppingTime rho=new HittingTime_1D(X,I); //the random walk sampled at tau RandomVariable X_rho=X.sampledAt(rho); //Monte Carlo mean, sample size 50000 E=X_rho.expectation(50000); //cut this down to 5 decimals E=1.0*Math.round(10000*E)/10000; message="Subfair odds (0.49/0.51, supermartingale case): "+ "0=W(0)>E(W_tau)="+E; System.out.println(message); } //end main }//end OptionalSamplingTest_1
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -