Developing portfolio construction trading strategies#

In this post, we will cover the basics of portfolio constructions and alpha models. We will show how to build a simple portfolio construction strategy using Python and Trading Strategy’s backtesting framework.

The target audience of this post us quants and people who want to learn algorithmic trading.

What is Portfolio Construction?#

Portfolio construction a trading strategy method of selecting securities optimally to achieve maximum returns while taking minimum risk.

It involves understanding how different asset classes, funds, and weightings impact each other and an investor’s objectives

Portfolio construction has several phases

  • Asset allocation models - to determine the optimal mix of asset classes (stocks, bonds, and commodities) in a portfolio, based on historical returns, volatility, and correlations.

  • Optimization techniques - to identify the best combination of individual securities within each asset class, based on factors such as expected return, risk, and liquidity.

  • Risk management tools - such as stop-loss orders, hedging strategies, and diversification techniques, to manage portfolio risk and reduce exposure to individual assets or market risks

  • Alpha generation strategies - such as factor investing, statistical arbitrage, and trend-following, to identify assets that are likely to outperform or underperform the broader market.

What is Alpha model?#

An alpha model is a mathematical or quantitative framework used to generate trading signals that can be used in portfolio construction.

The alpha model seeks to identify assets that are likely to outperform or underperform their peers, based on a variety of factors and variables.

Alpha models can be constructed using a variety of techniques, such as statistical analysis, machine learning algorithms, or financial modeling. The inputs to an alpha model may include company financial statements, price and volume data, macroeconomic indicators, and other market data.

Once an alpha model generates trading signals, the portfolio manager can use those signals to construct a portfolio that aims to generate alpha (i.e., excess returns) relative to a benchmark index.

What is Trading Strategy Framework?#

The Trading Strategy Framework is a Python based software development library to develop automated trading strategies for decentralised finance markets.

The framework consists of

The core audience of the library is quants.

How does Trading Strategy framework support creating portfolio constructions strategies?#

The Trading Strategy Framework provides functionality for

The workflow for the framework is

  • Develop and backtest your strategies using Jupyter Notebook

  • Visualise and analyse the performance of your trading strategy using various tools and methods, like performance summary statistics, equity curve, tracking the performance of individual positions

  • Take your trading strategy backtested code unmodified to the live trading execution environment

The strategy core logic#

The Trading Strategy Framework offers two functions the developer must implement for the strategies

  • creating_trading_universe that returns an object that represents all assets the strategy can trade. This data is used to set up and update backtesting and live market data feeds. This includes blockchains, exchanges, trading pairs, OHLCV data feeds, liquidity data feeds and some special data feeds e.g. used for stop loss triggers.

  • decide_trades takes in the current strategy cycle, timestamped trading universe and the current strategy state (open positions) as an input. Based on this data the function will return a list of new trades that will either open new or close existing positions

The strategy advanced in ticks. Each tick length is the duration of a strategy cycle. Common strategy cycles includes hourly, daily and weekly trade decisions. In the portfolio construction, this strategy cycle is called rebalance.

Overview of portfolio construction strategy architecture#

The Trading Strategy framework offers a Python “lego blocks” that allows you to easily put together a strategy without need to develop the software plumbinb yourself.

For a develop, this is seen as a high-level Python classes and objects.

  • Timestamp is the current strategy cycle tick of the trading strategy.

  • tradeexecutor.strategy.TradingStrategyUniverse contains all data that can go input to the trade.

  • tradexecutor.state.State contains all past and current data about the previous actions the strategy took, like opened and closed positions, trades, blockchain transaction execution details, technical indicators, uptime, deposited capital.

  • AlphaModel offers a way to set weighted trading signals based on the data analysis. It has helper methods of trackign signals, choosing top signals, and generating rebalance trades automatically.

  • PositionManager is a high level utility class that is used to generate trades. For example, you can call PositionManager.close_all and it will return a list of trade orders that need to be executed in order to sell all assets and go back to fully cash.