Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.

Topic: Repeat Simulation
Replies: 14   Last Post: Jul 30, 2012 6:39 PM

 Messages: [ Previous | Next ]
 Karren Posts: 15 Registered: 11/7/11
Re: Repeat Simulation
Posted: Mar 18, 2012 7:54 PM

"Nasser M. Abbasi" <nma@12000.org> wrote in message <jjvfhh\$78c\$1@speranza.aioe.org>...
> On 3/16/2012 3:52 AM, Karren wrote:
>

> >> -------------------------
> >> open excel
> >> read parameters to a vector V
> >> for i=1:length(V)
> >> run_simulation(V(i))
> >> end
> >> --------------------------
> >> go_to_sleep_now()
> >>

>
>

> > Do I need to use Simulink in order to run the above?
>
> No. Simulink is not needed. The above is just a matlab script.
>
> You create an .m file (using the Matlab editor) and type
> the Matlab commands in it.
>
> Then you run the .m file (i.e. execute the Matlab commands).
>
> The script will read the parameters from the excel work sheet
> and run the simulations. You do not need to sit and wait
> for it to finish.
>
> --Nasser

Hi Mr. Nasser,
Thanks very much for the guide. I tried it out but I couldn't get it. Can you please look at my code and provide further guide?

function [ SP_risk_neutral ] = Gen_SP_risk_neutral(S0, r, d, sigma, T, NSteps,NRepl)
%Generate stock price using risk-neutral approach.
dt = T/NSteps; %Time increment.
dBt = sqrt(dt)*randn(NRepl,NSteps+1); %Brownian motion.
SP_risk_neutral = zeros(NRepl,NSteps); %Initialise matrix.
SP_risk_neutral(:,1) = S0*ones(NRepl,1); % Vector of initial stock price.
for t = 1:NSteps;
SP_risk_neutral(:,t+1) = SP_risk_neutral(:,t).*exp((r-d-.5*sigma^2)*dt +sigma*dBt(:,t+1));
end
end

%Constant parameters include.
sigma = .3972;
r = .0471;
d = 0.00; % for this case.
NRepl = 100; % for a trial.
T = NSteps/360; %T changes with NSteps.

%Varying parameters include of NSteps and S0. As an example
NSteps S0
1858 15.72
1857 15.84
1856 15.46
1855 15.78
1854 15.50

I start running the function Gen_SP_risk_neutral with the first data set S0 = 15.72 and NSteps = 1858. From the function, I'll generate 100 * 1859 stock price, given by the loop. I have to keep the outputs.

Then I have to rerun the function using S0 = 15.84 and NSteps = 1857. The same process will repeat...

I tried to repeat the function/simulation as suggested but I failed. Following is the code that I used.

for i = 1:length(V)
run Gen_SP_risk_neutral(V(i))
end

Error message states that there is an error in line 3.

Hope my explaination would help you to better understand my problem. Kindly help. I really some guide here to complete running my data which I'm currently doing it manual (partially), thus slowing down a lot of my progress. Please assist.

Karren

Date Subject Author
3/15/12 Karren
3/15/12 Nasser Abbasi
3/16/12 Karren
3/16/12 Nasser Abbasi
3/18/12 Karren
3/18/12 Nasser Abbasi
3/18/12 Karren
3/19/12 Nasser Abbasi
3/19/12 Karren
3/19/12 Nasser Abbasi
3/20/12 Karren
3/20/12 Nasser Abbasi
3/20/12 Karren
3/20/12 Nasser Abbasi
7/30/12 Karren