Adding a level of randomness

In the simulations an opportunity will have a Gamma distribution and a cost, determined by a quantile of the distribution. Entrepreneurs will have an initial cash position that they can invest in opportunities, which payout, and they consume the maximum of a constant and a constant proportion of their wealth.  In this set up, the ruin time distribution of the investors will depend on the parameters.

Taking a simple case where k=5.0, θ=1.5 and the cost quantile is 3.0, so that the cost of each opportunity is 5.45 and running the following simulation

import numpy as np
import numpy.random
import scipy.stats as stats
from scipy.special import gammaincinv 
import matplotlib.pyplot as plt

# 
# MAIN CODE
#
#Number of runs
N_runs=10000
ruin_time=np.zeros(N_runs)

k=5.0
theta=1.5
q=0.3
cost = np.around( theta*gammaincinv(k,q), decimals=5)

for run in range(N_runs):
 cash = 6.0
 i=0
 while ( (cash >=0.0) and (i<100) ):
  i=i+1
  np.random.seed(22042006+run+i)
  p=np.random.rand()
  repay= np.around(theta*gammaincinv(k,p), decimals=5)
  cash = cash-cost+repay-max(0.8,cash/6.0)
 if (i>=100):
  i=0
 ruin_time[run]=i

non_zero=np.flatnonzero(ruin_time)

hist, bins=np.histogram(ruin_time[non_zero], bins=(np.asarray(range(100))+0.01))
fig = plt.figure()
ax = fig.add_subplot(111)

ax.bar(np.asarray(range(99)),hist)
plt.show()

results in the following distribution of ruin times (the total number of runs is 10,000)

ruin

Making a subtle change, that k~10*Β(2,2) and θ~U(0,3) so that E[k]=1.5 and E[θ]=1.5, and running the following simulation

import numpy as np
import numpy.random
import scipy.stats as stats
from scipy.special import   gammaincinv 
import matplotlib.pyplot as plt

# 
# MAIN CODE
#
#Number of entrapeneurs
N_runs=10000
ruin_time=np.zeros(N_runs)

# If k=10.0*stats.beta.ppf(r,2,2) then E[k]=5
#If theta=3.0*r then E[theta]=1.5
k=5.0
theta=1.5
q=0.3

for run in range(N_runs):
   cash = 6.0
   i=0
   while ( (cash >=0.0) and (i<100) ):
      i=i+1
      r=np.random.rand()
      k=10.0*stats.beta.ppf(r,2,2)
      theta=3.0*np.random.rand()
      cost = np.around( theta*gammaincinv(k,q), decimals=5)
      if (cost<cash): np.random.seed(22042006+run+i)="" p="np.random.rand()" repay="np.around(theta*gammaincinv(k,p)," decimals="5)" cash="cash-cost+repay-max(0.8,cash/6.0)" else:="" if="" (i="">=100):
	i=0
    ruin_time[run]=i

non_zero=np.flatnonzero(ruin_time)

hist, bins=np.histogram(ruin_time[non_zero], bins=(np.asarray(range(100))+0.01))

fig = plt.figure()
ax = fig.add_subplot(111)
ax.bar(np.asarray(range(99)),hist)
plt.show()

then  no entrepeneurs survive more than 100 steps and we get the following distribution with an average ruin time of 13 steps

ruin2

This highlights the effect of random opportunities.

If we use this random allocation of opportunities with q=0.2, we infer that about 58% or the entrepreneurs are ruined by step 20 (with the fixed opportunity distribution, 4% of the entrepreneurs are ruined by step 20).

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s