diff --git a/reading/001_Quantitative_Trading/README.md b/reading/001_Quantitative_Trading/README.md index 481108a..5d50ec6 100644 --- a/reading/001_Quantitative_Trading/README.md +++ b/reading/001_Quantitative_Trading/README.md @@ -2,6 +2,10 @@ [pdf](./Quantitative_Trading_Ernest_P_Chan.pdf) -total pages=204 +I will be loosey reading through this book. Many of the concepts will be gone into more rigour in other textbooks. -**Currently reading:** chapter 1, page 117 +## Post read notes + +Not alot of math, but math that did show up was hand wavy.(Seems like the book assumes you understand certain concepts) + +Main takeaway is use Kelly formula for sizing positions. diff --git a/reading/001_Quantitative_Trading/notes.ipynb b/reading/001_Quantitative_Trading/notes.ipynb index de7f5f5..ac849d1 100644 --- a/reading/001_Quantitative_Trading/notes.ipynb +++ b/reading/001_Quantitative_Trading/notes.ipynb @@ -13,7 +13,10 @@ "id": "b13688b9", "metadata": {}, "source": [ - "## Main Takeaways" + "When loss of money occurs, rationality is often the first victim.\n", + "\n", + "As long as financial markets demand instant liquidity, however, there will always be a profitable\n", + "niche for quantitative trading." ] }, { @@ -47,6 +50,18 @@ "## Definitions" ] }, + { + "cell_type": "markdown", + "id": "8ec7516e", + "metadata": {}, + "source": [ + "**Defn** Information Ratio (Sharpe ratio):\n", + "\n", + "$$\\text{Information Ratio} = \\frac{\\text{Average of Excess Returns}}{\\text{Standard Deviation of Excess Returns}}$$\n", + "\n", + "$$\\text{Excess Returns} = \\text{Portfolio Returns} - \\text{Benchmark Returns}$$" + ] + }, { "cell_type": "markdown", "id": "7aab1f0d", @@ -60,18 +75,6 @@ "- ***slippage*** - The difference between the price that triggers the trading signal and the average execution price of the entire order" ] }, - { - "cell_type": "markdown", - "id": "8ec7516e", - "metadata": {}, - "source": [ - "**Defn** Information Ratio (Sharpe ratio):\n", - "\n", - "$$\\text{Information Ratio} = \\frac{\\text{Average of Excess Returns}}{\\text{Standard Deviation of Excess Returns}}$$\n", - "\n", - "$$\\text{Excess Returns} = \\text{Portfolio Returns} - \\text{Benchmark Returns}$$" - ] - }, { "cell_type": "markdown", "id": "865b04b1", @@ -86,6 +89,14 @@ "- ***regime shift*** - Situation when the financial market structure or the macroeconomic environment undergoes a drastic change so much so that trading strategies that were profitable before may not be profitable now" ] }, + { + "cell_type": "markdown", + "id": "076ad86c", + "metadata": {}, + "source": [ + "- ***Risk-Adjusted returns*** - " + ] + }, { "cell_type": "markdown", "id": "a845580c", @@ -163,7 +174,9 @@ "- Liquidity cost\n", "- Opportunity cost\n", "- Market Impact\n", - "- Slippage" + "- Slippage\n", + "\n", + "Try to combine all of these into a \"one way transaction cost\" (onewaytcost)" ] }, { @@ -214,6 +227,227 @@ "source": [ "## Money and Risk Management" ] + }, + { + "cell_type": "markdown", + "id": "41ddff80", + "metadata": {}, + "source": [ + "### The Kelly Formula" + ] + }, + { + "cell_type": "markdown", + "id": "169dc996", + "metadata": {}, + "source": [ + "Let $F^*$ be the optimal fractions of your equity that you should allocate to each of your $n$ strategies by a column vector $F^* = (f_1^*, f_2^*, \\dots, f_n^*)^T$\n", + "\n", + "Let $C$ be the covariance matrix such that matrix element $C_{ij}$ is the covariance of the returns of the $i^\\text{th}$ and $j^\\text{th}$ strategies.\n", + "\n", + "Let $M = (m_1, m_2, \\dots, m_n)^T$ be the column vector of mean returns of the strategies, where $m_i$ is a one-period, simple(uncompounded), unlevered return.\n", + "\n", + "Given our optimization objective and the Gaussian assumption, Dr. Thorp has shown that the optimal allocation is given by\n", + "\n", + "$$F^* = C^{-1}M$$\n", + "\n", + "If we assume that the strategies are all statistically independent, the covariance matrix becomes a diagonal matrix, with the diagonal elements equal to the variance of the individual strategies. This leads to an especially simple formula\n", + "\n", + "$$f_i = \\frac{m_i}{s_i^2}$$\n", + "\n", + "This is the famous Kelly formula as applied to continuous finance as opposed to gambling with discrete outcomes, and it gives the optimal leverage one should employ for a particular trading strategy.\n", + "\n", + "As a practical procedure, this continuous updating of the capital allocation should occur at least once at the end of each trading\n", + "day. In addition to updating the capital allocation, one should also\n", + "periodically update F* itself by recalculating the most recent trailing mean return and standard deviation. What should the lookback\n", + "period be and how often do you need to update these inputs to the\n", + "Kelly formula? These depend on the average holding period of your\n", + "strategy. If you hold your positions for only one day or so, then as a\n", + "rule of thumb, I would advise using a lookback period of six months.\n", + "Using a relatively short lookback period has the advantage of allowing you to gradually reduce your exposure to strategies that have\n", + "been losing their performance. As for the frequency of update, it\n", + "should not be a burden to update F* daily once you have written a\n", + "program to do so." + ] + }, + { + "cell_type": "markdown", + "id": "270f0944", + "metadata": {}, + "source": [ + "Model risk simply refers to the possibility that trading losses are\n", + "not due to the statistical vagaries of the market, but to the fact that\n", + "the trading model is wrong\n" + ] + }, + { + "cell_type": "markdown", + "id": "b6709290", + "metadata": {}, + "source": [ + "the one golden rule in risk management is to keep the size of your portfolio under control at all times\n", + "\n", + "Do not succumb to either despair or greed" + ] + }, + { + "cell_type": "markdown", + "id": "a6edc9d9", + "metadata": {}, + "source": [ + "# Mean-reverting versus Momentum strategies" + ] + }, + { + "cell_type": "markdown", + "id": "63f1028e", + "metadata": {}, + "source": [ + "Security prices are either mean reverting or trending. Otherwise they are random walking and trading will be futile. \n", + "\n", + "- ***Mean reverting***: Prices tend to return to an average (mean) over time\n", + "- ***Trending***: Prices move persistently in one direction. Momentum builds and continues.\n", + "\n", + "Sometimes (usually) a security is both mean reverting and trending." + ] + }, + { + "cell_type": "markdown", + "id": "084a3a0b", + "metadata": {}, + "source": [ + "## Stationarity and Cointegration\n", + "\n", + "- ***cointegrated***: Most stock price series are not stationary—they exhibit a geometric random walk that gets them farther and farther away from their starting (i.e., initial public offering) values. However, you can often find a pair of stocks such that if you long one and short the other, the market value of the pair is stationary, then the pair of stocks are cointegrated\n", + "\n", + "If a price series (of a stock, a pair of stocks, or, in general, a portfolio of stocks) is stationary, then a mean-reverting strategy is guaranteed to be profitable, as long as the stationarity persists into the future (which is by no means guaranteed)\n", + "\n", + "**Cointegration Is Not Correlation**" + ] + }, + { + "cell_type": "markdown", + "id": "a60d882c", + "metadata": {}, + "source": [ + "## Factor Models" + ] + }, + { + "cell_type": "markdown", + "id": "2d21e3c0", + "metadata": {}, + "source": [ + "- ***Factor returns***: The common drivers of stock returns\n", + "- ***Factor exposures***: The sensitivities to each of these common drivers\n", + "- ***Specific return***: Any part of a stock’s return that cannot be explained by these common factor returns is deemed a specific return\n", + "\n", + "Each stock’s specific return is assumed to be uncorrelated to another stock’s." + ] + }, + { + "cell_type": "markdown", + "id": "6e48e218", + "metadata": {}, + "source": [ + "## Exit Strategy" + ] + }, + { + "cell_type": "markdown", + "id": "e61edcb1", + "metadata": {}, + "source": [ + "- A fixed holding period\n", + "- A target price or profit cap\n", + "- The latest entry signals\n", + "- A stop price\n", + "\n", + "The mean reversion of a time series can be modeled by an equation called the Ornstein-Uhlenbeck formula. See page 163 for more info.\n", + "\n", + "The properties of the Ornstein-Uhlenbeck formula can inform us about the exit strategies.\n", + "\n", + "If you believe that your security is mean reverting, then you also have a ready-made target price—the mean value of the historical prices of the security, or µ in the Ornstein-Uhlenbeck formula.\n", + "\n", + "Target prices can also be used in the case of momentum models if you have a fundamental valuation model of a company. But as fundamental valuation is at best an inexact science, target prices are not as easily justified in momentum models as in mean-reverting models.\n", + "\n", + "Exiting a position based on running an entry model also tells us whether a stop-loss strategy is recommended" + ] + }, + { + "cell_type": "markdown", + "id": "eb884fe5", + "metadata": {}, + "source": [ + "## High Frequency Trading Strategies" + ] + }, + { + "cell_type": "markdown", + "id": "22ad0ba8", + "metadata": {}, + "source": [ + "Requires low level programming and alot of reasources to consider viable" + ] + }, + { + "cell_type": "markdown", + "id": "9c8eeee5", + "metadata": {}, + "source": [ + "## Other topics / notes\n", + "\n", + "- Markov regime switching / hidden Markov models\n", + "- Kalman filter\n", + "- neural networks\n", + "\n", + "Empirical studies have found that a portfolio that consists of low-beta stocks generally has lower risk and thus a higher Sharpe ratio" + ] + }, + { + "cell_type": "markdown", + "id": "bdd23956", + "metadata": {}, + "source": [ + "- Mean-reverting regimes are more prevalent than trending regimes.\n", + "- There are some tricky data issues involved with backtesting mean-reversion strategies: Outlier quotes and survivorship bias are among them.\n", + "- Trending regimes are usually triggered by the diffusion of new\n", + "information, the execution of a large institutional order, or\n", + "“herding” behavior.\n", + "- Competition between traders tends to reduce the number of\n", + "mean-reverting trading opportunities.\n", + "- Competition between traders tends to reduce the optimal holding period of a momentum trade.\n", + "- Regime switching can sometimes be detected using a dataminingx approach with numerous input features.\n", + "- A stationary price series is ideal for a mean-reversion trade.\n", + "- Two or more nonstationary price series can be combined to form a stationary one if they are “cointegrating.”\n", + "- Cointegration and correlation are different things: Cointegration\n", + "is about the long-term behavior of the prices of two or more\n", + "stocks, while correlation is about the short-term behavior of\n", + "their returns.\n", + "- Factor models, or arbitrage pricing theory, are commonly used\n", + "for modeling how fundamental factors affect stock returns linearly.\n", + "- One of the most well-known factor models is the Fama-French\n", + "Three-Factor model, which postulates that stock returns are\n", + "proportional to their beta and book-to-price ratio, and negatively\n", + "to their market capitalizations.\n", + "- Factor models typically have a relatively long holding period and\n", + "long drawdowns due to regime switches.\n", + "- Exit signals should be created differently for mean-reversion versus momentum strategies.\n", + "- Estimation of the optimal holding period of a mean-reverting strategy can be quite robust, due to the Ornstein-Uhlenbeck formula.\n", + "- Estimation of the optimal holding period of a momentum strategy can be error prone due to the small number of signals.\n", + "- Stop loss can be suitable for momentum strategies but not reversal strategies.\n", + "- Seasonal trading strategies for stocks (i.e., calendar effect) have\n", + "become unprofitable in recent years.\n", + "- Seasonal trading strategies for commodity futures continue to\n", + "be profitable.\n", + "- High-frequency trading strategies rely on the “law of large numbers” for their high Sharpe ratios.\n", + "- High-frequency trading strategies typically generate the highest\n", + "long-term compounded growth due to their high Sharpe ratios.\n", + "- High-frequency trading strategies are very difficult to backtest\n", + "and very technology reliant for their execution.\n", + "- Holding a highly leveraged portfolio of low-beta stocks should\n", + "generate higher long-term compounded growth than holding unleveraged portfolio of high-beta stocks." + ] } ], "metadata": {