0% found this document useful (0 votes)
9 views

6Algorithmic_Trading_and_Backtesting_Notes

The document provides an overview of algorithmic trading and backtesting, emphasizing the integration of mathematics, statistics, computer science, data processing, and finance in quantitative trading strategies. It discusses key elements such as sources of profit, regular trading, data processing, and risk management, while also presenting an example of a value factor portfolio. Additionally, it highlights the importance of backtesting for optimizing strategies and assessing performance metrics against benchmarks.

Uploaded by

maxwell.zhu0925
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

6Algorithmic_Trading_and_Backtesting_Notes

The document provides an overview of algorithmic trading and backtesting, emphasizing the integration of mathematics, statistics, computer science, data processing, and finance in quantitative trading strategies. It discusses key elements such as sources of profit, regular trading, data processing, and risk management, while also presenting an example of a value factor portfolio. Additionally, it highlights the importance of backtesting for optimizing strategies and assessing performance metrics against benchmarks.

Uploaded by

maxwell.zhu0925
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 46

Algorithmic Trading and Backtesting

Paragon National Group


Overview

Quantitative trading uses mathematical models and automated models to make


trading decisions. It often involves a combination of multiple fields including
1. Mathematics (e.g. options pricing, portfolio optimization, numerical
analysis)
2. Statistics (e.g. relative value, stat arb)
3. Computer science (e.g. algorithms, parallel computing, networks, etc, etc)
4. Data processing (data cleaning, data pipelines, storage)
5. Finance/Economics (e.g. fundamental analysis, accounting,
macro-economic indicators)
Quantitative Trading

Key elements of a algorithmic trading strategy:


▶ Source of profit
▶ Regular securities trading
▶ Processing data flow
▶ Risk management
Each of these can be very rich and complex problems to solve in quantitative
finance!
Profit

Above all, we want a quantitative trading strategy to be profitable. The key


question is where can we find sources of profit in secondary markets that are
able to source returns systematically.
Sources of profit
▶ Providing services
▶ Liquidity
▶ Insurance/risk underwriting
▶ Market Inefficiencies
▶ Pure arbitrage
▶ Statistical arbitrage
▶ Fundamental analysis
Regular trading

Quantitative trading strategies require continual processing of new information,


dynamic hedging, and enter/exiting new attractive/unattractive positions as
part of re-balancing.
This is in contrast to event-driven traders or stock-pickers who will only make a
few large trades in hopes that those specific trades will be extremely profitable.
The advantages of regular trading activity is the ability to make multiple
independent bets over time as similar scenarios arise over history. This allows
for the realization of steadier profits.
Data processing

Quantitative trading strategies deal with the continual processing and analysis
of data that is streamed from the market.
The steps to the data cycle are generally as follows
1. Receive and parse useful information from data stream
2. Run models on returns and risks
3. Rebalance positions to an ideal portfolio to optimize risk-adjusted returns

The trading system is dynamic and responds to information from seemingly


random events.
Risk management

Trading strategies will often involve trading across numerous amounts of asset
classes and securities at the same time. In addition to this, they may apply
some amount of leverage to the positions using derivatives and/or margin. Due
to this, it is important to take into account position sizing and risk exposures.
Above all, the strategy should never blow up.
Example: Value (and Momentum) Factor Portfolio (Asness et al, 2012)

What is value? Value is the idea that some securities are cheap and some
securities are expensive.
How do we determine what is a cheap security and what is an expensive
security? For the purposes of this paper, we use the common signal of lagged
book value of equity to market value of equity used in Fama and French (1992)

BE/M E
Example: Value (and Momentum) Factor Portfolio (Asness et al, 2012)

Source of profit: Value signal (BE/M E)


Investment universe: Highest market-cap stocks that cumulatively account for
90% of the total market cap of the entire stock market. Corresponds to 354
firms up to the 676 largest names which are pretty liquid.
Data: Stock universe returns from CRSP and book value from Compustat.
Value Factor Portfolio

For the factor portfolio construction, we would use the following algorithm as
our strategy:
1. Rank each security by its value signal weighting
2. Demean the ranks to produce a dollar-neutral weighting portfolio
3. Multiply by a scalar factor ct to normalize for our dollar notional
Thus the dollar weighting for stock i at time t with signal Sit is
X
wit = ct (rank(Sit ) − rank(Sit )/N )
i
Value Market-Cap Weighted Portfolios

For the market-cap weighted portfolio construction, we consider the following


pseudo-algorithm to be our systematic strategy:
1. Rank each security by value signal
2. Sort into three equal groups - high, middle, low
3. For each group, we form a subportfolio with returns weighted by their
beginning-of-month market cap
Question: What are the advantages/disadvantages to using each of the
portfolios (market-cap vs factor portfolio) on our strategy analysis?
Value MC Portfolio Results
Further directions

The signal and portfolio construction used was pretty basic. The following
questions can be potential areas for improvement on the initial portfolio.
(Asness does address many of these in his paper)
Further directions

The signal and portfolio construction used was pretty basic. The following
questions can be potential areas for improvement on the initial portfolio.
(Asness does address many of these in his paper)
▶ Can we look for a better signal for value?
Further directions

The signal and portfolio construction used was pretty basic. The following
questions can be potential areas for improvement on the initial portfolio.
(Asness does address many of these in his paper)
▶ Can we look for a better signal for value?
▶ How can we combine different signals?
Further directions

The signal and portfolio construction used was pretty basic. The following
questions can be potential areas for improvement on the initial portfolio.
(Asness does address many of these in his paper)
▶ Can we look for a better signal for value?
▶ How can we combine different signals?
▶ How can we apply this to different asset class for diversification?
Further directions

The signal and portfolio construction used was pretty basic. The following
questions can be potential areas for improvement on the initial portfolio.
(Asness does address many of these in his paper)
▶ Can we look for a better signal for value?
▶ How can we combine different signals?
▶ How can we apply this to different asset class for diversification?
▶ How might we come up with a better portfolio construction methodology?
Further directions

The signal and portfolio construction used was pretty basic. The following
questions can be potential areas for improvement on the initial portfolio.
(Asness does address many of these in his paper)
▶ Can we look for a better signal for value?
▶ How can we combine different signals?
▶ How can we apply this to different asset class for diversification?
▶ How might we come up with a better portfolio construction methodology?
▶ How does the incorporation of transaction costs and liquidity to our
rebalancing affect our performance?
Further directions

The signal and portfolio construction used was pretty basic. The following
questions can be potential areas for improvement on the initial portfolio.
(Asness does address many of these in his paper)
▶ Can we look for a better signal for value?
▶ How can we combine different signals?
▶ How can we apply this to different asset class for diversification?
▶ How might we come up with a better portfolio construction methodology?
▶ How does the incorporation of transaction costs and liquidity to our
rebalancing affect our performance?
These are general questions that are of interest to a quant and are often
significant areas of research for systematic strategies.
Why Backtest

As shown in our example, quantitative strategy goes through a period of


analysis against historical data. The reasons for this are to
▶ Develop a sense of risks and rewards in potential trading scenarios
▶ Optimize strategy parameters to increase expectancy
▶ Create a case to invest in the strategy for investors (or for ourselves)
Return Metrics

We may be interested in many different metrics in our analysis. Some common


ones include (but are not limited to):
▶ Average return per trade
▶ Strategy return: size each trade up by a reasonable amount and sum
across all trades over time
▶ Backtested returns: use assumptions about trade size and cost models as
well as setting risk limits. Also include capital requirements
Strategy Metrics

Once we have the strategy return series, we may be interested in other


risk/reward metrics:
Strategy Metrics

Once we have the strategy return series, we may be interested in other


risk/reward metrics:
▶ Sharpe/Information ratio with benchmark rb .

E[r − rb ]
p
E[(r − rb )2 ]
Examples of benchmarks can be the risk-free-rate, market return, or factor
returns
Strategy Metrics

Once we have the strategy return series, we may be interested in other


risk/reward metrics:
▶ Sharpe/Information ratio with benchmark rb .

E[r − rb ]
p
E[(r − rb )2 ]
Examples of benchmarks can be the risk-free-rate, market return, or factor
returns
▶ Largest single-period drawdown
Strategy Metrics

Once we have the strategy return series, we may be interested in other


risk/reward metrics:
▶ Sharpe/Information ratio with benchmark rb .

E[r − rb ]
p
E[(r − rb )2 ]
Examples of benchmarks can be the risk-free-rate, market return, or factor
returns
▶ Largest single-period drawdown
▶ Maximum drawdown
Strategy Metrics

Once we have the strategy return series, we may be interested in other


risk/reward metrics:
▶ Sharpe/Information ratio with benchmark rb .

E[r − rb ]
p
E[(r − rb )2 ]
Examples of benchmarks can be the risk-free-rate, market return, or factor
returns
▶ Largest single-period drawdown
▶ Maximum drawdown
▶ Downside beta: defined by

r ∼ β · rM + c

conditioned on the set where rM < 0


Strategy Metrics

Once we have the strategy return series, we may be interested in other


risk/reward metrics:
▶ Sharpe/Information ratio with benchmark rb .

E[r − rb ]
p
E[(r − rb )2 ]
Examples of benchmarks can be the risk-free-rate, market return, or factor
returns
▶ Largest single-period drawdown
▶ Maximum drawdown
▶ Downside beta: defined by

r ∼ β · rM + c

conditioned on the set where rM < 0


▶ Stress moments
Strategy Metrics

Once we have the strategy return series, we may be interested in other


risk/reward metrics:
▶ Sharpe/Information ratio with benchmark rb .

E[r − rb ]
p
E[(r − rb )2 ]
Examples of benchmarks can be the risk-free-rate, market return, or factor
returns
▶ Largest single-period drawdown
▶ Maximum drawdown
▶ Downside beta: defined by

r ∼ β · rM + c

conditioned on the set where rM < 0


▶ Stress moments
▶ Other moments of returns: skew, kurtosis, etc
Benchmarks

The choice of benchmark for our strategy is used to determine how much
additional reward that an investor can get from our strategy compared to either
a simpler method (like buying an index) or a comparative strategy.
Some common benchmarks include:
Benchmarks

The choice of benchmark for our strategy is used to determine how much
additional reward that an investor can get from our strategy compared to either
a simpler method (like buying an index) or a comparative strategy.
Some common benchmarks include:
▶ Buy-and-hold market/other index
Benchmarks

The choice of benchmark for our strategy is used to determine how much
additional reward that an investor can get from our strategy compared to either
a simpler method (like buying an index) or a comparative strategy.
Some common benchmarks include:
▶ Buy-and-hold market/other index
▶ ETFs
Benchmarks

The choice of benchmark for our strategy is used to determine how much
additional reward that an investor can get from our strategy compared to either
a simpler method (like buying an index) or a comparative strategy.
Some common benchmarks include:
▶ Buy-and-hold market/other index
▶ ETFs
▶ Fama-French-Carhart Factors
Benchmarks

The choice of benchmark for our strategy is used to determine how much
additional reward that an investor can get from our strategy compared to either
a simpler method (like buying an index) or a comparative strategy.
Some common benchmarks include:
▶ Buy-and-hold market/other index
▶ ETFs
▶ Fama-French-Carhart Factors
▶ Barra factors
Benchmarks

The choice of benchmark for our strategy is used to determine how much
additional reward that an investor can get from our strategy compared to either
a simpler method (like buying an index) or a comparative strategy.
Some common benchmarks include:
▶ Buy-and-hold market/other index
▶ ETFs
▶ Fama-French-Carhart Factors
▶ Barra factors
▶ Some similar strategy
Return Attributions

Once we have our return series from our strategy, it is useful to decompose the
returns series into our benchmarks, which would attribute some amount of
P&L to each systematic or common factor.
Return Attributions

Once we have our return series from our strategy, it is useful to decompose the
returns series into our benchmarks, which would attribute some amount of
P&L to each systematic or common factor.
A simple, but useful technique is just using a cross-sectional linear regression:

r ∼ α + β1 F1 + β2 F2 + . . .

where Fk represents each of our factors. Typical factors include F-F-C,


volatility, liquidity, credit risk, inflation/interest rate changes.
Return Attributions

Once we have our return series from our strategy, it is useful to decompose the
returns series into our benchmarks, which would attribute some amount of
P&L to each systematic or common factor.
A simple, but useful technique is just using a cross-sectional linear regression:

r ∼ α + β1 F1 + β2 F2 + . . .

where Fk represents each of our factors. Typical factors include F-F-C,


volatility, liquidity, credit risk, inflation/interest rate changes.
The βs can be used to analyze how much of our P&L is explained by each
factor. The residual alpha α is considered to be our strategy novelty compared
to our benchmarks.
Return Attributions

Once we have our return series from our strategy, it is useful to decompose the
returns series into our benchmarks, which would attribute some amount of
P&L to each systematic or common factor.
A simple, but useful technique is just using a cross-sectional linear regression:

r ∼ α + β1 F1 + β2 F2 + . . .

where Fk represents each of our factors. Typical factors include F-F-C,


volatility, liquidity, credit risk, inflation/interest rate changes.
The βs can be used to analyze how much of our P&L is explained by each
factor. The residual alpha α is considered to be our strategy novelty compared
to our benchmarks.
In practice, the amount of α is a limited and very hard to find, due to
transaction costs and adverse selection.
Backtest Prerequisites: Asset Prices

Asset Prices: In order to generate accurate P&L metrics for our backtest, we
need accurate asset prices.
For US equities, futures, and FX, i.e. electronically traded assets, this data is
relatively easy to get.
For international products and products that are primarily traded OTC such as
exotic options and corporate bonds, this data can be difficult to obtain.
Slippage and Trading Costs

Whenever you place a trade, there is a difference between the price that you
intend to transact at and the price that you actually transact at. This is called
slippage and is generally a function of the size of your order and the trading
speed, market liquidity, commissions, bid-ask spread, and/or volatility.
A good first-order approximation is the square-root law for transaction cost
assumptions which is a linear function of the square-root of the size of your
trade N : √
c ∼ c0 + c1 · N
where c0 represents your fixed costs (such as commissions, fees, rebates) and
c1 scales your slippage.
For those interested in further exploration of the theory and practice of optimal
execution, Almgren and Chriss, 2001 is a seminal paper in this area
Financing

Typically, quantitative strategies will use some amount of leverage in order to


increase returns. This also comes with the cost of increasing risk.
In order to access leverage, one needs to fund their positions by borrowing
money from a prime broker (typically large commercial banks i.e. Goldman
Sachs, Morgan Stanley, BofA).
The rate at which they will borrow money is usually referenced from a rate
such as SOFR. Excess capital can also receive interest, but less than the
borrowing rate.
Available Assets

Q: Consider that we have a trading strategy that we want to backtest on


equities data over the past 20 years. We choose our asset universe to be the
current top 500 assets ranked by market cap so that there is sufficient liquidity
to transact. What may be some issues caused by this approach?
Available Assets

Q: Consider that we have a trading strategy that we want to backtest on


equities data over the past 20 years. We choose our asset universe to be the
current top 500 assets ranked by market cap so that there is sufficient liquidity
to transact. What may be some issues caused by this approach?
Surivivorship bias! By only including current highest market-cap stocks, it does
not include companies that defaulted or fell out of the top 500 assets.
It is crucial to make sure that the assets that you use are actually available and
are included at each time during the backtest.
Expanding the asset universe will usually allow more opportunities to gain
returns or deploy more capital.
System Assumptions

Typically, trading signals are based of point prices at a specific time. However
unless one is transacting at a very small amount, it is unfeasible to be able to
transact exactly at that price.
For example, if a trading strategy signal fires using the close price of the asset
each day, then one would only actually be able to transact at the beginning of
the next day.
For a higher frequency strategy in electronic markets, it may be reasonable to
incur a lag of 1 second to a few minutes in order to attain your position. For
OTC markets, this can even be several days.
Hedging

A quantitative strategy will want to hedge out some amount of risks. For an
equity long-short strategy, this may be market risk in order to be
market-neutral. For options, this may be delta and other volatility-related
Greeks.
Equities Considerations

Many of our trading strategies will involve equities data as that is the most
readily available. Some considerations to take into account:
▶ Mergers/spinoffs
▶ Dividends/stock splits - usually want to use dividend and split adjusted
data.
▶ High benchmark sensitivity. Most of equity strategy returns can be
described by the market factor or Fama-French factors. It is pretty difficult
to find non-noise alphas.

You might also like