Take the 2-minute tour ×
Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

I was trying to emulate a random currency value, and first thing I thought was to start with value 1 and then iteratively add, say, Rand(-.1, .1), which is a function call that gives me a random number between -.1 and .1. I then realized this could take my currency's value to less than zero, which would make no sense.

So I figured every new value should be proportional to the old value, and tested multiplying the value times Rand(0, 2) iteratively. My intuition behind it was that since is as likely for Rand(0, 2) to give a number < 1 than a number > 1, the value is as likely to increase as is to decrease. But then for every test I ran the value dropped quickly to almost zero. So I gave Rand(0, e) (e is the constant 2.718...) a try and it seemed to magically work (I also tried with Rand(0, 3) and it grew way above 1 every time).

This was really just a wild guess, and my question is, was my guess right or is this just a coincidence, and if it was, why does it work?

share|improve this question
add comment

1 Answer

up vote 3 down vote accepted

Your guess is right :

$$ Y_n=\prod_{i=1}^n X_i$$ with $X_i$ independent random variable uniform on (a,b).

Let $Z_n=\log(Y_n)$, then $$Z_n=\sum_{i=1}^n \log(X_i)$$

What is the distribution of $\log(X_i)$ ?

$$\mathbf P(\log(X_i)<x)=\mathbf P(X_i<e^x)$$

So for any $x\in(\log(a),\log(b))$, $\mathbf P(\log(X_i)<x)=\frac{e^x-a}{b-a}$

Hence $\log(X_i)$ has a density function $f(x)=\frac{e^x}{b-a}$ if $x\in(log(a),log(b))$, else $f(x)=0$.

Hence $\mathbb E(\log(X_i))=\int_{\log(a)}^{\log(b)}\frac{x.e^x}{b-a}dx=\left[\frac{x.e^x}{b-a}\right]_{\log(a)}^{\log(b)}-\int_{\log(a)}^{\log(b)}\frac{e^x}{b-a}dx=\frac{b\log(b)-a\log(a)}{b-a}-1$

if $a=0$, $\mathbb E(\log(X_i))=\log(b)-1$. Note that variance of $\log(X_i)$ is defined and finite. So we can use the central limit theorem to say that $Z_n$ will ultimately follow a normal distribution of mean $n.(\log(b)-1)$.

Of course if $b=e$, then mean is equal to $0$, and $\lim\mathbf P(-{n}\epsilon<Z_n<{n}\epsilon)=1$. So for $b=e$ : $$\forall\epsilon\lim_{n\rightarrow\infty}\mathbf P(e^{-\epsilon.{n}}<Y_n<e^{\epsilon.{n}})=1$$

Any other value of $b$ will make $Y_n$ quickly grows towards 0 or $+\infty$.

In particular, for $b=e$, $Y_n$ can grow quite large or small (due to the exponential factor), but it will eventually come back to 1.

EDIT :

For what you want to do, it would be better to simulate the logarithm of the value. Start from $v=0$, and at each step, add a random value between $-1$ and $1$. The value of your currency would be then $e^v$. It would be much more stable around $1$.

share|improve this answer
    
"So we can use the central limit theorem to say that Zn will ultimately follow a uniform distribution" This is definitely not what the CLT is saying. –  Did Dec 4 '13 at 9:22
    
ok, it's $\frac{Z_n}{n}$. –  Xoff Dec 4 '13 at 9:23
    
Nope, Zn/n is as far as can be from being uniform. –  Did Dec 4 '13 at 9:24
    
Oh, sorry , I mean normal of course ^^ –  Xoff Dec 4 '13 at 9:24
    
Then (Zn-nE(logX))/sqrt(n). –  Did Dec 4 '13 at 9:25
show 5 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.