?? bm.m
字號:
% This program simulates Brownian motion and Geometric Brownian motion. fprintf('\n This program simulates:')fprintf('\n 1. Brownian motion \n 2. Geometric Brownian motion \n')type = input('\n Choose one of the above options (enter 1 or 2): ');mu = input('\n Enter parameter mu: '); sigma = input('\n Enter paremeter sigma: ');S0 = input('\n Enter value at time 0: ');T = input('\n Enter the time horizon T: ');n = input('\n Enter the number of points in the discretization: ');delta = T/n;S = S0;alpha = mu - sigma^2/2;switch type case 1 for i=1:n S = [S; S(i) + mu*delta + sigma*sqrt(delta)*randn]; end plot(delta*[0:1:n], S,'b') title(['Brownian motion, \mu = ',num2str(mu),',\sigma = ',num2str(sigma)]) xlabel('t') case 2 for i=1:n S = [S; S(i)*exp(alpha*delta + sigma*sqrt(delta)*randn)]; end plot(delta*[0:1:n], S, 'g') title(['Geometric Brownian motion, \mu = ',num2str(mu),',\sigma = ',num2str(sigma)]) xlabel('t') otherwise fprintf('\n Error: That is not a valid option \n') end
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -