matlab question please need answer very quickly.. it is a challenge for you as well !
Show older comments
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.
5 Comments
Walter Roberson
on 11 May 2013
Have you asked your classmate Charlene for advice?
Lindsay Mahoney
on 11 May 2013
Walter Roberson
on 11 May 2013
If she doesn't know the answer, why did she Accept the solution she was given??
Jan
on 13 May 2013
Wow, Lindsay, this is bold. At first you claim the you need the answer quickly and 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
on 24 May 2013
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 please do not edit away your questions--as many contributors have pointed out, it makes it very unlikely that you'll receive help in the future.
Answers (2)
Image Analyst
on 11 May 2013
Edited: 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
13 Comments
Lindsay Mahoney
on 11 May 2013
Lindsay Mahoney
on 11 May 2013
Image Analyst
on 11 May 2013
How much of your homework do you want us to do for you? 100% of it? What part of your homework do you want to do yourself? Just submitting our code to your instructor?
Lindsay Mahoney
on 11 May 2013
Image Analyst
on 11 May 2013
Edited: Image Analyst
on 12 May 2013
But I did. Do you not know how to fill out the inside of case 2 and 3? Well look at the instructions: "remain the same with probability p(2) or go down to dS(t) with probability 1 - p(1) - p(2)". That pretty much says it right there. All you have to do is put that in a loop over t and have some code at the beginning defining what values p, uS, etc. have. I can't really do much more without doing it all for you since there is so little left to do. Here's a little more for you:
randomNumber = rand(1);
if randomNumber < p(1)
% Case 1: Price increases.
S(t) = u * S(t-1);
counts(1) = counts(1) + 1;
elseif randomNumber < p(1) + p(2)
% Case 2: Price stays the same.
counts(2) = counts(2) + 1;
S(t) = S(t - 1);
else
% Case 3: Price decreases.
S(t) = d * S(t-1);
counts(3) = counts(3) + 1;
end
Try to put that in a loop over t, normalize counts after you are all done, and check the normalized counts to see that you are getting the percentages that you specified for each case.
Lindsay Mahoney
on 12 May 2013
Image Analyst
on 12 May 2013
Lindsay! Come on! There's only 8 really exceedingly trivial lines left, and one of them is simply the "end" to the "for" line. You can do it, because you're a smart engineer, aren't you? The lines are (1) assign u, (2) assign d, (3) assign p, (4) assign S(1), (5) assign counts = [0 0 0], (6) "for", (7) "end", and (8) divide counts by the sum to turn it into a percentage to verify that you are getting the correct percentages. There, that's it. That's all you need for the entire program, unless you also want to call plot(S) after it. Honestly, my program doesn't have anything more than my code above plus those 8 lines, which I just told you what to put for them.
Lindsay Mahoney
on 12 May 2013
Edited: Lindsay Mahoney
on 12 May 2013
Image Analyst
on 12 May 2013
Edited: Image Analyst
on 12 May 2013
Lindsay, is this your very first programming class? When one says to assign some variable a value you don't go
assign u
you do
u = 42;
Now, try again.
[Edit] And just to be super super explicit, you don't assign 42 exactly, you assign the value that you want u to be. That YOU want it to be, not me who just picked 42 out of the hat. For example, you might want it to be 1.03 or whatever.
Lindsay Mahoney
on 12 May 2013
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.
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 $');
%
1 Comment
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.
Categories
Find more on Creating and Concatenating Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!