Machine-Learning-for-Asset-Managers icon indicating copy to clipboard operation
Machine-Learning-for-Asset-Managers copied to clipboard

Some typos in the execution sample code

Open Y-Saki26 opened this issue 2 years ago • 0 comments

There are some parts that do not work due to typos or name errors when the module is executed as a script.

ch3_metrics.py: from l38

- def mutualInfor(x,y, norm=False):
+ def mutualInfo(x,y, norm=False):
    #mutual information
    bXY = numBins(x.shape[0], corr = np.corrcoef(x,y)[0,1])
    cXY = np.histogram2d(x,y, bXY)[0]
    iXY = mutual_info_score(None, None, contingency=cXY)
    if norm:
-        hX = ss.entropy(np.histogram(x, bins)[0]) #marginal 
-        hY = ss.entropy(np.histogram(y, bins)[0]) #marginal
+        hX = ss.entropy(np.histogram(x, bXY)[0]) #marginal 
+        hY = ss.entropy(np.histogram(y, bXY)[0]) #marginal
        iXY /= min(hX, hY) #normalized mutual information

ch7_portfolio_construction.py: from l120

    # code snippet 7.4 - intracluster optimal allocations
    # step 2. compute intracluster allocations using the denoised cov matrix
    wIntra = pd.DataFrame(0, index=cov0.index, columns=clstrs.keys())
    for i in clstrs:
-        wIntra.loc[clstrs[i], i] = minVarPort(cov1.loc[clstrs[i], clstrs[i]]).flatten()
+        wIntra.loc[clstrs[i], i] = minVarPort(corr1.loc[clstrs[i], clstrs[i]]).flatten()

Y-Saki26 avatar Aug 04 '23 13:08 Y-Saki26