Created
December 3, 2017 14:43
-
-
Save ganeumann/adaf08ab7910faa27bebed9208cae35f to your computer and use it in GitHub Desktop.
Simulate VC portfolios, calculate percent above benchmarks
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
def vcdraws(alpha,n): | |
# prob density distribution = 1/3 0x, 1/3 1x, 1/3 power law with alpha=alpha | |
# returns list of n draws from the distribution | |
pn=np.random.randint(0,3, size=n) | |
td = powerlaw.Power_Law(xmin=1.0, parameters=[alpha]) | |
return [td.generate_random(1)[0] if pn[i]==2 else pn[i] for i in range(n)] | |
def vcportdraws(alpha,portsize,runs): | |
# generate runs portfolios of size portsize | |
# returns % of portfolios whose average is above 1..15 in 15-item list | |
numd=portsize*runs | |
ports = vcdraws(alpha,numd) | |
avgs = [average(ports[i:i+portsize]) for i in range(0,numd,portsize)] | |
count=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0] | |
inc = 1./runs | |
for i in avgs: | |
for j in range(15): | |
if i>(j+1): count[j]+=inc | |
return [int(i*1000)/10. for i in count] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment