6Algorithmic_Trading_and_Backtesting_Notes
6Algorithmic_Trading_and_Backtesting_Notes
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
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)
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
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
E[r − rb ]
p
E[(r − rb )2 ]
Examples of benchmarks can be the risk-free-rate, market return, or factor
returns
Strategy Metrics
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
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
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
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
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
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 + . . .
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 + . . .
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 + . . .
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, 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.