Finished to Chapter 10, 37% of book

master
Jason Zhu 2020-08-23 23:40:56 +10:00
parent f443a4b2f3
commit bda73ca27c
8 changed files with 196 additions and 1 deletions

View File

@ -1,3 +1,3 @@
# building-winning-algo-trading-system-book # building-winning-algo-trading-system-book
A book review for Building Winning Algorithmic Trading System by Kevin J Davey A book review repository for Building Winning Algorithmic Trading System (A Trader's Journey From Data Mining to Monte Carlo Simulation To Live Trading) by Kevin J. Davey

View File

@ -0,0 +1,2 @@
## Chapter 5 Testing and Evaluating a Trading System

View File

@ -0,0 +1,33 @@
# Chapter 6. Preliminary (初步的) Analysis
A complete performance report is long, only few worth notice.
## Ground Rules
1. Performance report should be based either on live data or on a walk-forward test.
2. Should be multiple years of data (5 ~ 10 years), with a multiple trades (30 ~ 100 trades)
3. Review performance reports without position sizing applied (only view single trade strategy)
4. Accurate assumptions for commission and slippage.
## Numbers to look in performance report
1. **Total Net Profit**: e.g. with a walk-forward backtest, annual net profit should be $5,000 per year per contract minimum, preferably $10,000 or more.
2. **Profit Factor**: gross profit divided by the gross loss (including commissions) for the entire trading period.
1. Anything over 1.0 is good
3. **Total Number of Trades**: ensure enough trades are taken. (120 ~ 400 in reports)
4. **Average trade net profit**: it's after commissions and slippage.
5. **Average Losing Trade**: combined with average trade net profit to calculate expectancy
6. **Expectancy (期待)**
1. Normal expectancy = $ average winners * win % + $ average losers * lose % = average trade; average $ loser is -ve
2. **Tharp Expectance (promoted by author)** = (average $ winners * win% + average $ losers * lose %)/(- average $ losers);
1. It's risk-adjusted. i.e. every $ you risk, what's your expected return?
7. **Total slippage and total commissions**
1. Total slippage (spread) is more critical. (as we buy at ask, sell at bid)
8. **Maximum Drawdown**: how much an investment or trading account is down from the peak before it recovers back to the peak.
## Graph to look after performance report
1. **Closed trade equity graph**: An equity curve is a graphical representation of the change in the value of a trading account over a time period
1. 1st thing in equity curve: slope.
2. 2nd thing in equity curve: flat periods. A good strategy should steadily grow.
3. 3rd thing in equity curve: drawdown periods. No drawdown? Problem hidden.

View File

@ -0,0 +1,59 @@
# Chapter 7. Detailed Analysis
Use Monte Carlo Analysis at later stage.
## What is Monte Carlo Analysis/Simulation
Author's Monte Carlo Simulation Excel sheet is not appropriate for me, read
* [Monte-Carlo Simulation Engine](https://medium.com/fintechexplained/monte-carlo-simulation-engine-in-python-a1fa5043c613) for reference
Benefit of Monte Carlo Simulation, Answering following questions:
* What's my **risk of ruin (account get wiped out)** for a given account size?
* What are the chance of my system's having a maximum drawdown of X percent? (How dangerous is my strategy)
* What kind of annual return can I expect from this trading system?
* Is the risk I am taking to trade this strategy appropriate? for the return I am receiving?
## Inputs to Monte Carlo Simulation
* **Base Starting Equity**
* **Stop Trading if Equity Drops Below $**: threshold consider account "ruined"
* **# Trades, 1 Year**, (not so important for me)
* **Individual Trade Results** (should be calculated by python)
## Simulator Output
Output sheet should contain:
* **Starting Equity**
* **Risk of Ruin**: within a year's time, the percentage of account drop below threshold
* It's obvious that larger starting equity mean lower chances of ruin
* **Median Drawdown**: Median value of **maximum drawdown**. Maximum drawdown is the maximum percentage drop in account size from an equity peak (measured from the previous equity peak).
* e.g. $5,000 drawdown, after peak equity of $20,000 = $5,000 / $20,000 = 25 percent drawdown
* For every simulation iteration, there will be one maximum percentage drawdown. Then iterations form a distribution (from 0% to 100%). Median is from this distribution.
* No reason why use median, also can use mean if it makes more sense.
* **Median $ Profit, Median Return**: similar as median drawdown
* **Return/Drawdown (aka Calmar Ratio calculated over 3-year)**: Considered most important.
* This ratio shows "it takes Y risk to make X"
* Higher, the beteer
* **PROB > 0**: the percentage that the system will make money in the first year of trading.
Important Performance Parameter
| Parameter | Source | Utilized During | Threshold |
| ----------------------------------------- | ---------------------- | --------------- | ------------------------------------------------ |
| Total net profit | Performance Report | Initial Review | ~$10K per year per contract |
| Profit Factor | Performance Report | Initial Review | > 1.0 OK, > 1.5 ideal |
| Average trade net profit | Performance Report | Initial Review | >$50 per contract |
| Tharp Expectancy | Performance Report | Initial Review | >0.10 |
| Slippage and commission | Performance Report | Initial Review | Discard if $0, otherwise $5 commission 1-2 ticks |
| Maximum Drawdown | Performance Report | Initial Review | Should be much smaller than total net profit |
| Equity curve Slope | Equity Curve | Initial Review | Ideally rises at 45-degree angle |
| Equity curve flat periods | Equity Curve | Initial Review | Short in duration |
| Equity curve drawdown, depth and duration | Equity curve | Initial Review | Proportional to overall curve |
| Equity curve fuzziness | Equity curve | Initial review | Small is ideal |
| Risk of ruin | Monte Carlo simulation | Detail review | < 10% |
| Median maximum drawdown | Monte Carlo simulation | Detail review | < 40% |
| Median % return | Monte Carlo simulation | Detail review | > 40% |
| Return/drawdown ratio | Monte Carlo simulation | Detail review | >2.0 |

View File

@ -0,0 +1,4 @@
# Chapter 8. Designing and Developing Systems
![My Strategy Development Process](img/fig_8_1.png)

View File

@ -0,0 +1,74 @@
# Chapter 10. Trading Idea
Following topics to cover:
* Entry rules
* Exit rules
* Market selection
* Time frame/bar size
* Programming
* Data considerations
## How will you Enter a Market?
Entry Lovers = people ignore the drawdowns during the trade and say "Look what would happened if you had bought Microsoft way back when."
Mis-conception:
* The time before entry is really the only time you feel in complete control. You tell the market, “Mr. Market, you must do this, that, and the other before I place a trade to enter. If you do not follow my rules, Mr. Market, I will not enter a trade. I am in charge here.” That feels nice, as opposed to the time spent in a trade, where many times you hope and pray the market roller coaster will go your way!
Entry & trading style:
* Long-term swing trader (trades lasting weeks to months), an entry a few days early or a few days late won't affect
* Scalping (抽头转卖) trader: entry becomes important. An entry off by a tick or two could turn a winning system into a piece of garbage.
After getting ideas, first turn it into *pseudo code*: "If close this bar is the highest close of last X bars, then by next bar at market."
* pseudo code can help to identify any important variables.
Few tips:
* *Keep it simple*
* *Limit number of input parameters*. More parameters means more chance of over-fitting
* *Try to think differently*. Moving average crossovers hav been over used.
* *Use a single rule at first*. Slowly add new conditions if they significantly improve performance. Many entry conditions may turn out useless.
## How will you Exit a Market?
Most important, to get maximum profit or minimum loss. Need spend a lot of time
Common ways of exiting a market;
* **Stop and Reverse**: A new entry position means exit for existing one.
* **Technical-based exits**: Support/resistance lines, moving averages, candlestick patterns, etc. Need coop with existing positions
* **Breakeven (保本) stops**: Often seem to limit profit, since they typically exit on a retracement (回撤), with market then resuming its earlier trend
* **Stop-losses**: when coupled with good entries, can help prevent catastrophe.
* **Profit targets**
* **Trailing stops**
## What Markets Will You Trade?
Two schools of trading system:
* One for all: Applying one trading system over all market, tuning parameters for each market.
* Pro: If it works on all markets, it is robust.
* Con: Development is difficult. Need to relax their acceptance criteria
* One for a particular market
* Pro: Highly customization. Easier to create.
* Con: Not robust.
## What Type of System Do You Want?
Author's preference, start a trading strategy as a day-trading. (i.e. in/out, multiple trades a day).
## What Time Frame/Bar Size Will You Trade?
Time Frame = length of time for each bar.
* **Time frame contraction (收缩) and dilation (扩散)** used by many trader:
* First, Test a strategy with a 10-min time frame
* If succeed, testing on 9-min bar
* Problem: add/minus 1 min will lead to change of indicator
## How will you Program the Strategy?
Program it by yourself.

View File

@ -0,0 +1,23 @@
# Chapter 9 Stragey Development - Goals and Objectives
**SMART**:
* **Specific**: specific goal;
* **Measurable**: want to have a trading system with certain performance metrics.
* **Attainable**: "I need to develop a trading system that will provide 500 percent annual return with less than 2 percent maximum drawdown" NOT REALITY!!!
* **Relevant**: Heart and mind must be fully committed.
* **Time bound**: Trading (creating strategies) cost time.
Create first SMART goal, implement trading strategy, then re-evaluate it after trails
Using a wishlist to create a SMART goal:
| Like/Dislike | Item | Does System Meet This ? |
| ------------ | ---------------------------------- | ----------------------- |
| Likes | Trades e-minis only | |
| | X % annual return, Y% max drawdown | |
| | Calmar > Z, Sharpe > W | |
| | No overnight exposure | |
| | 2 or fewer indicator | |
| | 100% mechanical | |
| Dislikes | More than 2 trades per day | |
| | Adds to losing positions | |

BIN
img/fig_8_1.png 100644

Binary file not shown.

After

Width:  |  Height:  |  Size: 152 KiB