Merlin Overview
Merlin is a strategy optimization and portfolio optimization tool designed for quantitative traders and portfolio managers. It combines the capabilities of MesoSim for Options Strategy backtesting with Machine Learning and statistical techniques from Q-API to discover profitable trading patterns and optimize capital allocation.
Key features:
- Predictor discovery: Identify features with strong predictive power for your strategy using Cramér's V statistical test and MIFS (Mutual Information based Feature Selection) model
- Strategy optimization: Implement the Stepwise Ensemble for Trade Selection (SETS) model with Linear, Logistic, and Quadratic regression support to improve strategy performance using walkforward testing
- Portfolio optimization: Apply Portfolio Allocation methods - like Mean-Variance Optimization or Kelly Criterion - to optimize across multiple trading strategies and assets
Merlin's Source Code is provided to the customer and serves as a standalone, ready to use tool as well as an extensible library for custom applications.
Installation
Merlin can be installed from GitHub Repo or from Google Drive.
Dependencies
Python 3.11 or higher is required to run Merlin. If you don't have Python installed, you can download it from the official website or use other distributions, such as Anaconda.
Alternatively, you can use Google Colab to run Merlin in Cloud environment from your browser.
In Colab, from Google Drive
-
Follow the installation steps outlined in the Notebooks page
-
Find the latest version in the Google Drive folder
-
Run the following command to install Merlin:
!pip install /content/drive/MyDrive/deltaray-software-releases/merlin/merlin-VERSION.whlWhere
VERSIONis the desired version of Merlin.NOTEThe exclamation mark (
!) is required to run shell commands in Colab. Therefore, if you are running Merlin in Colab, you should prefix all Merlin commands with!. -
Run Merlin commands using the
!merlinprefix, e.g.:!merlin --help
You can find Sample notebooks using Merlin in the Notebooks section.
In your machine, from GitHub
-
Login with your GitHub account and create a personal access token IMPORTANT: personal access tokens are like passwords, keep them secure and do not share them.
-
Make sure you have access to Merlin's source repository with your GitHub User: https://github.com/deltaray-io/merlin If you can't access the page please reach out to Support to request access to the repository.
-
Create a working directory for the installation and navigate to it.
mkdir merlin-workdir
cd merlin-workdir -
Prepare and activate a Python Virtual Environment hosting this installation
python3 -m venv ./venv
source ./venv/bin/activate -
Install Merlin using the following command:
pip install git+https://<token>@github.com/deltaray-io/merlin.git@1.2.2Your personal access token should be placed in the URL instead of
<token>. The 1.2.2 version is an example. Replace it with the desired version.Release locationYou can find the versions in the GitHub Releases page.
-
Start Merlin
merlin --help
Next Steps
Please check out the Features section of the documentation to learn more about Merlin's capabilities:
You can find example runs in the Notebooks section.
Workflow
Start with Predictor Discovery to identify the most promising features for your strategy.
Then apply Strategy Optimization with Stepwise Selection using a single model to see which predictors would have been chosen by the model fully automatically. Based on the predictor discovery and stepwise's results create specific models allocating 2 to 3 predictors to each model. Leave room for an additional model where Stepwise can allocate the remainder of predictors automatically.
Apply the above Strategy Optimization process to all of your strategies and put them into a portfolio. Run the Portfolio Optimizer to find the optimal allocation for the strategies.
Re-run the process regularly (e.g. weekly) to obtain the Strategy Inclusion list for each period. Within each period (e.g. daily) run the Strategy Optimizer with Last Fold Enabled to obtain the Optimized Trade Plans.
Finally, import the Optimized Trade Plans (strategy definitions) to MesoLive and trade them based on the Portfolio Optimizer's allocation.
Further steps
Feature Engineering provides details on customizing and extending the features used in Merlin.
Merlin can also be used as a Python Library to build custom optimizers tailored to your specific needs. You can find details on how to set-up a development environment in the Dev Setup page.
License
Feel free to extend and fine-tune it to match your use-case. Please avoid sharing Merlin's source code publicly.
For full details please refer to the LICENSE