Mean Reversion Trading Process in RapidMiner

Lately I’ve been think about becoming more active in trading again. I was reviewing some strategies and decided to recreate a mean reversion trading process in RapidMiner. I found a mean reversion trading strategy that uses Python here and just recreated it in RapidMiner.

The Process

The process is quite simple. You do the following:

1. Load in stock quote data via CSV;
2. Calculate daily returns;
3. Calculate a 20 day moving average;
4. Calculate a rolling 90 day standard deviation;
5. Generate Trading Criteria per the article
6. Wrap it all together and look at the Buy vs Hold and Buy Signals
 
Mind you, this doesn’t include commission costs and slippage. I suspect that once I add that in, the Buy and Hold strategy will be the best.

PS: to test this, just go to Yahoo Finance and download historical quote data for a stock and then repath it in the Read CSV operator. Use at least a 2 year time period.

Next Steps

I still have several ‘kink’s to work out but I can definitely see the opportunity for optimization here, such as:

  1. Why use a rolling 90 day window? Use parameter optimization to vary that value from 50 to 100.
  2. Why use a 20 day moving average? You could vary between a 10 or 30 day MA?
  3. Write a python script to download EOD stock data and then have RapidMiner loop through it.
  4. Write an commission and slippage subprocess to see if this method IS really profitable or not.
  5. Offload the processes to a RapidMiner Server and have it spit out trading recommendations on a daily basis

Stock Trend Following Model in RapidMiner

Recently I discovered in my old archives a stock trend following model I started in RapidMiner. I never finished it back then but now I cleaned it up. I’m releasing it to the world as beta (use at your own risk) and will probably have some bugs” in it. The trend following model is based on Blackstar Funds, LLC paper Does Trend Following Work on Stocks?

The process is not production ready and there are some clean up things I need to do. I need to write a function that will cleanly output the ATR stops so I can chart them like in the paper.

Of course, the ultimate goal is to loop over a daily list of 52 week new highs and spit out recommendations, but that’s for another post and another process altogether.

Here’s a snapshot of the first part of the process.

stock-trend-following-process

Get the Stock Trend Following Model in RapidMiner

I have lots of RapidMiner and Finance/Trading related processes and posts in my Tutorial section, make sure to check those out too!

To get this Stock Trend Following Model, just download the zipped file here. You’ll need to install the Finance/Economics and Series extensions for the RapidMiner marketplace first to get this to work.

I’m So Bad At Picking Stocks

I spelled it out in this post. I do very little trading these days and mostly focus on diversifying in mutual funds. I do own a few stocks (see below) but I really suck at picking them, especially at the right time. So far 50% are under water, and 50% are doing just fine. I’m so bad at picking stocks.

Note: Blue arrow is where I went long. Red line is my entry price.

I think it’s time to go to the local coin show again.