The Average Investor's Blog

A software developer view on the markets

ARMA Models for Trading, Part I

Posted by The Average Investor on Apr 14, 2011

All posts in this series were combined into a single, extended tutorial and posted on my new blog.

Lately I have been testing trading models based on methods from various fields: statistics, machine learning, wavelet analysis and others. And I have been doing all that in R! In this series, I will try to share some of these efforts starting with the well-known from statistics Autoregressive Moving Average Model (ARMA). There is a lot of written about these models, however, I strongly recommend Introductory Time Series with R, which I find is a perfect combination between light theoretical background and practical implementations in R.

In R, I am using the fArma package, which is a nice wrapper with extended functionality around the arima function from the stats package (used in the book). Here is a simple session of fitting an ARMA model to the S&P 500 daily returns:

library(quantmod)
library(fArma)

# Get S&P 500
getSymbols( "^GSPC", from="2000-01-01" )

# Compute the daily returns
GSPC.rets = diff(log(Cl(GSPC)))

# Use only the last two years of returns
GSPC.tail = as.ts( tail( GSPC.rets, 500 ) )

# Fit the model
GSPC.arma = armaFit( formula=~arma(2,2), data=GSPC.tail )

The first obstacle is to select the model parameters. In the case of ARMA, there are two parameters. In other words, there is an infinite number of choices: (0,1), (1,0), (1,1), (2,1), etc. How do we know what parameters to use?

A naive approach would be to back-test strategies with all different combinations over a period of time and pick the best. This is something I have dubbed “hyper system” (ie a system of systems) and can be applied to any combination of indicators and comparative function.

Fortunately there are more robust statistical methods to do that. More on that in the next post

About these ads

6 Responses to “ARMA Models for Trading, Part I”

  1. [...] left the last post at the point of determining the best ARMA model. Before continuing the discussion, however, I would [...]

  2. The fArma package is no longer on CRAN. Where can I get it?

  3. [...] system described in the earlier series for ARMA trading was in fact an “extreme” version of the more common, orthodox approach prevailing in [...]

  4. EDo said

    Where is the part 2 ??

  5. Zachary Mayer said

    On the right, look t the “top posts” sidebar:

    http://theaverageinvestor.wordpress.com/2011/04/21/arma-models-for-trading-part-ii/

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
Follow

Get every new post delivered to your Inbox.

%d bloggers like this: