Posts

LVQ and Machine Learning for Algorithmic Traders – Part 1

Algorithmic traders across all spectra of asset classes, often face a rather daunting challenge.

What are the best inputs for an algorithmic trading strategy’s parameter space?

Different algorithmic trading strategies (whether manual or automated) will each have their own unique set of parameters that govern their behaviour.

Granted.. Genetic and Walk-Forward Optimization will help algorithmic traders establish what input values (or ranges thereof) in chosen parameter spaces, yield favourable results historically.

They will also help traders identify optimal time periods over which to re-optimize “the currently optimized parameter space”…. yes, that could indeed, get pretty messy.

While this approach may or may not yield robust parameter inputs, several questions still remain in algorithmic traders’ minds:

1) Should absolutely all parameters be optimized, or just some? If so, which ones?

2) What is the relevance and unique importance of each parameter in the trading strategy?trading strategy optimization questions

Why is this important for Algorithmic Traders?

Selecting the right parameters in your trading algorithm can be the difference between:

  • Average performance with a large number of parameters -> painfully long optimization times,
    or,
  • Fantastic performance with a smaller number of parameters -> much shorter optimization times.

What is the solution?

Selecting the most appropriate parameters is a practice known as Feature Selection in the Machine Learning world, a vast and complex area of research and development.

Needless to say it cannot be encapsulated in one single blog post, which therefore implies that there will be more blog posts on this subject in the very near future 🙂

R (Statistical Computing Environment)

R (Statistical Computing Environment)

For now, we will focus on estimating “the most important” parameters in a trading strategy, using a bit of machine learning in R.

Specifically, we will make use of the caret (short for Classification and Regression Training) package in R, as it contains excellent modeling functions to assist us with this Feature Selection problem.

Lastly, we will use a small constructed sample of 1,000 id|feature|target records as the dataset, to demonstrate Linear Vector Quantization (the solution).

 

Step 1 – Load the “caret” machine learning library in R

> library(caret)

Step 2 – Prepare the data

Construct a dataset containing 1,000 training data points in CSV form.

Making sure you’re in the directory where the training data resides, type the following commands in your R console:

> train.blogpost <- read.csv("data.csv", head=T, nrows=1000)

We need only the “feature” and “target” column values in the dataset. Type the following command in your R console to achieve this:

train.blogpost <- train.blogpost[,grep("feature|target",names(train.blogpost))]

Step 3 – Construct an LVQ Model on the data.

> model.control <- trainControl(method="repeatedcv", number=10, repeats=3)> model <- train(as.factor(target)~., data=train.blogpost, method="lvq", preProcess="scale", trControl=model.control)

Step 4 – Retrieve the “importance” of each “feature” from the computed model.

> importance <- varImp(model, scale=FALSE)> print(importance)
loess r-squared variable importance
only 20 most important variables shown (out of 21)Overall
feature2  0.011949
feature18 0.010770
feature7  0.010556
feature16 0.010522
feature5  0.010400
feature11 0.009825
feature1  0.009673
feature14 0.009672
feature3  0.009663
feature13 0.008916
feature21 0.008846
feature15 0.008737
feature10 0.008616
feature17 0.008180
feature19 0.007864
feature12 0.005575
feature9  0.005268
feature8  0.005124
feature20 0.005089
feature4  0.005052
>

Step 5 – Visualize the importance of each feature.

plot(importance)

LVQ Importance Visualization - Machine Learning in R

LVQ Importance Visualization – Machine Learning in RThe plot of “feature importance” above clearly shows that features 12, 9, 8, 20, 4 and 6 have little impact on the outcome (the “target”), compared to the rest of the features.

To put it into context – in a trading strategy, these features may well have been parameters called:

Stop Loss 1, Stop Loss 2, Take Profit 1, Take Profit 2, RSI Top, RSI Bottom.. and so on.

Conclusion

By conducting LVQ analysis on optimization results, algorithmic traders can save themselves not only time, but lost accuracy.

Machine learning techniques of this nature, greatly reduce the time a trader needs to spend on any optimization problem.

By ascertaining the relevant importance of parameters in this manner, traders can not only simplify their algorithms, but also make them more robust than previously possible with a larger number of parameters.

Additional Resource: Learn more about DARWIN Portfolio Risk (VIDEO)
* please activate CC mode to view subtitles.

Do you have what it takes? – Join the Darwinex Trader Movement!

 

Quantitative Trader

Why Quantitative? – Serious Algorithmic Trading Series (Part 2)

Quantitative Trading

Quantitative Trading

In case you haven’t already, you may wish to read the first two posts of the Serious Algorithmic Trading Series, here and here.

Many individual traders will often hear the term “Quant” and may visualize either:

  1. A sharply dressed City trader working in a hedge fund, sat in front of his Bloomberg or Thomson Reuters Eikon terminals, or
  2. A stocky chap wearing a Batman t-shirt, with telescopes for specs (and possibly a doctorate in Nuclear Physics), sat in his basement trading room pouring over mathematical models, following a staple fast food diet.

For the avoidance of doubt: you do NOT need a university degree to become a Quantitative Trader (though having one does come in very handy, IF you were paying attention in class!)

Now, both these individuals above likely followed a similar academic (or independent learning) path to their current disposition.

It’s even possible that the City trader was once a frequent visitor to his own basement trading room, before being spotted by a financial recruiter and beamed up to the 39th floor.

This prompts a few questions:

Why do Quants become Quants in the first place?

Quantitative Trader

Quantitative Trader

There are numerous advantages to quantitative trading, advantages that not only reduce the financial impact of discretionary decision-making going wrong, but also help measure performance in a manner that permits efficient future learning.

For the purpose of distinction, it must be noted that unlike algorithmic trading that employs technical analysis, the quantitative approach to algorithmic trading involves primarily Bayesian Statistics and Time Series Analysis.

These are more effective methods of generating uncorrelated risk-adjusted returns, all too often ignored by the retail fundamental or technical analyst. Those who recognize their advantages, naturally progress down a path to becoming Quants.

Is Quantitative Trading reserved for just institutions?

In short, no it isn’t. Find out why in part 1 of this series here.

Why should this interest retail traders?

The world of quantitative trading extends far beyond that of technical moving average crossovers, candlestick patterns, martingales, grids, and off-the-shelf trading systems celebrating their latest and greatest “trading secrets” that resulted in their most sensationally overfitted backtests to date.

It does so because the markets are a much more complex phenomenon than we think, and undergo several micro-structure and regime changes frequently.

Darwinex - The Open Trader Exchange

Darwinex – The Open Trader Exchange

Note: To protect investors from overfitted systems, all strategies listed as DARWINS on the Darwin Exchange are analyzed for proficiency in 12 investment attributes. Investors therefore have the ability to immediately assess whether a strategy’s current equity curve is likely to persist in future or not, something standard backtest results cannot reveal.

Indeed one could go as far as to say that the market is a stochastic process in and of itself.

Generating uncorrelated risk-adjusted returns in as seemingly stochastic an environment as this, is therefore a mammoth task.

Why more retail traders haven’t then embraced quantitative methods (that enable the discovery and subsequent exploitation of inefficiencies in stochastic processes) can only be attributed to a lack of awareness and “approachable” learning resources.

We will aim to address this in Part 3 of this series, “The Quantitative Approach to Algorithmic Trading”, and all subsequent posts that fall in the same category.

Advantages of Quantitative Trading

  1. Alpha is an elusive beast.

    Alpha is difficult to discover, gradually loses its profitability as more capital is allocated to its exploitation, and inevitably transitions from a source of risk-adjusted profitability to a source of risk.

    Quantitative methods allow traders to not only discover and exploit alpha, but to do so in a manner that maximises its profitability horizon and minimizes risk of decay.

    Quantitative analysis also facilitates the creation of statistical testing frameworks that can forecast risk of alpha decay in advance.

    Note: DARWIN investors benefit from a Scalability/Capacity investment attribute  displayed on each asset listed on the Darwin Exchange. It is a score ranging from 1 to 10 that indicates how much capital the underlying strategy can support without decay. The higher the score, the more assets under management (AuM) it can attract.

  2. Statistically Robust vs. Regular Backtesting

    Quantitative traders can make use of statistical tools that add another layer of validity to backtests.

    In simple terms, if you’re currently examining a backtest and taking its results with a “grain of salt”, substitute the latter with some rigorous quantitative testing and you have a much more credible (or not) backtest on your hands.

  3. Quantitative Trading encourages thinking in “Portfolios”

    Common behaviours among a large segment of individual traders include deploying a single trading strategy on a single asset, or deploying the same strategy on a mix of assets, without careful consideration given to weighted allocation as would be the case in an institutional setting.

    In the former’s case, the trader has put all his/her eggs in one basket.

    In the latter’s case, the trader has employed logic that goes something like “if it’s a robust strategy, it will perform well in all markets, under all market conditions.”

    Unfortunately, this logic is prone to leading traders into intractable situations where the lack of an appropriate risk-adjusted allocation matrix may lead to unexplained underperformance.

    Construct DARWIN Portfolios

    Construct DARWIN Portfolios

    Quantitative analysis allows traders to construct portfolios of assets or strategies (or both), such as to maximize their aggregate profitability while minimizing their aggregate risk. This is simply not possible to achieve without quantitative methods being employed.

    Note: Investors on the Darwin Exchange can construct uncorrelated portfolios of DARWINS using our proprietary diagnostics toolkit. Twelve investment attributes (as of Darwinex Reloaded) allow investors to not only select DARWINS that match their criteria for investment, but also reduce overall portfolio risk through adequate diversification. As of Darwinex Reloaded, investors are even rewarded for diversifying their DARWIN portfolios, through the introduction of Diversification Rebates.

One of the most commonly voiced disadvantages of Quantitative Trading is that it’s a complex discipline to master.

So is learning to drive a car for the very first time. The right instructor can be the difference between a confident future driver and a jittery one.

Quantitative trading is no different. Over the course of these posts (that aim to make the complex simple), the best most approachable educational material will always be referenced for the reader’s benefit.

The fruits of a Quant’s labour are far sweeter than one can imagine. You will be well served by visiting the Darwin Exchange Leaderboard for inspiration.

The next post will begin our journey into the Quantitative Approach to Algorithmic Trading.

Trade safe,
The Darwinex Team

Do you have what it takes? – Join the Darwinex Trader Movement!

Darwinex - The Open Trader Exchange

Darwinex – The Open Trader Exchange