Recursive bisection function to matlab from python
古いコメントを表示
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
回答 (1 件)
Thomas
2018 年 6 月 20 日
0 投票
Did you ever get anywhere with this?
カテゴリ
ヘルプ センター および File Exchange で Call Python from MATLAB についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!