## jueves, 1 de mayo de 2014

### Expected value of random walk

I found this nice answer where a guy draws a random walk that simulates the stock market.

The remarkable thing is that he talked about the expected distance of the one dimensional random walk from the starting point, after N steps.

It is different from the average distance (taking signs into account), that should be 0.

So, the expected (absolute) distance from the origin (see 1 and 2) is:

And this surprised me. Yeah, you even get PI there.

The math seems nice, I haven't checked it all :-)

Here is a quick simulation: expected_distance.cc.

Here is the output for 1000 steps:

\$ ./random_walk_distance_1000_steps
Theoretical average distance: 25.2313
Empirical average distance: 25.0942

\$ ./random_walk_distance_1000_steps
Theoretical average distance: 25.2313
Empirical average distance: 25.1914

\$ ./random_walk_distance_1000_steps
Theoretical average distance: 25.2313
Empirical average distance: 25.2604

It checks out. I'm glad I know this now.