more renaming

This commit is contained in:
2026-06-22 01:26:17 -07:00
parent cd86381692
commit f7a72f2cf5
3 changed files with 0 additions and 0 deletions
@@ -0,0 +1,460 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "ec753176",
"metadata": {},
"source": [
"# Notes"
]
},
{
"cell_type": "markdown",
"id": "b13688b9",
"metadata": {},
"source": [
"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."
]
},
{
"cell_type": "markdown",
"id": "5df7046f",
"metadata": {},
"source": [
"## Daily routine"
]
},
{
"cell_type": "markdown",
"id": "5a622bb3",
"metadata": {},
"source": [
"\"The largest block of time I need to spend is in the morning\n",
"before the market opens: I typically need to run various programs to\n",
"download and process the latest historical data, read company news\n",
"that comes up on my alert screen, run programs to generate the orders for the day, and then launch a few baskets of orders before\n",
"the market opens and start a program that will launch orders automatically throughout the day. I would also update my spreadsheet\n",
"to record the previous days profit and loss (P&L) of the different\n",
"strategies I run based on the brokerages statements. All of this takes\n",
"about two hours.\" - Quant trader morning routine"
]
},
{
"cell_type": "markdown",
"id": "f0855890",
"metadata": {},
"source": [
"## 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",
"metadata": {},
"source": [
"- ***directional trades*** - long or short only\n",
"- ***dollar-neutral trades*** - hedged or pair trades\n",
"- ***dollar neutral portfolio*** - The market value of the long positions equals the market value of the short positions\n",
"- ***market neutral portfolio*** - The beta of the portfolio with respect to a market index is close to zero, where beta measures the ratio between the expected returns of the portfolio and the expected returns of the market index\n",
"- ***Leverage*** - Borrowing funds to buy an investment\n",
"- ***slippage*** - The difference between the price that triggers the trading signal and the average execution price of the entire order"
]
},
{
"cell_type": "markdown",
"id": "865b04b1",
"metadata": {},
"source": [
"- ***equaity curve***: A line chart of your portfolio's value over time\n",
"- ***drawdown***: The decline from a peak to a subsequent trough, expressed as a percentage. It's a measure of loss from a prior high, not from your starting point.\n",
"- ***maximum drawdown***: The largest peak-to-trough decline over the entire history of a strategy. It answers: \"What's the worst loss someone could have experienced if they invested at the worst possible time?\" It's one of the most common risk metrics used to evaluate strategies.\n",
"- ***high watermark***: The highest portfolio value ever reached\n",
"- ***maximum drawdown duration***: The longest amount of time spent below the high watermark.\n",
"- ***basis points***: 1 basis point is 0.01%\n",
"- ***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",
"metadata": {},
"source": [
"## Ruling out bad strategies"
]
},
{
"cell_type": "markdown",
"id": "303f8dc1",
"metadata": {},
"source": [
"\n",
"- If a strategy trades only a few times a year, chances are its\n",
"Sharpe ratio wont be high. This does not prevent it from being\n",
"part of your multistrategy trading business, but it does disqualify\n",
"the strategy from being your main profit center.\n",
"- If a strategy has deep (e.g., more than 10 percent) or lengthy\n",
"(e.g., four or more months) drawdowns, it is unlikely that it will\n",
"have a high Sharpe ratio. I will explain the concept of drawdown\n",
"in the next section, but you can just visually inspect the equity\n",
"curve (which is also the cumulative profit-and-loss curve, assuming no redemption or cash infusion) to see if it is very bumpy\n",
"or not. Any peak-to-trough of that curve is a drawdown. (See\n",
"Figure 2.1 for an example.)\n",
"\n",
"As a rule of thumb, any strategy that has a Sharpe ratio of less\n",
"than 1 is not suitable as a stand-alone strategy\n",
"\n",
"For a given strategy, its important to ask the following:\n",
"\n",
"- Does it outperform a benchmark?\n",
"- Does it have a high enough Sharpe ratio?\n",
"- Does it have a small enough drawdown and short enough drawdown duration?\n",
"- Does the backtest suffer from survivorship bias?\n",
"- Does the strategy lose steam in recent years compared to its earlier years?\n",
"- Does the Strategy Suffer from Data-Snooping Bias?\n",
"- Does the strategy have its own “niche” that protects it from intense competition from large institutional money managers?"
]
},
{
"cell_type": "markdown",
"id": "ecc17253",
"metadata": {},
"source": [
"## Backtesting\n"
]
},
{
"cell_type": "markdown",
"id": "98567746",
"metadata": {},
"source": [
"- When gathering data for backtesting, ensure data is split and dividend adjusted.\n",
"- A backtest that relies on high and low data is less reliable than one that relies on the open and close\n",
"- Typically, an extreme return should be accompanied by a news announcement, or should occur on a day when the market index also experienced extreme returns. If not, then your data is suspect."
]
},
{
"cell_type": "markdown",
"id": "0dbd8630",
"metadata": {},
"source": [
"$$\\text{Annualized Sharpe Ratio} = \\sqrt{N_T} \\times \\text{Sharpe Ratio Based on }T$$"
]
},
{
"cell_type": "markdown",
"id": "319f28df",
"metadata": {},
"source": [
"Incorporate transaction costs into backtests. Transaction costs include:\n",
"\n",
"- Commission\n",
"- Liquidity cost\n",
"- Opportunity cost\n",
"- Market Impact\n",
"- Slippage\n",
"\n",
"Try to combine all of these into a \"one way transaction cost\" (onewaytcost)"
]
},
{
"cell_type": "markdown",
"id": "1cbf1e0a",
"metadata": {},
"source": [
"Potential backtest performance issues:\n",
"\n",
"- Data: Split/dividend adjustments, noise in daily high/low, and\n",
"survivorship bias.\n",
"- Performance measurement: Annualized Sharpe ratio and maximum drawdown.\n",
"- Look-ahead bias: Using unobtainable future information for past\n",
"trading decisions.\n",
"- Data-snooping bias: Using too many parameters to fit historical\n",
"data, and avoiding it using large enough sample, out-of-sample\n",
"testing, and sensitivity analysis.\n",
"- Transaction cost: Impact of transaction costs on performance.\n",
"- Strategy refinement: Common ways to make small variations on\n",
"the strategy to optimize performance."
]
},
{
"cell_type": "markdown",
"id": "8047f4f0",
"metadata": {},
"source": [
"## Execution Systems: Why does actual performance diverge from expectations?"
]
},
{
"cell_type": "markdown",
"id": "30a1531a",
"metadata": {},
"source": [
"- Do you have bugs in your ATS software?\n",
"- Do the trades generated by your ATS match the ones generated\n",
"by your backtest program?\n",
"- Are the execution costs much higher than what you expected?\n",
"- Are you trading illiquid stocks that caused a lot of market impact?\n",
"- Strategy may have suffered from data-snooping bias or regime shift"
]
},
{
"cell_type": "markdown",
"id": "d5ea890d",
"metadata": {},
"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 stocks return that cannot be explained by these common factor returns is deemed a specific return\n",
"\n",
"Each stocks specific return is assumed to be uncorrelated to another stocks."
]
},
{
"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": {
"language_info": {
"name": "python"
}
},
"nbformat": 4,
"nbformat_minor": 5
}