Popular Libraries

MlFinLab

Introduction

MlFinLab is a collection of production-ready algorithms (from the best journals and graduate-level textbooks), packed into a python library that enables portfolio managers and traders who want to leverage the power of machine learning by providing reproducible, interpretable, and easy to use tools. It covers every step of the machine learning strategy creation starting from data structures generation and finishing with backtest statistics.

The mission of Hudson and Thames is to promote the scientific method within investment management by codifying frameworks, algorithms, and best practices to build the world’s central repository of ready to use implementations and intellectual property. For more information, see the Hudson and Thames website. The  Hudson and Thames environment, which includes the MlFinLab library, is currently only available in QC Cloud.

Import Libraries

Follow these steps to import the mlfinlab library:

  1. Open a project.
  2. In the Project panel, click the LEAN Environment field and then click Hundson Thames from the drop-down menu.
  3. Add your MlFinLab API key as a project parameter (for example, mlfinlab-api-key).
  4. Using a parameter keeps your API key safe for sharing project code.

  5. Open one of the code files in your project.
  6. At the top of the code file, add import ht_auth.
  7. In the Initialize method, add the following snippet:
    ht_auth.SetToken(self.GetParameter("mlfinlab-api-key"))
    import mlfinlab as ml

MlFinLab costs £100 (+VAT) per month, per user. Follow these steps to get your API key:

  1. Create a profile on the Hudson & Thames website and log in.
  2. On the dashboard page under MlFinLab, click Buy.
  3. On the MlFinLab page, click Buy.
  4. In the Terms of Use window, accept the terms of use and then click Purchase.
  5. In the Purchase MlFinLab window, enter your payment card details and then click Subscribe Now.
  6. Wait for the success window to display.
  7. On the dashboard page, under MlFinLab, click View.
  8. On the MlFinLab page, click Copy API Key.

Financial Data Structures

Transform unstructured data sets into structured tick, volume, and dollar bars as well as the less common information-driven bars. With MlFinLab you can even generate bars on the go with our online data structures framework. For more information about data structures, see Standard Bars in the MlFinLab documentation.

Labeling Techniques

MlFinLab provides a comprehensive list of labeling techniques, including the following: Raw Returns, Fixed Horizon, Triple-Barrier & Meta-Labeling, and many more. For more information about labeling, see Labeling in the MlFinLab documentation.

Feature Engineering

This section of MlFinLab contains several important tools to manipulate, select and transform raw data into useful features. Feature engineering techniques you can use include: Fractionally Differentiated Features, Structural Breaks, Volatility Estimators, and even Automatic Feature Extraction. For more information about feature engineering, see Feature Importance in the MlFinLab documentation.

Bet Sizing

This section will allow you to optimally size your bets to improve returns or limit downside metrics in alignment with your risk preferences. Methods include Kelly Criterion, EF3M and dynamic bet sizes. For more information about bet sizing, see Bet Sizing in the MlFinLab documentation.

Codependence Measures

Improve your strategies by taking into account measures of codependence between assets in MlFinLab. Choose between correlation-based, information theory and copula-based metrics. For more information about codependence measures, see Measures of Codependence in the MlFinLab documentation.

Generate Sythetic Data

Generate data that simulate important events for example, flash crashes, world-wide economic crises, global pandemics, etc. to assess if an algorithm will fare well for any event. Having an abundance of realistic financial data has never been easier with MlFinLab. Examples of financial data that can be generated include stock prices, stock returns, correlation matrices, retail banking data, and all kinds of market microstructure data. For more information about synthetic data, see Synthetic Data Generation in the MlFinLab documentation.

Clustering Techniques

Discover a wide range of clustering techniques at your fingertips to improve the credibility of your investment strategy. MlFinLab offers both hierarchical clustering techniques and the ability to determine the optimal number of clusters. For more information about clustering techniques, see Clustering in the MlFinLab documentation.

Networks Modeling

Creates beautiful and informative visualizations of financial data, using network theory to describe complex systems such as financial markets. Use graphs such as a Minimum Spanning Tree, creating a mini Flask server using Plotly’s Dash to display the interactive graphs with MlFinLab. For more information about networks modeling, see Networks in the MlFinLab documentation.

Example Algorithm

The following example algorithm demonstrates how to use the mlfinlab library. The algorithm uses the trend_scanning_labels method to determine the trend direction of the Bitcoin-USD pair. If Bitcoin is in an uptrend, the algorithm allocations 100% of the portfolio to Bitcoin. Otherwise, it holds USD. The algorithm achieves a 1.79 Sharpe ratio, outperforming Bitcoin buy-and-hold, which achieves a 1.26 Sharpe ratio over the same time period.

Support

After you purchase MlFinLab, you get access to the Hudson and Thames Slack Community, where you and other quants can answer questions. Hudson and Thames also provide support under consulting.

FAQs

Note the following frequently asked questsions.

How do I install MlFinLab on QuantConnect?

To use MlFinLab on QuantConnect, see Import Libraries.

How do I install MlFinLab on my local machine?

To use MlFinLab on your local machine, see the Client Documentation that Hudson & Thames provides to avoid dependency issues. You receive the MlFinLab Client documentation after your purchase is successful.

Are the Jupyter Notebooks downloadable?

Yes, you can access the notebooks via the Client Documentation and download them.

Does Hudson & Thames provide support?

Yes, they provide support under consulting and you can ask their community on Slack if you have a question.

You can also see our Videos. You can also get in touch with us via Discord.

Did you find this page helpful?

Contribute to the documentation: