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

📄 bm.m

📁 Brownian Motion, Option.
💻 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 + -