I’ve read a book about financial mathematical model used in Wall Street. This book describes about the people who invented the financial models which become state-of-the-art technologies nowadays.

I’m not familiar with finance detail but the book was very interesting. The models introduced in this book was simple. So I want to write a tiny program to confirm the detail of these models.

## Random Walk model of profit rate

In the second chapter of the book, random walk model of profit rate is described. It means profit rate can be transitioned completely at random. We cannot predict the profit rate of next time because it rises at 50% and falls at 50% as well. This is random walk. A mathematician, Osborne find a profit rate is transitioned at random. So profit rate of stock value can be described below.

```
%matplotlib inline
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
```

```
def random_walk(n):
ret = [0]
for i in range(n):
if np.random.random() > 0.5:
# Rising profit rate
ret.append(ret[-1] + 0.01)
else:
# Falling profit rate
ret.append(ret[-1] - 0.01)
return ret
# We compute 100 trials
for i in range(100):
plt.plot(random_walk(1000))
plt.xlabel('Time')
plt.ylabel('Interest rate')
```

Osborne also find the profit rate at the time is distributed according to normal distribution whose mean is 0. The mean of profit rate at the future is 0 unfortunately. We cannot expect any growth of profit rate in average.

```
from scipy.stats import norm
last_values = [random_walk(1000)[-1] for n in range(2000)]
x = np.arange(-5,5,0.01)
plt.hist(last_values, bins=30)
```

Surely, the profit rate after 1000 time unit seems to be obeyed to normal distribution.

# Stock value transition

How about stock value itself? According to Osborne, if profit rate is decided by random walk model, the stock value distribution can be log-normal distribution. Let’s plot the transition of stock value with above profit rate model.

```
def random_walk_value(n, initial_value):
# Collect profit rate transition
interest_rates = random_walk(n)
# Initial stock value
ret = [initial_value]
for i in range(n):
# Calculate revenue with given profit rate
revenue = ret[-1] * interest_rates[i]
ret.append(ret[-1] + revenue)
return ret
# Compute 500 trials
for i in range(500):
plt.plot(random_walk_value(20, initial_value=10.0))
```

Now we can confirm the stock value at the specific time unit is distributed according to log-normal distribution.

```
last_values = [random_walk_value(20)[-1] for n in range(1000)]
x = np.arange(-5,5,0.01)
plt.hist(last_values, bins=10)
```

The histogram of the stock value at the 20 time unit is plotted. It looks like log-normal distribution.