GithubHelp home page GithubHelp logo

emoen / machine-learning-for-asset-managers Goto Github PK

View Code? Open in Web Editor NEW
438.0 11.0 147.0 2.49 MB

Implementation of code snippets, exercises and application to live data from Machine Learning for Asset Managers (Elements in Quantitative Finance) written by Prof. Marcos López de Prado.

License: Apache License 2.0

Python 100.00%
correlation machine-learning eigenvalue clusters density

machine-learning-for-asset-managers's People

Contributors

emoen avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

machine-learning-for-asset-managers's Issues

cMDA

For the cMDA function in ch6_feature_importance_analysis.py, should the following code be outside of train test for loop? The mean score is for cross vaildation calcualted on cluster level.

    imp=(-1*scr1).add(scr0,axis=0)
    imp = imp/(-1*scr1)
    imp = pd.concat({'mean':imp.mean(), 'std':imp.std()*imp.shape[0]**-.5}, axis=1)
    imp.index=['C_'+str(i) for i in imp.index]

Some typos in the execution sample code

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()

ModuleNotFoundError: No module named 'ch4_optimal_clustering'

When used as a package, the description from ch4_optimal_clustering import clusterKMeansBase in l13 of "ch6_feature_importance_analysis.py" causes the error "ModuleNotFoundError: No module named 'ch4_optimal_clustering'". The reference needs to be changed to an explicit relative reference from .ch4_optimal_clustering import clusterKMeansBase.

AttributeError: 'NoneType' object has no attribute 'labels_'

When I run the script called 'ch7_portfolio_construction' I get the following error:

AttributeError Traceback (most recent call last)
in
39 cov1 = pd.DataFrame(cov1, index=cols, columns=cols)
40 corr1 = mp.cov2corr(cov1)
---> 41 corr1, clstrs, silh = oc.clusterKMeansBase(pd.DataFrame(corr0))
42
43 # # code snippet 7.4 - intracluster optimal allocations

D:\User\Desktop\ch4_optimal_clustering.py in clusterKMeansBase(corr0, maxNumClusters, n_init, debug)
56 print("********")
57
---> 58 newIdx = np.argsort(kmeans.labels_)
59 #print(newIdx)
60

AttributeError: 'NoneType' object has no attribute 'labels_'

Can you please help me to fix this bug? Thank you!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.