Monday, October 13, 2008

Funny Math

The question is what happens to a value if you increment or decrement it by a uniformly distributed value centered around zero?

As a disclaimer this isn't really the ha-ha kind of funny.  Its the other kind of funny.

To start this off lets ask a a simpler question.  Lets say you have a $100 dollars invested in a stock.  Today it goes down 10% tomorrow it goes up 10%, how much to you have? 100- 10% =$90.  90 + 10% = $99.  Rats you lost a dollar, its unfortuante but pretty straight forward.

Now lets say one out of every two days your stock goes up 10% and every other day it goes down 10%.  From the first example it is pretty easy to see that we would expect our value to steadily decline, and if we enumerate the values we can see that indeed that is the case.


DayMovementValue
0--100
110%110
2-10%99
310%108.9
4-10%98.01
510%107.81
6-10%97.03
710%106.73
8-10%96.06

From there is not so hard to see that it probably won't be any different using a random distribution than with set values.  But lets find out.  I am sure there is a way to prove this in a proof and or show it with a closed form formula.  But coming up with the formula/proof escapes me right now.  So we'll fall back to simulating it.

[TestMethod]

public void RandomWalking()

{

    for (int round = 0; round < 10; round++)

    {

        double start = 1000;

        Random randNumber = new Random((int)DateTime.Now.Ticks);

        double bias = 0;

        for (int i = 0; i < 10000; i++)

        {

            double diff = randNumber.Next(-100, 100) / 1000.0;

            start *= 1 + diff;

            bias += diff;

        }

        Console.WriteLine("1000 -> {0}, bias:{1}", start, bias);

    }


}


Generates:

1000 -> 0.329915187578686, bias:8.688
1000 -> 3.14340291320618E-06, bias:-2.75600000000002
1000 -> 5.88119745218127E-06, bias:-2.26699999999999
1000 -> 4.1356376989622E-10, bias:-12.037
1000 -> 1.38040135841817E-06, bias:-3.68200000000001
1000 -> 4.46395869719455E-09, bias:-9.291
1000 -> 1.26886933354314E-06, bias:-3.65099999999999
1000 -> 2.42195007654241E-08, bias:-7.97599999999999
1000 -> 9.08609341706222E-08, bias:-6.48599999999998
1000 -> 0.000263032702826233, bias:1.545

It appears that I wasn't lying.  So that's nice.  This shows that in 10,000 iterations of uniformly distributed random motion in almost every scenario almost all the original value was destroyed.

One observation that can be made from the above data set is that when the random values aren't quite centered around zero, specifically when they are a bit higher there is relatively less values lost, which makes a lot of sense.  

Which left me curious what center value leaves things more or less intact.  From trial and error it looks like if the distribution is centered around .00105 things stay pretty stable.  I imagine this is a very famous theorem.  Anyone know what its called?  I'll try to find out for the next post.

0 comments: