CustomMenu

Showing posts with label Rotation. Show all posts
Showing posts with label Rotation. Show all posts

Wednesday, September 28, 2016

Momentum Rotation System AmiBroker Code

I've received several requests for details on the AmiBroker (AB) code and settings used for the backtest shown in my April post: Momentum Rotation 60 Day ROC System Results. That post used the AmiBroker Formula Language (AFL) code from my article in March 2015.  That was a long time ago, so here is the 60 day momentum rotation system AFL again:
SetBacktestMode( backtestRotational );

// 1 ###### BACKTESTER SETTINGS - 1. GENERAL TAB 
SetOption("InitialEquity", 100000);
SetOption("MinShares", 1);
SetOption("MinPosValue", 0);
SetOption("FuturesMode", False);
SetOption("AllowPositionShrinking", False);
SetOption("ActivateStopsImmediately", False);
SetOption("ReverseSignalForcesExit", False);
SetOption("AllowSameBarExit", False);
RoundLotSize = 0;
TickSize = 0;
MarginDeposit = 0;
PointValue = 1;
SetOption("CommissionMode", 2);
SetOption("CommissionAmount", 7.95);
SetOption("InterestRate", 0);
SetOption("AccountMargin", 100);
SetOption("MarginRequirement", 100);

// 2 ###### BACKTESTER SETTINGS - 2. TRADES TAB 
BuyPrice = SellPrice = ShortPrice = CoverPrice = Close;
SetTradeDelays( 1, 1, 1, 1);

// 5 ###### BACKTESTER SETTINGS - 5. PORTFOLIO TAB 
//SetOption("MaxOpenPositions",   1);
// check the box to "Add artificial future bar..."
// Limit trade size as % - use 10 for live trading
// check the box to "Disable trade size limit..."
SetOption("UsePrevBarEquityForPosSizing", False);
SetOption("UseCustomBacktestProc",  False);

// 6 ###### BACKTESTER SETTINGS - 6. WALK FORWARD TAB
//SetOption("WorstRankHeld",    1);


Totalpositions = 1;
SetOption("WorstRankHeld", 1);
SetOption("MaxOpenPositions", Totalpositions );
PositionSize = -100 / Totalpositions ;

LastDayOfMonth = IIf( (Month() == Ref( Month(), 1) AND (Month() != Ref( Month(), 2)) ), 1, 0);
TradeDay = LastDayOfMonth ;

Score = ROC(Close, 60);
PositionScore = IIf(Score < 0, 0, Score ); // Long only
PositionScore = IIf(TradeDay , PositionScore , scoreNoRotate);

//Exploration
Filter = 1;
AddColumn(Score ,"Score",1.1);
AddColumn(PositionScore ,"PositionScore ",1.1);
AddColumn(PositionSize ,"Position Size",1.1);
You can download the AFL code above from my Google Drive: 00_60DayMomentum.afl

It is fairly straight forward AFL code, but I've highlighted four key areas:
  • Line 1 - Rotational trading needs to be activated for this system
  • Line 24 - Trade delays are set to 1, which means trades are entered one day after the signal is generated
  • Line 43 - The LastDayOfMonth variable actually stores the second to last day of the month.  This causes the rotation ranking signal to be calculated on the second to last day of the month.  Since our trade delay is one, the trade occurs the following day, the last day of the month
  • Line 47 - If the ROC(60) is negative, then the PositionScore is set to 0, otherwise the PositionScore is set to the ROC(60)

On the second to last trading day of the month, this strategy calculates the 60 day ROC for each product in the portfolio based on closing prices on that day.  If the 60 day ROC is negative, the system sets the PositionScore to 0 for that product.  It then ranks all of the products in the portfolio, selecting the product with the highest rank.  If all products have a rank of 0, the system will move to cash.  On the last trading day of the month, it executes the buy and sell orders at the close - "market on close" orders in live trading.

In addition to the AFL code above, I used the AB settings shown below.  To replicate my results, you'll need to update your AB settings to match mine.

AmiBroker Backtester Settings - General Tab
AmiBroker Backtester Settings General Tab
(click to enlarge)

AmiBroker Backtester Settings - Trades Tab
AmiBroker Backtester Settings Trades Tab
(click to enlarge)

AmiBroker Backtester Settings - Stops Tab
AmiBroker Backtester Settings Stops Tab
(click to enlarge)

AmiBroker Backtester Settings - Report Tab
AmiBroker Backtester Settings Report Tab
(click to enlarge)

AmiBroker Backtester Settings - Portfolio Tab
AmiBroker Backtester Settings Portfolio Tab
(click to enlarge)

AmiBroker Backtester Settings - Walk Forward Tab
AmiBroker Backtester Settings Walk Forward Tab
(click to enlarge)

AmiBroker Backtester Settings - Monte Carlo Tab
AmiBroker Backtester Settings Monte Carlo Tab
(click to enlarge)

AmiBroker Backtester Filter Settings
AmiBroker Backtester Filter Settings
(click to enlarge)

To run my AFL in your installation of AmiBroker:
  • Download my AFL file
  • Open an AB Analysis tab
  • Select my AFL file in the Formula field on the Analysis tab
  • Update the filter settings (shown above) to only run this strategy against a specific Watch List
  • Change the range to "From-To dates", and then select a date range
  • Finally, select the Backtest button to run the strategy

After you have backtesting configured and running, the next step is to automate quote updates and signal generation.  I use the Windows Task Scheduler utility to call JS scripts, that in turn launch AB and AmiQuote.  This topic is beyond the scope of this article, but I may discuss it in the future.

Also, since my last blog post, there have been several articles on momentum trading, and the poor performance of these systems lately.  Here are a few worth reading:


Follow my blog by email, RSS feed or Twitter (@DTRTrading).  All options are available on the top of the right hand navigation column under the headings "Subscribe To RSS Feed", "Follow By Email", and "Twitter"

Thursday, July 14, 2016

Momentum Rotation Multiple System Results

In the last two posts (here and here) we looked at the performance of a simple 60 day momentum rotation system. In this post, we will look at variations on that simple system, and how these variations performed during the same time period, using the same 10 ETF products.  The 10 ETFs used by all of the systems were:

Recall that our simple momentum rotation system only looked at the 60 day/period momentum (ROC) for ranking, and picked the one ETF with the largest positive change.  If all 10 of the ETFs in the group had a negative rate of change...a price today that was lower than the price 60 days ago, then the system moved to cash.  The system only ranked the ETFs in the portfolio on the last trading day of the month.  This is how the system shown in the past posts was structured.  The associated AmiBroker afl code can be found here.

In this post, we will look at six versions of this simple system:
  1. 20 period momentum rotation ( ROC(20) )
  2. 60 period momentum rotation ( ROC(60) )
  3. 120 period momentum rotation ( ROC(120) )
  4. 20 period / 120 period momentum rotation ( ROC(20) + ROC(120) )
  5. 20 period / 120 period smoothed momentum rotation ( ROC(20) + MA(ROC(120), 20) ) 
  6. Weighted momentum rotation ( 0.5*ROC(120) + 0.3*ROC(20) + 0.2*HV(120) )

We will review four variations of each of these six systems, and compare their performance to that of our "standard" 60 period momentum rotation system reviewed in my previous articles.  There are six equity curve charts below, one for each of the six versions listed above.  Each equity curve chart contains the following four variations:
  1. No Ftr (No Filter - NF) - select the ETF that has the greatest ROC of the 10 ETFs; positive momentum or the smallest negative momentum (green)
  2. Slope Ftr (Slope Filter - SF) - select the ETF that has the greatest positive ROC of the 10 ETFs; do not select any ETF if all 10 ETFs have negative ROC -> go to cash (blue)
  3. Brdth Ftr (Breadth Filter - BF) - select the ETF that has the greatest ROC of the 10 ETFs; positive momentum or the smallest negative momentum; if the breadth filter (based on 200 funds) is below a threshold value -> go to cash (gold)
  4. Markt Ftr (Market Filter - MA) - select the ETF that has the greatest ROC of the 10 ETFs; positive momentum or the smallest negative momentum; if the S&P 500 is below the 200 day MA on the S&P 500 -> go to cash (purple)

In addition, each of the six equity curve charts contains the equity curves for two additional systems:
  • Standard - our standard 60 period momentum rotation system with slope filter; no trades taken with negative momentum (red)
  • S&P 500 Index - buy and hold the S&P 500 (orange)

Now let's look at the equity curves for each of the six system variations...

20 Period Momentum ( ROC(20) )
(click to enlarge)
The four systems (No Ftr, Slope Ftr, Brdth Ftr, Mrkt Ftr) use as their core, a momentum system based on the 20 period rate of change (ROC(20)).  The "standard" 60 period momentum system (red) had the greatest overall return, and the four 20 period variations returned about the same as buying and holding the S&P 500 (orange).


60 Period Momentum ( ROC(60) )
(click to enlarge)
In the equity curve chart above, the red curve is the same as the blue curve; the "standard" system is the same as the 60 period system with the slope filter.  Our "standard" system had the lowest overall performance of the 60 period systems, although they all performed better than buy and hold (orange).  The best performance went to the non-filtered system variation (green).


120 Period Momentum ( ROC(120) )
(click to enlarge)
Other than the market filter variation (purple), the other three 120 period variations seem to be recovering from the 2015 performance lull fairly well.  The best performance went to the non-filtered system variation (green).  The "standard" system (red) under performed all 120 period variations.


ROC(20) + ROC(120)
(click to enlarge)
These four variations added the 20 period momentum to the 120 period momentum, yielding a composite momentum score.  The best performance again went to the non-filtered variation, with the breadth filter variation coming in second place.  All variations out performed buy and hold.


ROC(20) + MA(ROC(120), 20)
(click to enlarge)
These four variations added the 20 period momentum to the 20 period moving average of the 120 period momentum.  These variations respond more slowly to the change in the 120 period momentum.  We see the impact of this change on the steep decline in system performance in 2015.  All variations again out performed buy and hold.


Weighted System Components (3)
(click to enlarge)
Lastly, we look at four variations that are based on summing three weighted scores.  These four variations add the 120 period momentum (multiplied by 0.5) with the 20 period momentum (multiplied by 0.3) with the 120 period historical volatility (multiplied by 0.2).  The best performance went to the non-filtered variation, followed by the breadth filter variation.

For me, there were two big take-aways in reviewing these equity curves.  One, all versions and variations experienced poor performance in 2015.  Second, the non-filtered variations, in general, outperformed the other variations.  These same two trends were present in nearly all of the other 30+ product portfolios I tested with these systems.

Finally, I thought it was interesting that just this week the following article was published via QuantpediaHas Momentum Lost Its Momentum?

In the next post, I will share the AmiBroker system settings that I used for these tests, so that you can replicate the "standard" system results.


Follow my blog by email, RSS feed or Twitter (@DTRTrading).  All options are available on the top of the right hand navigation column under the headings "Subscribe To RSS Feed", "Follow By Email", and "Twitter"

Wednesday, July 6, 2016

Momentum Rotation 60 Day ROC System Metrics

It's been a while since my last post.  I had planned on writing this particular article about three months ago, but work got in the way of my writing and testing  Over the next few weeks I will try to close out this series on momentum rotation using my 60 day ROC example written for AmiBroker.  After I finish this series, I will get back to option strategy backtesting

I thought it was interesting how poorly the 60 day ROC momentum rotation system performed during 2015.  During this period, there were no consistent uptrends for the products traded by my example system.  I believe this was the primary reason for the poor performance.  I thought this might be reflected in the 250 day correlation between the products (measured at the end of each year in the test period).  The correlation tables are shown below.  Surprisingly, 2015 did not look dramatically different than some of the other years.

2003 - 250 Day Correlation
2003 250 day correlation between ETFs: EEM, EFA, FXI, IEF, IYR, SHY, SPY, TIP, UUP, and XLV
(click to enlarge)
2004 - 250 Day Correlation
2004 250 day correlation between ETFs: EEM, EFA, FXI, IEF, IYR, SHY, SPY, TIP, UUP, and XLV
(click to enlarge)
2005 - 250 Day Correlation
2005 250 day correlation between ETFs: EEM, EFA, FXI, IEF, IYR, SHY, SPY, TIP, UUP, and XLV
(click to enlarge)
2006 - 250 Day Correlation
2006 250 day correlation between ETFs: EEM, EFA, FXI, IEF, IYR, SHY, SPY, TIP, UUP, and XLV
(click to enlarge)
2007 - 250 Day Correlation
2007 250 day correlation between ETFs: EEM, EFA, FXI, IEF, IYR, SHY, SPY, TIP, UUP, and XLV
(click to enlarge)
2008 - 250 Day Correlation
2008 250 day correlation between ETFs: EEM, EFA, FXI, IEF, IYR, SHY, SPY, TIP, UUP, and XLV
(click to enlarge)
2009 - 250 Day Correlation
2009 250 day correlation between ETFs: EEM, EFA, FXI, IEF, IYR, SHY, SPY, TIP, UUP, and XLV
(click to enlarge)
2010 - 250 Day Correlation
2010 250 day correlation between ETFs: EEM, EFA, FXI, IEF, IYR, SHY, SPY, TIP, UUP, and XLV
(click to enlarge)
2011 - 250 Day Correlation
2011 250 day correlation between ETFs: EEM, EFA, FXI, IEF, IYR, SHY, SPY, TIP, UUP, and XLV
(click to enlarge)
2012 - 250 Day Correlation
2012 250 day correlation between ETFs: EEM, EFA, FXI, IEF, IYR, SHY, SPY, TIP, UUP, and XLV
(click to enlarge)
2013 - 250 Day Correlation
2013 250 day correlation between ETFs: EEM, EFA, FXI, IEF, IYR, SHY, SPY, TIP, UUP, and XLV
(click to enlarge)
2014 - 250 Day Correlation
2014 250 day correlation between ETFs: EEM, EFA, FXI, IEF, IYR, SHY, SPY, TIP, UUP, and XLV
(click to enlarge)
2015 - 250 Day Correlation
2015 250 day correlation between ETFs: EEM, EFA, FXI, IEF, IYR, SHY, SPY, TIP, UUP, and XLV
(click to enlarge)
2016 - 250 Day Correlation
2016 250 day correlation between ETFs: EEM, EFA, FXI, IEF, IYR, SHY, SPY, TIP, UUP, and XLV
(click to enlarge)

Next, I looked at the performance of this system from: 1) 2003 through 2014, 2) 2015 through the first three months of 2016, and 3) 2003 through the first three months of 2016.  These metrics are shown in the table below.

60 day momentum rotation system metrics for different yearly periods
(click to enlarge)

For 2015, there were a few metrics that jumped out at me compared to the 2003 through 2014 period:
  1. The win rate was much lower, so fewer winning trades than typical for this system
  2. The average bars held was higher for both winners and losers, so we were in the trades longer than usual before a momentum change occurred
  3. The maximum consecutive winners and losers was lower, indicating a market with no sectors with strong upward momentum...a zig zagging market
  4. The maximum trade drawdown was lower, indicating no persistent down moves before a trade was exited...weak uptrends and weak downtrends

I also reviewed Monte Carlo simulations for this system (using the same ETF products) from 2003 through 2016.  For the Monte Carlo runs, the position sizing utilized 99% of the available capital for each trade.
Equity curves for 1000 Monte Carlo simulations (2003 - 2016) for the 60 day momentum rotation system
(click to enlarge)

The actual metrics for this simulation are shown in the table below.  The backtesting and Monte Carlo simulations assumed an initial portfolio equity of $100K.

Metrics for 1000 Monte Carlo simulations (2003 - 2016) for the 60 day momentum rotation system
(click to enlarge)

90% of the observed annual return values were at or above 9.86%.  Also in 90% of cases the drawdown was less than or equal to 31.84%.  A negative return for the system should occur in less than 1% of the cases based on the data above.  For the actual bactested system, the annual return was 16.9%.  Even when I performed the simulations with a fixed number of shares per trade, rather than 99% of the portfolio equity, there were no negative annual return values in the Monte Carlo metrics tables.  Using a fixed number of shares per trade eliminates the compounding effect.

In the next article I will show the equity curves for several other momentum rotation systems trading the same products.  Do you think they will also perform poorly during 2015?


Follow my blog by email, RSS feed or Twitter (@DTRTrading).  All options are available on the top of the right hand navigation column under the headings "Subscribe To RSS Feed", "Follow By Email", and "Twitter"

Monday, April 11, 2016

Momentum Rotation 60 Day ROC System Results

In my last post, Yahoo Data and Momentum Rotation - Analysis of 2015 Data, the big take away was the importance of performing a full download / update of historical data before generating your signals.  This is particularly important when using dividend adjusted data, which is typical for most equities and ETFs.  The dividend adjustments need to be reflected in the entire series for a particular product, not just the most recent few months.

In this post we will look at the current performance of a momentum rotation system for AmiBroker that I showed in an earlier post here.  This momentum rotation system ranks a portfolio of products based on their 60 day rate of change.  The product with the largest positive change in the portfolio is selected for entry.  If all of the products in the portfolio have a negative rate of change...a price today that is lower than the price 60 trading days ago, then the system will move to cash.  The system runs on the last trading day of the month, and executes orders at the close - "market on close" orders in live trading.

This momentum rotation system was run against the products listed below in the March 2015 post.  We will use the same products for this post.

So how has this momentum rotation system performed since last March?  Pretty poorly!  March of 2015 was the high water mark for this system's equity curve.  Since that time, the equity curve has dropped 23.82%.

60 Day Momentum Rotation System Equity Curve 2003 - 2016
(click to enlarge)

60 Day Momentum Rotation System Profit Table 2003 - 2016
(click to enlarge)

The ETFs held by date are shown in the chart below.  Early in the life of this system, it was not uncommon to hold the same ETF for several months.  Trade duration has shortened in last few years.

60 Day Momentum Rotation System - Positions By Date - 2003 - 2016
(click to enlarge)

The score for each ETF by date can be downloaded from Google Docs: Rank By Date.  Note that the score is calculated based on the closing prices the day before the last trading day of the month.  This score is then used to rank the ETSs and determine the trade for the last day of the month (using a market on close order).

The trade log for this system can be downloaded from Google Docs: Trade Log

In my next post, I will review some metrics for this system and how they have changed over the years.


Follow my blog by email, RSS feed or Twitter (@DTRTrading).  All options are available on the top of the right hand navigation column under the headings "Subscribe To RSS Feed", "Follow By Email", and "Twitter".

Monday, April 4, 2016

Yahoo Data and Momentum Rotation - Analysis of 2015 Data

I've taken a bit of a break from posting options strategy research, but before I dive back in I'm going to revisit some material I posted on Momentum Rotation systems last year.

If you're new to my blog you may have missed my posts related to rotation system results and data.  For the last several years, I have been trading monthly Momentum Rotation strategies across six accounts.  These strategies rank portfolios containing between 10 and 30 ETFs or mutual funds by momentum.  Some of my strategies combine multiple momentum readings to derive a rank, while others go further and add filters.  All of my rotation strategies rank a basket of funds relative to each other...and this is a common approach across all Momentum Rotation systems, not just mine.

I use AmiBroker and Yahoo! end-of-data data (Yahoo Data Info 1, Yahoo Data Info 2) for my rotation strategies.  A few years ago I began to realize that the signals I was receiving (and trading on!) from my rotation strategies were occasionally inconsistent with the backtests of these same strategies.  I didn't spend much time digging into the issue at the time, but it remained in the back of my mind.

In August 2014, I decided to backtest my live rotation strategies across the same period that I had actively traded with these same rotation strategies.  I found that a number of the trades in the backtests did not match the trades I had actually executed and recorded in my spreadsheets.

I initially thought the issue was caused by using dividend adjusted data rather than actual data, but in my last Momentum Rotation post (here) I realized this was not the issue.  Dividend adjusted data does result in stable Momentum Rotation rankings as dividends are issued.  I also analyzed several ETFs to determine if their ROC values were stable across dividend issuance, and they were.

Based on these findings and some advice from Cesar Alvarez, I started taking taking snapshots of my AmiBroker database at the end of each month beginning in March of 2015.  I continued taking database snapshots through January of 2016...11 months in total.  Planning to get to the bottom of the mismatch between the actual signals and the backtest signals, I ran backtests of my live systems across each database snapshot and compared these signals with the signals I actually traded.  Surprisingly, there was no difference ... the backtest signals from all 11 database snapshots matched my live signals during those same periods.

What changed during those 11 months compared to the time prior to March of 2015?  Well, I had made one small change...so I thought!  Prior to March, 2015 I did not perform complete historical data updates very often...and I would typically only update the last several months of historical data when I did perform an update...and this was a big mistake that I did not recognize!

Beginning in March, 2015 I started performing complete database updates on the 25th of each month.  With these updates, I re-downloaded all of my historical data from January 1st, 1900 to the present.  This corrected my signal instability problem.  The lack of complete historical updates had been a big mistake on my part and resulted in my backtest signals not matching the signals I had actually traded.

The big take away ... if you're not already doing this ... perform a complete historical data update prior to generating your live trading signals.  If your data is dividend and split adjusted, you need to update the entire series...pretty obvious now, but something I missed...hopefully others will learn from my mistake!

In my next post, I will review the 2015 results of the Momentum Rotation system that I shared in March 2015 (here).

Lastly, I just started reading Momo Traders (full disclosure, Brady Dahl sent me a copy) and it reminds me of the Market Wizards series.  I'm only on the first interview, so no book review yet, but I am enjoying it so far.


Follow my blog by email, RSS feed or Twitter (@DTRTrading).  All options are available on the top of the right hand navigation column under the headings "Subscribe To RSS Feed", "Follow By Email", and "Twitter"

Sunday, March 29, 2015

Momentum Rotation Strategies and Data - Part 4

In the last three posts (Part 1, Part 2, Part 3), we looked at how dividend adjusted data and non-dividend adjusted data generate different results with Momentum Rotation Strategies.  We also looked at a hybrid approach using the signals generated from the non-dividend adjusted series, combined with the returns from the dividend adjusted series.  As expected all three approaches generated different results.

I started this review of data approaches because I was/am seeing fund ranking instability in my live trading.  For example, one of my Mutual Fund Rotation Systems signaled an entry into Fidelity Leveraged Company Stock (FLVCX) on Wednesday, April 30, 2014.  On the last trading day of the next month, Friday, May 30, 2014, I received a signal to hold my position of Fidelity Select Chemicals Portfolio (FSCHX).  The issue...my position was in FLVCX, not FSCHX.  In this particular example, the dividend issued in April to FSCHX had an impact on this fund's rank in later runs.  FLVCX did not have a dividend issued during this period.

During the last several days, I reviewed all of the code of my Momentum Rotation Strategies and found that dividend adjusted data should result in stable ranking as dividends are issued.  I also analyzed several ETFs to determine if their ROC values were stable across dividend issuance.  Theoretically, ROC values should be stable with the Yahoo/CSI dividend adjusted data, and I did find this to be correct.  My analysis of EEM can be found here.

At this point, the issue I am seeing is most likely being caused by a rare error with the Yahoo/CSI data related to dividends.  My current theory is that this is being caused by a late addition of a dividend to the time series.  For example, say a dividend was issued on April 11, 2014, but not added to the time series.  Then at some point in the future, say May 1, 2014 the error is discovered and the dividend is added to the April 11, 2014 date.  If this situation were to occur, then the ranking on April 30 would change.  This is purely speculation at this point, but it could be the cause of the situation that I am seeing occasionally in my live trading.

Starting this month, I am going to be taking snapshots of my AmiBroker database at the end of each month.  This should help me find the exact cause of this ranking instability that occasionally crops up during the year.  Thanks to Cesar Alvarez for this tip!

I will have another post on this topic after I am confident in the cause of my ranking instability.

If you don't want to miss my new blog posts, follow my blog either by email or by RSS feed.  Both options are free, and are available on the top of the right hand navigation column under the headings "Follow By Email" and "Subscribe To RSS Feed".  I follow blogs by RSS using Feedly, but any RSS reader will work.

Wednesday, March 18, 2015

Momentum Rotation Strategies and Data - Part 3

In this post we will look at the results for a Momentum Rotation strategy that ranks funds based on the sum of two rate-of-change (ROC) values.  We will use the same portfolio of ETFs discussed in Part 1 and Part 2 of this series.

So far this series has started a number of good conversations, trying to find an explanation for my results.  I appreciate all of your comments, and would be delighted if you could find an alternate explanation for my results!  At the end of this post I will include the AFL code I used in AmiBroker to generate the results in Part 2.  The primary AFL indicator that I am using for rotation ranking is ROC.

The strategy discussed in this post works as follows.  On the second to last trading day of the month, the strategy calculates the 60 day ROC and 120 day ROC for each fund in the portfolio based on closing prices on that day.  It adds these two values together, and if the sum is negative it reassigns the sum a value of 0.  It then ranks all 10 funds, selecting the fund with the highest rank.  If all funds have a rank of 0, the system will move to cash.  On the last trading day of the month, it executes the buy and sell orders at the close - "market on close" orders in live trading.

In the diagram below, three equity curves are displayed for a 60 day / 120 day dual momentum Rotation System.  

60 Day / 120 Day Momentum Rotation Strategy Equity Curves
(click to enlarge)
The blue curve labeled "Adjusted" is the equity curve generated from our momentum system using dividend and split adjusted data.  The signals and P&L are derived only from the adjusted data time series.  The red curve labeled "Actual" is the equity curve generated from our momentum system using only split adjusted data, that has not been adjusted for dividends.  It is lower, as expected, since dividends are not included.  The green curve labeled "Hybrid" is the equity curve generated from our momentum system using the "Actual" time series for signal generation and the "Adjusted" time series for the P&L calculation.  This is a two step process...first the system is run across the "Actual" time series data to derive the trade dates and ETFs selected.  The second step uses the dates and ETFs selected in step 1 to to calculate P&L from the "Adjusted" time series data.

What we can see in the next two images are the signals, or ETFs selected, by the strategy from the "Actual" data set and the "Adjusted" data set.  The chart below shows the ETFs selected (and held) by the strategy by date using the "Actual" time series data.

(click to enlarge)

The chart below shows the ETFs selected (and held) by the strategy by date using the "Adjusted" time series data.  Similar to the 60 day momentum strategy, the signals do not match.

(click to enlarge)

As I mentioned to some readers today, I am using Yahoo adjusted data in my "Adjusted" data database, and Yahoo non-adjusted data in my "Actual" data database.  Here are two links from Yahoo that discuss their data source for historical data (it's CSI), and their approach for dividend adjusting data:


Also, here is the AmiBroker AFL code that was used in Part 2 of this series:

SetBacktestMode( backtestRotational );

// 1 ###### BACKTESTER SETTINGS - 1. GENERAL TAB 
SetOption("InitialEquity", 100000);
SetOption("MinShares", 1);
SetOption("MinPosValue", 0);
SetOption("FuturesMode", False);
SetOption("AllowPositionShrinking", False);
SetOption("ActivateStopsImmediately", False);
SetOption("ReverseSignalForcesExit", False);
SetOption("AllowSameBarExit", False);
RoundLotSize = 0;
TickSize = 0;
MarginDeposit = 0;
PointValue = 1;
SetOption("CommissionMode", 2);
SetOption("CommissionAmount", 7.95);
SetOption("InterestRate", 0);
SetOption("AccountMargin", 100);
SetOption("MarginRequirement", 100);

// 2 ###### BACKTESTER SETTINGS - 2. TRADES TAB 
BuyPrice = SellPrice = ShortPrice = CoverPrice = Close;
SetTradeDelays( 1, 1, 1, 1);

// 5 ###### BACKTESTER SETTINGS - 5. PORTFOLIO TAB 
//SetOption("MaxOpenPositions",   1);
// check the box to "Add artificial future bar..."
// Limit trade size as % - use 10 for live trading
// check the box to "Disable trade size limit..."
SetOption("UsePrevBarEquityForPosSizing", False);
SetOption("UseCustomBacktestProc",  False);

// 6 ###### BACKTESTER SETTINGS - 6. WALK FORWARD TAB
//SetOption("WorstRankHeld",    1);


Totalpositions = 1;
SetOption("WorstRankHeld", 1);
SetOption("MaxOpenPositions", Totalpositions );
PositionSize = -100 / Totalpositions ;

LastDayOfMonth = IIf( (Month() == Ref( Month(), 1) AND (Month() != Ref( Month(), 2)) ), 1, 0);
TradeDay = LastDayOfMonth ;

Score = ROC(Close, 60);
PositionScore = IIf(Score < 0, 0, Score ); // Long only
PositionScore = IIf(TradeDay , PositionScore , scoreNoRotate);

//Exploration
Filter = 1;
AddColumn(Score ,"Score",1.1);
AddColumn(PositionScore ,"PositionScore ",1.1);
AddColumn(PositionSize ,"Position Size",1.1);

You can download the AFL code above from my Google Drive: 00_60DayMomentum.afl

If you don't want to miss my new blog posts, follow my blog either by email or by RSS feed.  Both options are free, and are available on the top of the right hand navigation column under the headings "Follow By Email" and "Subscribe To RSS Feed".  I follow blogs by RSS using Feedly, but any RSS reader will work.

Monday, March 16, 2015

Momentum Rotation Strategies and Data - Part 2

In Part 1, I discussed an issue that can occur when using dividend adjusted price data in Momentum Rotation Strategies that select funds based on a relative ranking algorithm.  I outlined three different data approaches that can be used, and presented a simple rotation strategy and portfolio to illustrate this data issue.  For additional background please see Part 1, and my older post: Historical Data and Momentum Rotation Strategies

In this post we will dive right into the backtest results.  In the diagram below, three equity curves are displayed for the simple 60 day dual momentum Rotation System outlined in Part 1.

60 Day Momentum Rotation Strategy Equity Curves
(click to enlarge)
 The blue curve labeled "Adjusted" is the equity curve generated from our momentum system using dividend and split adjusted data.  The signals and P&L are derived only from the adjusted data time series.  The red curve labeled "Actual" is the equity curve generated from our momentum system using only split adjusted data, that has not been adjusted for dividends.  It is lower, as expected, since dividend are not included.  The green curve labeled "Hybrid" is the equity curve generated from our momentum system using the "Actual" time series for signal generation and the "Adjusted" time series for the P&L calculation.  This is a two step process...first the system is run across the "Actual" time series data to derive the trade dates and ETFs selected.  The second step use the dates and ETFs selected in step 1 to to calculate P&L from the "Adjusted" time series data.

For this example, I selected a portfolio of ETFs and a Rotation System that had a small difference between the Hybrid and Adjusted data equity curves.  If Adjusted data did not have an impact on ranking, then the two curves would exactly overlap.

What we can see in the next two images are the signals, or ETFs selected, by the strategy from the "Actual" data set and the "Adjusted" data set.  The chart below shows the ETFs selected (and held) by the strategy by date using the "Actual" time series data.

ETF Holdings By Date From Actual Data Signals
(click to enlarge)
The chart below shows the ETFs selected (and held) by the strategy by date using the "Adjusted" time series data.  It is obvious when comparing the chart above with the cart below that the signals, or ETFs selected do not match...although they are close!

ETF Holdings By Date From Adjusted Data Signals
(click to enlarge)
In my view, this is a pretty clear sign that using dividend adjusted price data will cause your relative ranking systems to generate results, and signals, that will change with time.  I have experienced this first hand with my live rotation systems.  Occasionally I will receive a signal to sell one ETF and buy another ETF...where the ETF I am supposed to sell is not the ETF that I am actually holding from the prior month's signal...when real money is on the line, understanding the cause of this situation is vitally important!

In the next post, we will look at another example...

If you don't want to miss my new blog posts, follow my blog either by email or by RSS feed.  Both options are free, and are available on the top of the right hand navigation column under the headings "Follow By Email" and "Subscribe To RSS Feed".  I follow blogs by RSS using Feedly, but any RSS reader will work.

Sunday, March 15, 2015

Momentum Rotation Strategies and Data - Part 1

I am going to take a short break from reviewing backtest results for different variations of Iron Condors, and revisit Momentum Rotation strategies.  In a past post (Historical Data and Momentum Rotation Strategies), I discussed how data choices impact the repeatability of ranking output typically used in Momentum Rotation strategies.

I'll summarize a bit of what I discussed in that last rotation post...

I have been trading monthly Momentum Rotation strategies across six accounts for several years.  These strategies rank portfolios containing between 10 and 30 ETFs or mutual funds by momentum.  Some of my strategies combine multiple momentum readings to derive a rank, while others go further and add filters.  The key point here is that all my rotation strategies rank a basket of funds relative to each other...and this is a common approach across all rotation systems, not just mine.

Now to the crux...the data used by rotation systems has an impact on individual fund ranking scores.  Most rotation strategies that are published on the internet (commercial systems, blogs, etc) use split and dividend adjusted price data to generate the ranking scores.  The entire adjusted price data series changes with every dividend that is issued, which changes all past prices in the time series.  When a dividend is issued for one of these funds today, all of the past adjusted prices change, which will change the past rank scores for that fund.  When the past rank scores change, a fund that was in position 1, can move to position 2, which then changes the backtest results.  I will show two examples of this issue in this post and subsequent posts.  This situation does not occur when non-adjusted price data is used.

When you implement a Rotation System, or any system for that matter, you can use: 1) split and dividend adjusted price data...I'll refer to this as "adjusted" data in the rest of this post, 2) split adjusted only data...I'll refer to this as "actual" price data in the rest of this post, or 3) a hybrid where "actual" price data is used for ranking/signal generation, and "adjusted" price data is used to determine strategy P&L.

----

We will look at the results for each of the three data approaches above for a simple rotation system.  Our system will only look at the 60 day rate of change for ranking and will pick the ETF with the largest positive change in the portfolio.  If all of the ETFs in the portfolio have a negative rate of change...a price today that is lower than the price 60 days ago, then the system will move to cash.  The system will only rank the ETFs in the portfolio on the last trading day of the month.

The ETFs in the portfolio include:

I have included screenshots from Yahoo Finance for each of these ETFs, that show how the actual price and adjusted price can deviate over time as dividend payments are added into the adjusted price time series.

EEM - on Jan 3, 2007 the close was 115.14, but the adjusted close was 32.99
(click to enlarge)

EFA - on Jan 3, 2007 the close was 73.51, but the adjusted close was 57.75
(click to enlarge)

FXI - on Jan 3, 2007 the close was 116.40, but the adjusted close was 32.91
(click to enlarge)

IEF - on Jan 3, 2007 the close was 82.68, but the adjusted close was 64.90
(click to enlarge)

IYR - on Jan 3, 2007 the close was 83.87, but the adjusted close was 59.47
(click to enlarge)

SHY - on Jan 3, 2007 the close was 80.04, but the adjusted close was 70.24
(click to enlarge)

SPY - on Jan 3, 2007 the close was 141.37, but the adjusted close was 119.69
(click to enlarge)

TIP - on Jan 3, 2007 the close was 99.23, but the adjusted close was 76.67
(click to enlarge)

UUP - on Jan 2, 2008 the close was 23.49, but the adjusted close was 23.33
(click to enlarge)

XLV - on Jan 3, 2007 the close was 33.50, but the adjusted close was 28.88
(click to enlarge)
In Part 2, I will show the results from this Rotation System for the three different data approaches listed above.

...to be continued...