Skip to content

GARCH - Models

11 messages · Immanuel, Sarbo, Konrad Hoppe +1 more

#
Hey all,

I tested a simple trading system from:
http://blog.fosstrading.com/2009/04/testing-rsi2-with-r.html

(i)

    What I'm missing is some visual feedback on the chart plot about the
    entry / exit
    signals and open positions.

    I would like to have an arrow over or below the bar where the signal
    occurred to
    indicate long or short signals and a doted line to indicate an open
    position?
    Whats the best way to accomplish this?

(ii)

    I like to code some simple Dow trend detection with visual feedback.
    How can I choose the chart background or bar at every bar according
    to the trend direction ?
    Is there an indicator for x-bar high or x-bar low? ( I need this to
    identify important high or lows)


I'm quite curious if and how all this can be realized in quantmod,
therefore I'm
happy about any hint in the right direction.

Regards mane
#
I can see your problem right away- there's no noise factor. Everything
that comes out of your model is purely deterministic- no stochastic
component to it whatsoever.

See this bit of code?

for(t in 2:length(v2)){
In order for this stochastic process to work, there has to be a driving
white noise factor. It's important to note the the return series itself
is considered to be essentially just a random process, the precise
nature of which depends on the conditional distribution that you
specify.

Try the version in the code I've attached instead. I don't use the
quantmod package, simply because I've never needed it- there are other
ways to get the job done.

Oh, and I made a slight error in the references I provided- you'll need
Hull Ch.19.

I hope that helps.

Regards,

Sarbo
On Sat, 2010-04-17 at 17:29 +0200, Konrad Hoppe wrote:
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://stat.ethz.ch/pipermail/r-sig-finance/attachments/20100417/4b40d85b/attachment.html>
-------------- next part --------------
#Load packages:
library(fImport)
library(fGarch)

#Get data:
from <- as.Date('01/01/91', format = '%m/%d/%y')
to <- as.Date(Sys.Date() - 1, format = '%m/%d/%y')
DAX <- yahooSeries('^GDAXI', from = from, to = to)
prices <- rev(DAX[,6])
i <- 2:length(prices)
rets <- log(prices[i] / prices[i-1])

#Plot prices & returns:
par(mfrow = c(1,2))
ts.plot(prices)
ts.plot(rets)

#Fit a GARCH(1,1) model to the returns:
fit <- garchFit(data = rets)
summary(fit)

#If you want a selection of plots for this fit, use the function below:
plot(fit)

#Simulate a GARCH(1,1) model using the fitted parameters:
fitcoef <- fit at fit$par
model <- list(mu = fitcoef[1], omega = fitcoef[2], alpha = fitcoef[3], beta = fitcoef[4])
spec <- garchSpec(model)
sim <- garchSim(spec, n = 500)

#Plot the simulated GARCH(1,1) values:
ts.plot(sim)
10 days later
#
Immanuel,

Look at the code in the chart.Posn() function in the blotter package
on r-forge.  While it may not do _exactly_ what you want, it should
give you a good start.

Best,
--
Joshua Ulrich
FOSS Trading: www.fosstrading.com
On Fri, Apr 16, 2010 at 5:21 PM, Immanuel <mane.desk at googlemail.com> wrote: