Recursive bisection function to matlab from python
Mostrar comentarios más antiguos
Hi,
Could some one help me to translate this code from python to matlab? (it's an intersting code develped by Marcos López de Prado)
def getRecBipart(cov,sortIx):
# Compute HRP alloc
w=pd.Series(1,index=sortIx)
cItems=[sortIx] # initialize all items in one section
while len(cItems)>0:
cItems=[i[j:k] for i in cItems for j,k in ((0,len(i)/2), len(i)/2,len(i))) if len(i)>1]
# bi-section
for i in xrange(0,len(cItems),2): # parse in pairs
cItems0=cItems[i] # section 1
cItems1=cItems[i+1] # section 2
cVar0=getClusterVar(cov,cItems0)
cVar1=getClusterVar(cov,cItems1)
alpha=1-cVar0/(cVar0+cVar1)
w[cItems0]*=alpha # weight 1
w[cItems1]*=1-alpha # weight 2
return w
The Tricky part is this one:
cItems=[i[j:k] for i in cItems for j,k in ((0,len(i)/2), len(i)/2,len(i))) if len(i)>1]
Is the part where he use the recursive.
Thank you! Best Regards
Cihan
Respuestas (1)
Thomas
el 20 de Jun. de 2018
0 votos
Did you ever get anywhere with this?
Categorías
Más información sobre Call Python from MATLAB en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!