MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn moreOpportunities for recent engineering grads.

Apply Today**New to MATLAB?**

Asked by Lindsay Mahoney
on 11 May 2013

Let S(t) be the price of one share of a particular company at time t. If the price S(t+1) at time t+1 can either take the value of uS(t) with probability p(1) ( where u > 1), remain the same with probability p(2) or go down to dS(t) with probability 1 - p(1) - p(2) ( where 0<d<1), create a Matlab function that simulates {S(t)} from t=0 to 20 for given u,d,p(1),p(2) and plots S(t) against t. Hence, by counting the number of paths, calculate the probability that S(6)=S(0)*u^2*d^3. USE THE COMMAND RAND.

*No products are associated with this question.*

Answer by Image Analyst
on 11 May 2013

Edited by Image Analyst
on 12 May 2013

It's not really a challenge for us - not difficult enough. Homework Hint:

randomNumber = rand(1) if randomNumber < p(1) % Case 1 S(t) = u * S(t-1); elseif randomNumber < p(1) + p(2) % Case 2: Price remains the same. else % Case 3: Price decreases. S(t) = d * S(t-1); end

Show 10 older comments

Lindsay Mahoney
on 12 May 2013

and what is the for end you mentioned earlier exactly for? and when you say assigning p does it means giving a value to p(1) and p(2) independently or only to p as a whole? and where should i insert plot(S) in which line?

Image Analyst
on 12 May 2013

(Sigh. Then sound of hand slapping forehead) I give up. You don't even know what a for loop is, *and then* you edit the question, essentially removing it. I gave you 99% of the answer. but apparently you can't continue unless I give you all 100%. Really - I'm done here. Good luck.

To find out "for" and "end" are used for, look here: For loops

Answer by Youssef KHMOU
on 11 May 2013

hi, i think there was a similar question just two days a go :

try to enhance this version:

u=1.33; d=0.75; p1=0.44; p2=0.25; p3=1-p1-p2; t=0:1:20; St=zeros(size(t)); St(1)=400; % S(t=0)=S0 for n=1:length(t)-1 r=rand(1); % ~(Uniform) if r>p3 && r<p2 St(n+1)=d*St(n); elseif r>p2 && r<p1 St(n+1)=St(n); elseif r>p1 St(n+1)=u*St(n); end end figure, plot(t,St), xlabel('time (DISCRET)'), ylabel(' PRICE in $');

%

Image Analyst
on 12 May 2013

No, it doesn't even work. It has errors, which I presume is a challenge to you to fix, if you want to.

## 5 Comments

## Walter Roberson

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/75435#comment_148414

Have you asked your classmate Charlene for advice?

## Lindsay Mahoney

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/75435#comment_148415

neither she knows it i need it really bad please :(

## Walter Roberson

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/75435#comment_148426

If she doesn't know the answer, why did she Accept the solution she was given??

## Jan Simon

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/75435#comment_148595

Wow, Lindsay, this is bold. At first you claim the you need the answer

quicklyand try to push us. Then you remove the question, what is unfriendly. This reduces your chances, that you get any answers in the future.## Randy Souza

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/75435#comment_150770

I've restored the original text of this question for future reference, though I have misgivings about it hanging around (it should probably be closed or deleted).

@Lindsay, in the future

pleasedo not edit away your questions--as many contributors have pointed out, it makes it very unlikely that you'll receive help in the future.