Showing posts with label Aresh saharkhiz. Show all posts
Showing posts with label Aresh saharkhiz. Show all posts

Saturday, July 28, 2012

Summary Book 1 - Chapter 4 Evaluating Trading Strategy Performance


Quantitative trading strategies harnessing the power of quantitative techniques to create a winning trading program:

Poppers theory focuses on the growth of human knowledge and the methods used in making new discoveries.

never accept that a strategy is going to be profitable.

assume the strategy is profitable until a better strategy is found or a there is a problem with it in historical data and performance.

a trading theory may change and not hold accross time. no strategy will continue to be profitable forever.

Flaws in current performance measures of a trading strategy:

Net Profit- widely quoted performance statistics. it is the dollar profit earned or lost during the life of the back-test.

maximize return per unit of risk.
Note:Absolute returns are not important as they do not measure the risk involved such as volatility of the stock,standard deviation of the price.


Profit factor- calculated by dividing the total profit gained on winning trades by the total loss on losing trades.
profitable strategy factor will be greater than one. unprofitable strategy will be less than one.

Gross Profit +1750
Gross Loss -1500
1750/1500 = profit factor of 1.17

profit to drawdown- ratio of net profit to maximum drawdown.
a drawdown occurs when net profit falls from its highest point.
calculated each trading day with the maxium value being the maximum drawdown.

deviding net profit by maximum drawback is a measure of reward to risk.
Riskier strategies have larger maximum drawdowns.

the problem with this is: this method net profit does not increase linearly with time.
 profit to drawdown ration varies depending on the length of time in the test.

One of my requirements for performance measures is the ability to compare various strategies regardless of the time frame studied.

Percent of profitable trades- used to gauge strategy success. the number of winning trades divided by the total number of trades in the back-test.

BETTER PERFORMANCE MEASURE
KRatio and sharpe ration, measures compare reward to risk in order to assess strategy performance.

Sharp Ratio:
if return is widely dispersed with large and winner and loser,its a risky trade because of the high standard deviation.
if returns are wrapped around the mean, the strategy has a smaller standard deviation and is less risky.

Sharpe ratio = Average return / Standard deviation of returns * Scaling factor

the scaling factor is the square root of time periods in a year.

when testing a strategy calculate the sharpe ratio and focus on finding strategies that produce sharpe ratios greater than positive one.

the sharpe ratio is its flaws. so to compliment it we use the K-ratio.
instead of looing at returns irrespective of when they occur, the Kratio calculates performance based on the stability of the equity curve.

first we need to create an equity curve to calculate K-ratio (graph of cumulative profits over time)

equity curve should increase linearly with respect to time.

if risk is constant thoughtout the life of the test, no adjustments need to be made to the equity curve.

start by calculating a linear regression (best fit line that minimizes the square error between forecast and actual) of the equity curve.

b1 in the equity curve is the proxy for reward in the k-ratio.

equity cruve i = b0 + b1 . trend i

risk in k-ratio is measured by calculating the standard error of the b1 regression coefficient.

large standard error indicates slope of the equity curve is inconsistent over time. small errors indicate consistent equity curve.
calculating K-Ratio in Excel


The K-ratio is calculated by dividing the b1 estimate by both the standard error of b1 and the number of periods in the performance test. By dividing by the number of data points, we normalize the K-ratio to be consistent regardless of the periodicity used to calculate its components.

K-ratio is a unitless measure of performance, Weekly performance of corn futures can be compared with tick data performance of trading IBM.


The Sharpe and K-Ratio are measures of trading strategy performance.

COMPARISON OF BENCHMARK STRATEGIES
the following 2 are benchmark strategies.

Channel breakout-trend following method
     Enter long if today’s close is the highest close of the past 40 days.
     Exit long if today’s close is the lowest close of the past 20 days.
     Enter short if today’s close is the lowest close of the past 40 days.
     Exit short if today’s close is the highest close of the past 20 days.
moving average crossover-trend following method
     Enter long if the 10-day simple moving average of closes crosses above the 40-day simple moving
average of closes.
     Enter short if the 10-day simple moving average of closes crosses below the 40-day simple moving
average of closes.

we calculate the K-Ratio and sharpe ratio of the channel breakout and moving average crossover over a portfolio of markets.

always trade with the trend.trend following is profitable as shown by history.

a strategy may decline through the days, meaning the average of returns may reduce every year for a
certain strategy.

Equity Curve and Regression Band Forecast. We can forecast equity growth using past data. If equity
falls below the lower band, we must reevaluate the potential of the strategy.

any strategy that performs badly can always be reversed to generate profit. simply by doing the opposite. sell when the signal is a buy, buy when the signal is a sell.

Some trading strategies may produce profits due solely to an overall rising or falling underlying market.

sometimes a strategy may work because of the markets uptrend. in order to remove the bias of the markets up direction we use the following formula:

return strategy = b0 + b1 return market + b2 returnmarket^2 + epsilon

if the t-statistics is less than +1 then chances are its performing due to markets runup or decline.
if t-statistics is greater than one, then strategy is valid and not biased

Magical thinking: people think that their behaviour causes something to happen while its another power that is making it happen. just because a strategy worked a few times in history doesnt mean it will work again.

Wednesday, July 25, 2012

Summary Book 1 - Chapter 3 Creating Trading Strategies

Quantitative trading strategies harnessing the power of quantitative techniques to create a winning trading program:

 3 building blocks for a trading system
1. Enteries - signals of buy and sell
2. Exits - indicate expected value of a trade has diminished to the point that the trade should be closed.
3. Filters - persuade the trader to only take entries with highest expected profits over the life of the system

Trend-following technique - buy signal while the market is in a period of strength.
sell signals are during period of weakness.

Moving average-the mean of a time series updated each trading day.
Most common moving averages are:Simple,Weighted, Exponential.

The simple moving average is an average of values recalculated every day.
Sum the previous days closing value and devide by the number of days.

Exponential moving average is calculated using todays price and yesterdays moving average value.alpha is the smoothing factor which is 2 devided by the number of days plus 1.

Sample Computation on EXCEL

A weighted moving average assigns higher weights to more recent data.

Trading signals are triggered when the price of a stock goes above the moving average, higher prices are likely and it signals that its time to buy.

When prices cross below the moving average, a declining market is expected and its time to sell.

a moving average of 20 to 100 days are commonly used to generate buy and sell signals. shorter moving averages will respond quicker to recent price movement.

longer moving averages produce trading signals infrequently.

when combining moving average methods such as exponential and simple, 10 and 40 days are used to generate signals.

if a market is prone to short and violent moves with many reversals along the way, moving average systems are likely to suffer. this drawback is called a whipsaw, asociated with choppy market action.

Channel breakout;
channels created when plotting a running tally of the highest highs and lowest lows over a fixed interval of days.

in a 40 day channel breakout: buy if market close was the highest of the past 40 days.
sell when the market close lower than any other close of the past 40 days.

A surge above the upper channel line shows extraordinary strength that can signal the start of an uptrend. Conversely, a plunge below the lower channel line shows serious weakness that can signal the start of a downtrend

Momentum-
take the difference between one value and another value at some point in time.
Momentum = Value Today - Value X days ago

Buy when todays close is greater than the close x days ago
Sell when todays close is less than the close x days ago

Volatility breakouts-
large short-term price jumps tend to be precursors of further movement in the same direction.
it is comprised of 3 pieces:
1. reference value - measurement price of the move from the start
2. volatility measure - computes the typical valatility of the market to separate significant movement from random price changes
3. volatility multiplier - determines the sensitivity of price movement required to trigger entry signals.

buy when prices close above the upper trigger.
sell when prices close below the lower trigger.

the most logical valatility measure is to calculate a standard deviation of price returns.


another volatility measure is to calculate the average true range.
1. the largest value of todays high minus todays low
2. largest value of todays high minus yesterdays close
3. largest value of yesterdays close minus todays low

 Excel Sheet showing how to calculate the 14 day Average True Range


average the true range over a set number of days to calculate ATR (average true range)

another volatility measure is the standard deviation of market prices.
this method does not allow strict interpretation using the normal distribution.

Volatility breakout entry points are derived by multiplying the volatility multiplier
by the volatility measure and adding that value to the reference value.

Volatility Breakout Rules
-Upper trigger = Reference Value (yesterday’s close, today’s open, short-term moving average) plus the Volatility Multiplier times Volatility Measure (standard deviation of price returns, average true range, standard deviation of
price). Buy when today’s close is greater than the upper trigger.
-Lower trigger = Reference Value (yesterday’s close, today’s open, short-term moving average) plus the Volatility Multiplier times Volatility Measure (standard deviation of price returns, average true range, standard deviation of
price). Sell when today’s close is less than the lower trigger

When a trend has become overextended or exhausted we define the technique as an Oscillator.

Sell signals are given using range statistics to explain that prices have risen too high and buy signals when prices are too low.

the premise behind standard oscillators is that once prices move to levels far from average, a reversal is eminent.

one method is the Relative strength index(RSI is the most popular). a market top is completed when the indicator rises above 70, while bottoms when fall below 30.

RSI sums the price changes of up days and compares them with the price changes of down days to calculate the RSI value.

RSI = 100 - ( 100 / (  1+  (U/D)  )  )
U is the average of all up moves
D is the average of all down moves

NOTE: The Relative Strength Index (RSI) rises and falls between 0 and 100

a stochastic oscillator compares current prices to the high and low range over a look-back period.

Traditional settings use 80 as the overbought threshold and 20 as the oversold threshold
stochastic oscillator

Fast %K stochastic is a smoothed out raw %K using a 3 day moving average
The fast %D stochastic is the smoothed out of the fast %K stochastic using another 3 day moving average.


the Raw %K stochastics = (Todays Close - Lowest low) / (Highest High - lowest low)

The moving average Convergence/Divergence (MACD) is an oscillator created by taking the difference between two exponential

averages.
1. a 12 day exponential weighted average with alpha=0.15
2. a 26 day exponential moving average with alpha=0.075

MACD = 12 Day EMA of close - 26  day EMA of close
MACD signal = 9 Day EMA of MACD

a popular patter of prices
SELL - Key reversal sell
todays high > yesterdays high
todays close < yesterdays close

BUY-key reversal buy
Todays Low < yesterdays low
Todays close > yesterdays close

signals that close profitable trades are called EXITS
signals that close unprofitable trades are called "STOPS"
Profit Targets close profitable

trades using range statistics.if we buy IBM at 100$ and the average true range of the past 20 days above the entry price of 100$ is 2$ then we sell at
100$ + (3)(2$) = 106$ we sell at 106$

A trailing exit has many examples to lock in profit before trade turns.
exit when market makes a 5 day low.
exit when market closes below previous pivot point

a pivot point is created when one days low is lower than both the

previous and following days low. (V Shape)
2 days before and 2 days after. or
3 days before and 3 days after.

LOSING IS A PART OF ALL TRADING (page 94 fail-safe exits)

FAIL SAFE EXIT
the trade goes against you by an amount equal to 2 times the average true range of the past 20 days.

if we buy IBM at 100$ and the average true range is 1.5$ we sell if 100 - (2*1.5$) = 97$ to minimize losses.

filters are used to either give a green light to trade or a red light that overrides buy and sell signal.

Trend filters:
Average directional movement index (ADX)
Vertical Horizontal Filter (VHF)

A typical use of a filter is to only take signals when values of these filters are greater than some threshold.

OUTSIDE BOOK SCOPE:
ADX is used to determine the direction and strength of a trend.

1. Calculate the True Range (TR), Plus Directional Movement (+DM) and Minus Directional Movement (-DM) for each period.

2. Smooth these periodic values using the Wilder's smoothing techniques. These are explained in detail in the next section.

3. Divide the 14-day smoothed Plus Directional Movement (+DM) by the 14-day smoothed True Range to find the 14-day Plus Directional Indicator (+DI14). Multiply by 100 to move the decimal point two places. This +DI14 is the Plus Directional Indicator (green line) that is plotted along with ADX.

4. Divide the 14-day smoothed Minus Directional Movement (-DM) by the 14-day smoothed True Range to find the 14-day Minus Directional Indicator (-DI14). Multiply by 100 to move the decimal point two places. This -DI14 is the Minus Directional Indicator (red line) that is plotted along with ADX.

5. The Directional Movement Index (DX) equals the absolute value of +DI14 less - DI14 divided by the sum of +DI14 and - DI14.

6. After all these steps, it is time to calculate the Average Directional Index (ADX). The first ADX value is simply a 14-day average of DX. Subsequent ADX values are smoothed by multiplying the previous 14-day ADX value by 13, adding the most recent DX value and dividing this total by 14.



strong trend is present when ADX is above 25 and no trend is present when below 20.

  • Theory: Large moves are a result of new information entering the markets.This information may not be immediately digested by all market participants.
  • Trading rule: Buy when today’s price change is greater than two standard deviations of the 20-day standard deviation of price changes.
  1. Formulate a theory
  2. Create an experiment
  3. draw conclusion

"I learned that following a detailed trading plan based
on sound historical results is the only way to trade effectively. And oh yeah, make
sure you’re awake and sober when placing your trades."

Summary Book 2 - Chart Patterns (Chapter 2)

For Up Trendlines
3 points on a trendline is valid.
draw the trendline along two minor lows in a forming price to see where the 3rd point may be.
a trendline starting with two close touches may not hold up in the longer term.
two points spaced too far apart may not have much value.
On average, trendlines with touches spaced widely apart perform better than those spaced close together.
on average long trendlines perform better than short ones
increasing the volume of stock as the trend continues is a good sign.
a breakout occurs when prices close below the trendline.
a high volume downward breakout propels prices further.

a plunge is a price trend that shows little price overlap from day to day leading to, but not including the breakout day.

INCOMPLETE