Showing posts with label System Testing. Show all posts
Showing posts with label System Testing. Show all posts

Thursday, May 5, 2011

Sensex: Quantifying Sell in May

There is a very famous investment philosophy to Sell in May and return in October.

Lets see how that strategy works for our Indian Markets.

The conditions are to Sell on first day in May and Buy on first day on October with commissions of 5 bps.
We are testing this from year 1980 and 2010 so that it covers most of the history available.

How are the results? Well, its not profitable. The initial equity of $10K got reduced to $9.8K while buy and hold was massively up by ~2 times.

Here's the snap shot of the performance.



There were only 10 profitable years among the 31 years of testing with the year 2010 contributed massively $4780  to the results.
The profits are completely skewed by a single year.

This clearly shows that the strategy is not profitable in itself but there was one profitable trend. That was the higher probability of a dip in early May which lasts for 2-3 weeks on an average.

Here's the equity graph.


Wednesday, February 9, 2011

Quanting India: Sensex Mean Reversion study

Markets display a very peculiar phenomenon called Mean reversion. Without this there the prices would be just random. See more on this concept at Wikipedia. Link here.

There can be multiple variations of this concept which are applied to markets. Like closing price relation to high or low etc.

One widely followed is the mean reversion to moving averages like 50, 100 and 200 day MA. There are already well defined trading strategies based on the price and the moving averages.

For today let us consider the 50 Simple Moving Average and Sensex. I am taking Sensex because it has longest price history in Indian indices so the strategies can be back tested well.

To look for mean reversion to 50 DMA lets plot the Sensex closing w.r.t 50 DMA.

We get the following chart:



There are few spikes but more or less the prices have stayed within a band. Doing the statistical analysis to the values we get the following:



The values are consistent with the bullish bias of Indian markets for last 30 years.
Going further I calculated the lows of the data set in the bull phase and high points in the bear phase. These values can tell us the probable points where the buying in done in bull and selling in bear phase. And this particular trade has the highest probability of success till our view of market phase is correct.

Well now how to trade with the above strategy at this point.
Looking at the extreme right hand side of the chart of last 2 years we can have some idea about the current setup. The ratio is at the lows of the bull run where generally the buying comes.


Does this indicate that buying can be done at this point. Well there is still no confirmation in the reversion strategy as of now as there are a few elements missing for triggering buy at these levels.

I will update in future posts if there is any indication in that respect.

The above post is meant for quant strategy discussion rather than any investment advice.


Wednesday, January 26, 2011

Year 2010 Nifty: System testing the Color code

For long I have been writing about the color of the indices which defines the trend.
I think the best way to know about any strategy is to backtest the strategy. So let us test the Nifty for the color system.

Time frame: Daily for year 2010. Testing only for Longs no Short trade tested.

Buy Condition: Buy color
Sell Condition: Neutral or Sell color

Commissions: 0.10% of trade.



The results
The system was equal to buy and hold but the profit factor of the trade at 4.7 makes it attractive with only 10 long trades for the year.

Also the maximum draw down for a single trade was about 3% which is reasonable given that we are trading on daily timeframe.



More details later.

Thursday, January 20, 2011

Bank Nifty: System Testing Trend Defining Line

Last month I wrote about a simple concept of buying and selling based on a buying and selling on cross of a simple trend line. Post here.

Then I tested the Nifty daily data of last 15 years and the system was outperforming the buy and hold. Post here.

Today I am testing the same concept for Bank Nifty on weekly charts. The main reason I am testing on weekly instead of daily charts is that the Bank Nifty being a high beta index has more whipsaws on daily charts and the test conditions being very simple it generates a lot of trades some even by just 2 points lower close.

Also there are always different system performing well on different timeframes and we should always trade them in that very timeframe for maximum advantage.

Please see this post as an endeavor to quantifying some technical strategies and then optimize them for better trading results.

Lets look at the results:

Buy & Hold out performance: 54%
Profit Factor (Profit/ Loss):      5.3
Absolute Drawdown:              513 points

Time frame: Daily for last 10 years on Bank Nifty spot.

Buy Condition: Close above the TDL.
Sell Condition: Close below TDL

Short Condition: Close below TDL
Profit Book Condition:  Close above the TDL.

Commissions: 0.10% of trade.
Trade Entry: Buy/Sell on next open bar i.e. if signal is generated before today's close then buy/sell tomorrow open. This is to have a realistic results and avoids preempting the signal though we loose a lot by waiting for next candle.

As can be seen these are very simple rules to trade.

Output

Equity curve is attached.

* CNX BANK INDEX (70001968)
Simulation Date 20/01/2011 12:17:04 PM 577 Weekly Bars 07/01/2000 Through 19/01/2011 (4030 Days)
Points Only Test
Performance
Profit 14724.5876 Pts
Performance N/A
Annualized Performance N/A
Buy & Hold Profit 9559.2855 Pts
Buy & Hold Performance N/A
Buy & Hold Annualized Performance N/A

Trade Summary
Total Trades 31
Trade Efficiency -3.59 %
Average Profit/Average Loss N/A


Profitable Trades
Total 15
Long 10
Short 5


Average Profit 1206.4348 Pts
Highest Profit 3907.3321 Pts
Lowest Profit 32.2313 Pts
Most Consecutive 2


Unprofitable Trades
Total 16
Long 5
Short 11


Average Loss -210.7459 Pts
Highest Loss -830.6802 Pts
Lowest Loss -25.8716 Pts
Most Consecutive 5


Maximum Position Excursions
Long Favorable 5257.9317 Pts
Short Favorable 4073.1338 Pts
Long Adverse -931.1746 Pts
Short Adverse -958.5298 Pts


Trade Efficiency
Average Entry 60.11 %
Average Exit 36.30 %
Average Total -3.59 %


Average Long Entry 71.38 %
Average Long Exit 42.19 %
Average Long Total 13.57 %


Average Short Entry 49.54 %
Average Short Exit 30.78 %
Average Short Total -19.69 %
Performance Indices
Buy & Hold Index 54.03 %
Profit/Loss Index 81.37 %
Reward/Risk Index 96.63 %

Accounting
Initial Equity 0.0000 Pts
Trade Profit 18096.5213 Pts
Trade Loss -3371.9338 Pts
Commissions 115.0702 Pts
Interest Credited 0.0000 Pts
Interest Charged 0.0000 Pts
Final Equity 14724.5876 Pts
Open Positions 0.0000 Pts


Account Variation
Highest Account Balance 15565.2663 Pts
Lowest Account Balance -513.0161 Pts
Highest Portfolio Value 5257.9317 Pts
Highest Open Drawdown -513.0161 Pts
Highest Closed Drawdown -461.0274 Pts


Account Events
Margin Calls 0
Overdrafts 0


Profitable Timing
Average Trade Length 30
Longest Trade Length 76
Shortest Trade Length 5
Total Trade Length 451


Unprofitable Timing
Average Trade Length 6
Longest Trade Length 21
Shortest Trade Length 1
Total Trade Length 104


Out of Market Timing
Average 7
Longest 21
Total 22

Tuesday, December 14, 2010

System Testing Trend Defining Line

I did a simple system trade on the trend defining line (TDL from now onwards) as described here.

The idea was to buy and sell on cross up or down.
Brief summary:

Time frame: Daily for last 15 years on Nifty spot.

Buy Condition: Close above the TDL.
Sell Condition: Close below TDL

Short Condition: Close below TDL
Profit Book Condition:  Close above the TDL.

Commissions: 0.10% of trade.
Trade Entry: Buy/Sell on next open bar i.e. if signal is generated before todays close then buy/sell tommorrow open. This is to have a realistic results and avoids preempting the signal.

As can be seen these are very simple rules to trade.

Output
 
3945 Daily Bars 23/01/1995 Through 30/11/2010 (5790 Days)

 
Performance
Profit
5681.2447 Pts
Performance
N/A
Annualized Performance
N/A
Buy & Hold Profit
4819.6582 Pts
Buy & Hold Performance
N/A
Buy & Hold Annualized Performance
N/A

Trade Summary
Total Trades
335
Profitable Trades
Total
115
Long
64
Short
51


Average Profit
147.2962 Pts
Unprofitable Trades
Total
220
Long
103
Short
117


Average Loss
-51.1719 Pts
Accounting
Initial Equity
0.0000 Pts
Trade Profit
16939.0650 Pts
Trade Loss
-11257.8203 Pts
Commissions
784.7109 Pts
Interest Credited
0.0000 Pts
Interest Charged
0.0000 Pts
Final Equity
5681.2447 Pts






Drawdown
Highest Account Balance
5791.9947 Pts
Lowest Account Balance
-278.9460 Pts

Profit Factor: 1.5

Equity chart:


Result:
The system outperforms Nifty buy and hold by 25% over the last 15 years without much efforts.

There could be some minor variation in the results when we use Nifty futures instead of spot. 
I will dissect the trading system in later posts.

Friday, December 10, 2010

A trend defining line

Would it be not easy to have a single line define the trend. So that we go long on cross above it and then sell on cross down.

It would be more easier to follow and tradable.

Well I think there does exists such a line. But beware it is not a holy grail. It does fails many times but will make sure that you will never have that left out feeling and  can give better returns on a half yearly timeframe.

Any ideas or comments on such a line.

The back tested results link for Nifty and Bank Nifty.

System Testing Trend Defining Line

Bank Nifty: System Testing Trend Defining Line