Skip to content

Instantly share code, notes, and snippets.

@dtoma
Last active January 31, 2020 13:39
Show Gist options
  • Save dtoma/fa3636e3de2c5041cd6f2f0e388cf30e to your computer and use it in GitHub Desktop.
Save dtoma/fa3636e3de2c5041cd6f2f0e388cf30e to your computer and use it in GitHub Desktop.
Into the Black Box

Notes from "Inside the Black Box: a Simple Guide to Quantitative and High-Frequency Trading"

Chapter 5 - Transaction cost models

  • commissions & fees (brokers)
    • clearing: reporting, monitoring, taxes...
    • settlement: deliver of securities in exchange for payment in full
    • transaction costs
  • slippage [1]
    • market moves between the decision & the execution
    • can be positive or negative
    • hard to measure/anticipate
  • market impact
    • instrument price when entering order vs. instrument price after execution
    • large orders can move the market significantly
    • hard to measure
    • usually modeled order size vs. liquidity

[1] T-bills for example don't move much. However stocks e.g. GOOG has (at the time of writing) an average daily range of 2.6% of its opening price, ~16 times larger than its average move from one day to the next, so slippage can have a big impact.

Types of transaction cost models

  1. flat
  2. linear
  3. piecewise-linear
  4. quadratic

Each instrument has different characteristics (traded by different types of investors, different liquidity, volatility...).

"Generally accepted" that the cost of trading vs order size is quadratic (due to market impact). Hence the four models above are each more accurate than the previous one.

Forecasts are based on historical data, so not perfect.

Chapter 6 - Portfolio Construction Models

Two major forms:

  • rule-based
    • heuristics defined by the quant
    • from simple to complex
    • often derived from human experience
  • optimized
    • measure results with an objective function eg. Sharpe ratio
    • simple concept, implementation can be difficult to understand in detail

Rule-based portfolio construction models

Equal position weighting

  • if a position is good to own, size doesn't matter
  • assumes instruments are relatively homogeneous (in terms of risk, etc.)
  • seems simplistic but avoids potential downsides to unequal weighting:
    1. it would require sufficient data to predict not only the move, but the magnitude of the move
    2. can lead to taking large bets on an instrument because of specific events like the end of a good Momentum run (before it starts dipping, it's at its most attractive), or suddenly wanting to buy an instrument that was accidentally quoted in pence instead of pounds
  • diversifies risk
  • liquidity of each instrument must still be taken into account

Equal risk weighting

  • More volatile (or other risk measure) instruments are given a smaller allocation
  • Some believe it to be an improvement over equal weights
  • One downside if that risk is always a backward-looking measurement
  • Exposed to sudden changes in volatility, eg. banks were stable between 1998 and 2008, then became very volatile

Alpha-driven weighting

  • Allocation determined by alpha model
  • Capped by risk model

Portfolio optimizers

Famous example: Markowitz' "Portfolio Selection" paper.

Simply: for two instruments with equal returns, investors prefer the least risky.

Example: the optimizer might be required to solve for the optimal (eg. max risk-adjusted returns) portfolio, with additional inputs such as:

  • portfolio size in currency terms
  • desired risk level (eg. volatilty or expected drawdown)
  • hard-to-borrow costs

The inputs for an optimizer include:

  • expected returns
    • can be a score for expected returns or direction
    • doesn't have to be exact, just to point in the right direction / give a sense of attractiveness
  • expected volatility
    • often using stochastic (random) volatility models eg. GARCH
  • correlation matrix of the instrument universe
    • correlation: measure of similarity of movement between 2 instruments
    • [-1, 1]
    • can be very unstable over time
    • can be daily, weekly...

Optimization techniques

  • Unconstrained optimization
    • Can suggest, for example, allocating 100% of capital to 1 instrument.
  • Constrained optimization
    • limits on positions by instrument, by sector...
    • can get complicated, hit a local maximum quickly but take a while to find the globally optimal solution

A few approaches:

  • Black-Litterman optimization
    • Add a degree of confidence to the historical precedent evident in the data
  • Grinold & Khan's Optimizing Factor Portfolios
    • build portfolios of signals rather than position sizes
    • build one portfolio for each factor (momentum, value...) (long/short)
    • generate a time series of historical returns for each factor
    • each time series is treated as one instrument
    • Example:
      1. 100 equal-weighted instruments (each has a weight of 1%)
      2. 2 factors, and signals that are -1 for shot and +1 for long
      3. time series show we should weight 60% factor 1, 40% factor 2
      4. for a given company, factor 1 says "long", factor 2 says "short"
      5. for this company the weight is (0.01 * 1 * 0.6) + (0.01 * -1 * 0.4)
      6. ergo we should be long 0.2% of our capital on this company
  • Resampled
    • Paper "Efficient Assert Management", Richard Michaud
    • Monte Carlo simulation reorders the observed results many times (eg. S&P 500 returns)
    • Only useful if the data is good, for example:
      1. S&P 500 returns from 1988 through 2006 seems "good": lots of data
      2. however the argest negative observations (by far) were in 1987 and 2007-2008

Final observations on optimization

  • an instrument that has positive returns might end up being shorted because, for example, of neutrality constraints: we are long an even better instrument in the same sector, so we need to short something
  • this tends to happen on smaller positions, where expected returns can be overcome by transaction costs of risk considerations
  • the output of an optimization process is an ideal/target portfolio, and the difference with the current portfolio are the trades to be made

Chapter 7 - Execution

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment