trading with Artificial Intelligence and humans

An AI trading experiment on Nasdaq 100:

I’ve always wondered if AI could manage investments better than human beings.
As an individual investor I have always suffered from the emotions of fear, euphoria, greed, the rush of making a profit, the reluctance to suffer a loss.
In recent years, Hedge Funds equipped with supercomputers and big data access have claimed to be able to consistently outperform the stock market. This capacity generates alpha, that is, the differential advantage of allocating money in a hedge fund rather than simply buying the reference index (SP500, Nasdaq, etc.).

Naturally, the real information is known only to those who actually work within these alternative investment vehicles.
However, if AI is superior to human intelligence in uncovering recursive patterns in big data, then trading is the ideal field to investigate this.

As a teenager I programmed the Sinclair ZX Spectrum; then, my studies led me into a career in the consulting and energy world.

ZX Spectrum

A few years ago, during a sleepless night spent trying to get my daughter to sleep, I had the idea of searching the internet for the best way to code Machine Learning solutions.
The answer was Python.
Well, I reckoned the power of Python was astonishing. After learning a lot through online courses (coursera, udacity, udemy) plus invaluable reading on Stack Overflow, I started coding again.
In the following months, in which I devoted a few hours a week to coding, a trading engine based on Python’s Machine Learning libraries was born. The name given to this simple platform is
Let’s come back a little bit to address the genesis of the idea.
Stock markets are tough. Between the seventies and the eighties the simple rule that made a lot of traders rich was to buy if short-term moving averages crossed the long-term moving average from below, and to sell in the opposite situation.
Now, if you try to do this by yourself the probability of success is the same as a coin toss; you can get it right once, twice or if you are very lucky ten times in a row, but at the end you will gain 50% of the time and consequently also lose 50% of the time.
While reading about Machine Learning techniques my basic question was: “If a machine observes what happens on the market, at the end of each daily section, is it able to find patterns to provide positive returns in more than a mere 50% of attempts? tries to answer this question by combining:

  • Python, Pandas, Numpy, Scikit-learn.
  • Classification and clustering.
  • Basic Machine Learning techniques (learning, testing, predicting).
  • Examples of any available codes about trading systems, with a focus on Nasdaq 100 stocks.

Basically, on a daily basis for each of the stocks in the Nasdaq 100 Index,

  • Downloads end-day Open, Low, High, Close, Volume data.
  • Calculates 10+ technical indicators.
  • Updates the optimal level for stop-loss, take-profit.
  • Learns and tests 30-day stock predictions using various ML classifiers.
  • Selects the best classifiers.
  • Picks six stocks with long or short positions and creates a portfolio.

The portfolios generated are kept for one month. At the end of the period they deliver their contribution to the equity line (the contribution will be a combination of profit/loss if correspondent levels are touched + market value of open long/short positions).

Performance benchmark

In order to visualize the results of the trading activity, charts and tables are freely accessible on

Furthermore, the ambition is to create a community of Machine Learning/trading enthusiasts who can freely subscribe to the website, communicate and start providing feedback to improve the system.

Further development steps are planned as (hopefully) the community grows. A systematic comparison of the three strategies that will be implemented in 2018 will be added in the coming months.

It is crucial for the system to test the methodologies for at least one year, in order to check if performances are reliable in any market regimes.

A metric of a positive testing will be:

  • Positive returns in any market regime (bullish, bearish, low/high volatility).
  • Relatively low volatility of returns (and Sharpe ratio >1).
  • The less correlated the system returns (in connection with Nasdaq 100), the better.
  • Constant improvement of stop-loss/take-profit levels.

It would be great to receive your feedback, ideas, links. If the experiment goes well, the idea is to give the source code to a professional team which will develop the solution and open up the “equity” to the community of subscribers (crowdfunding) and to other investors. is an experiment, in which the machines will do the work autonomously and human beings will observe, hopefully contributing to building a new way of investing.

AI will be the new internet: a new industrial and social revolution.
Just as steam machines brought development, but also the exploitation of natural resources and the consequent pollution, AI will also bring benefits for and potential negative impacts on our way of life. In order to deepen these concepts, I have also developed a blog:

Thank you for your attention and stay in touch!