-
Notifications
You must be signed in to change notification settings - Fork 0
/
run_portfolio.py
173 lines (130 loc) · 4.82 KB
/
run_portfolio.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
from collections import Counter
import random
import math
###
# Parameters of assumptions
###
# How many initial investments and avg check size
num_seed_rounds = 50
invested_per_seed_round = 0.5
# Probabilities of different outcomes (prob, outcome multiple)
outcome_probs_seed = [ [0.01, 100], # N% chance of Mx return
[0.03, 20],
[0.03, 10],
[0.03, 6],
[0.25, 1],
[0.65, 0]]
follow_on_pct = 0.5 # % of deals in which fund invests in next round
invested_per_follow_on = 1.0 # avg size of follow-on investment
outcome_probs_follow = [ [0.02, 30],
[0.06, 15],
[0.06, 8],
[0.06, 4],
[0.30, 1],
[0.50, 0]]
# number of simulated portfolios to generate
num_simulations = 10000
# constants
fund_size = (num_seed_rounds * invested_per_seed_round) +\
(num_seed_rounds * follow_on_pct * invested_per_follow_on)
###
# Classes
###
class Investment:
def __init__(self, amt_in, outcome, is_seed=True):
self.is_seed = is_seed
self.amt_in = amt_in
self.outcome = outcome
@property
def amt_out(self):
return (self.outcome * self.amt_in)
class Portfolio:
def __init__(self, investments):
self.investments = investments
@property
def total_invested(self):
return sum([i.amt_in for i in self.investments])
@property
def total_returned(self):
return sum([i.amt_out for i in self.investments])
@property
def return_multiple(self):
return ((self.total_returned*1.0) / self.total_invested)
def __str__(self):
l = ['invested: %s' % self.total_invested,
'returned: %s' % self.total_returned,
'return_multiple %s' % self.return_multiple,
'num_deals_total %s' % len(self.investments),
'num_deals_seed %s' % len([i for i in self.investments if i.is_seed]),
'num_deals_follow %s' % len([i for i in self.investments if not i.is_seed]),
]
return '%s' % l
###
# Funcs
##
def validate_params():
if (sum([x[0] for x in outcome_probs_seed]) != 1.0):
raise Exception("Seed probabilities don't add to 1! ")
if (sum([x[0] for x in outcome_probs_follow]) != 1.0):
raise Exception("Follow on probabilities don't add to 1! ")
def create_portfolio():
investments = []
# Seed rounds
for i in range(0, num_seed_rounds):
r = random.random()
prob_sum = 0
for (cur_prob, cur_outcome) in outcome_probs_seed:
prob_sum += cur_prob
if (r <= prob_sum):
investments.append(Investment(invested_per_seed_round, cur_outcome))
break
# Follow on
for i in range(0, num_seed_rounds):
if (random.random() > follow_on_pct):
continue # did not follow on
r = random.random() # for now, make them uncorrelated
prob_sum = 0
for (cur_prob, cur_outcome) in outcome_probs_follow:
prob_sum += cur_prob
if (r <= prob_sum):
investments.append(Investment(invested_per_follow_on, cur_outcome, is_seed=False))
return Portfolio(investments)
def run_simulations(num_iters):
portfolios = []
for i in range(0, num_iters):
cur_portfolio = create_portfolio()
portfolios.append(cur_portfolio)
# print a few, for debugging
print('Sample portfolios:')
for p in portfolios[0:10]:
print(' P: %s' % p)
print('# of portfolios with different multiple returns')
returns_counter = Counter([math.floor(p.return_multiple) for p in portfolios])
for (ret, cnt) in sorted(returns_counter.items()):
pct = 100 * ((cnt*1.0) / num_iters)
print(' %sx - %s (%0.0f%%)' % (ret, cnt, pct))
print('# of portfolios with different multiple returns (to 0.1x)')
returns_counter = Counter([round(p.return_multiple,1) for p in portfolios])
cum_pct = 0
for (ret, cnt) in sorted(returns_counter.items()):
pct = 100 * ((cnt*1.0) / num_iters)
cum_pct += pct
stars = '*' * int(pct*10)
print(' %sx - %s (%0.0f%%) (%0.0f%%) %s' % (ret, cnt, pct, cum_pct, stars))
###
# main()
###
if __name__ == "__main__":
# for dev
# random.seed(31331)
print('starting...')
print('validating params...')
validate_params()
print('Parameters')
print(' $%0.0fm fund which makes %s $%sm seed investments.' %\
( fund_size, num_seed_rounds, invested_per_seed_round))
print(' Follows on with $%sm, %s of the time.' % (invested_per_follow_on, follow_on_pct))
print('')
print('Running portfolio simluation...')
run_simulations(num_simulations)
print('done.')