I need to generate values for variable z (n=100). The variable should be generated using X=mu(X)+error term where mu(z) is mean of z series and error term is drawing from a standard normal distribution with mean 0 and variance equal to 1.
Values should be generated in log form to avoid the possibility of obtaining zero or negative values : z=mu(ln Z)+e where mu(z ln) is mean of natural log of z series. After the series is generated the data should be exponentiated to obtain levels (i.e. z=e^ln z).
I've tried to create the z series by using this script:
n=100;
mean=0;
sd=1;
z1=log(mean+sd); % log form of Z series
z2=normrnd(0,1,n,1); % error term with mean 0 and variance 1
z=exp(z1+z2); % exponentiate data
Do you think that the code is in line with the description? I'm not sure if exponentiating is done correctly by simply using the exp function.
Hi Deb
Could you be a bit more specific on what exactly you are trying to do? Generating the series the way you do (i.e. by taking exp of a normally distributed variable) will give you a lognormally distributed variable. I.e. z in the final row of your code will be lognormally distributed and have an expected value of exp(my+1/2sigma^2). Is this what you are trying to accomplish?
I'm just guessing but are you trying to generate asset paths (i.e. a geometric brownian motion model)?
Regards
/Sebastian Arslanogullari
"Deb " <jackbr20@gmail.com> wrote in message <hcf5a6$gjg$1@fred.mathworks.com>...
> I need to generate values for variable z (n=100). The variable should be generated using X=mu(X)+error term where mu(z) is mean of z series and error term is drawing from a standard normal distribution with mean 0 and variance equal to 1.
>
> Values should be generated in log form to avoid the possibility of obtaining zero or negative values : z=mu(ln Z)+e where mu(z ln) is mean of natural log of z series. After the series is generated the data should be exponentiated to obtain levels (i.e. z=e^ln z).
>
> I've tried to create the z series by using this script:
>
> n=100;
> mean=0;
> sd=1;
> z1=log(mean+sd); % log form of Z series
> z2=normrnd(0,1,n,1); % error term with mean 0 and variance 1
> z=exp(z1+z2); % exponentiate data
>
> Do you think that the code is in line with the description? I'm not sure if exponentiating is done correctly by simply using the exp function.
On Oct 31, 5:47 am, "Deb " <jackb...@gmail.com> wrote:
> I need to generate values for variable z (n=100). The variable should be generated using X=mu(X)+error term where mu(z) is mean of z series and error term is drawing from a standard normal distribution with mean 0 and variance equal to 1.
>
> Values should be generated in log form to avoid the possibility of obtaining zero or negative values : z=mu(ln Z)+e where mu(z ln) is mean of natural log of z series. After the series is generated the data should be exponentiated to obtain levels (i.e. z=e^ln z).
>
> I've tried to create the z series by using this script:
>
> n=100;
> mean=0;
> sd=1;
> z1=log(mean+sd); % log form of Z series
> z2=normrnd(0,1,n,1); % error term with mean 0 and variance 1
> z=exp(z1+z2); % exponentiate data
>
> Do you think that the code is in line with the description? I'm not sure if exponentiating is done correctly by simply using the exp function.
Hi Sebastian and thank you for your reply. I'm just trying to generate values that can only have positive values. I understand that lognormal variable is always positive but I'm not sure why in the literature there is examples saying that the generated series should be exponentiated in order to get levels (what does it mean "to get levels"?).
Deb
PS. TideMan: Knowledge is power, but it a sign of wisdom to share it with others.
What the literature is saying is that if you generate a random vector of normally distributed variables and take the exp, you will receive a vector of lognormally distributed variables.
The mean will be as I wrote in my answer, i.e. if you want the mean of the lognormally distributed values to be my, you should subtract 1/2sigma^2 before taking exp, e.g.
x = log(2)+randn(10000,1); % Normal with mean 2 and variance 1
xpos = exp(x-0.5); % lognormal with mean 2
Regards
Sebastian
"Deb " <jackbr20@gmail.com> wrote in message <hd375k$bem$1@fred.mathworks.com>...
> Hi Sebastian and thank you for your reply. I'm just trying to generate values that can only have positive values. I understand that lognormal variable is always positive but I'm not sure why in the literature there is examples saying that the generated series should be exponentiated in order to get levels (what does it mean "to get levels"?).
>
> Deb
>
> PS. TideMan: Knowledge is power, but it a sign of wisdom to share it with others.
On Nov 7, 8:21 pm, "Deb " <jackb...@gmail.com> wrote:
> Hi Sebastian and thank you for your reply. I'm just trying to generate values that can only have positive values. I understand that lognormal variable is always positive but I'm not sure why in the literature there is examples saying that the generated series should be exponentiated in order to get levels (what does it mean "to get levels"?).
>
> Deb
>
> PS. TideMan: Knowledge is power, but it a sign of wisdom to share it with others.
Well, here's another maxim (I'll take the credit for it):
She who does her own homework gains more than she would by getting
others to do it for her.
Tags for this Thread
Add a New Tag:
Separated by commas
Ex.: root locus, bode
What are tags?
A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.
Anyone can tag a thread. Tags are public and visible to everyone.
NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for
all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content.
Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available
via MATLAB Central.
Read the complete Terms prior to use.