R - please share your experiences - page 6

 
RandomWorker:

I have entered EURUSD in R. Calculated the model and calculated the coefficient. How do I draw the chart and align it with the kotir?


?plot ?lines ?points

By the way, you just estimated the model. The prediction is done by the predict function.

n <- 100
n.ahead <- 15
ts <- sin(0.05 * pi * (1 : n)) + rnorm(n = n, mean = 0, sd = 0.1)
ts.model <- ar(ts, method = 'burg')
ts.pred <- predict(ts.model, n.ahead = n.ahead)
plot(
  1 : (n + n.ahead),
  c(ts, rep(NA, n.ahead)),
  t = 'l'
  )
lines(
  (n + 1) : (n + n.ahead),
  as.numeric(ts.pred$pred),
  col = 'gray'
  )
lines(
  (n + 1) : (n + n.ahead),
  as.numeric(ts.pred$pred) + as.numeric(ts.pred$se),
  col = 'gray',
  lty = 'dashed'
  )
lines(
  (n + 1) : (n + n.ahead),
  as.numeric(ts.pred$pred) - as.numeric(ts.pred$se),
  col = 'gray',
  lty = 'dashed'
  )
 
anonymous:


?plot ?lines ?points

By the way, you have only estimated the model. The prediction is done by the predict function.

Thank you. It's difficult for me, though. I'll give it a try.

What you wrote will draw on the history?

 
anonymous:


?plot ?lines ?points

By the way, you have only estimated the model. The prediction is done by the predict function.

I've figured it out a little bit.

I am not interested in prediction.

I have a model that I consider as an indicator something like MA. How do I draw it on the history where the model is calculated?

 
RandomWorker:

How do you draw it on the story on which the model was calculated?


?plot ?lines

library(TTR)

x <- cumsum(rnorm(100))
x.ma <- EMA(x, 10)

plot(x, t = 'l')
lines(x.ma, col = 'red')
 
anonymous:


?plot ?lines

> x<-ar(eur[1:256],method="mle")
> x

call:
ar(x = eur[1:256],method="mle")

Coefficients:
1 2 3
0.9420 0.1955 -0.1644

Order selected 3 sigma^2 estimated as 2.73e-06
> plot(x, t = 'l')
Error in xy.coords(x, y, xlabel, ylabel, log) :

'x' is a list, but does not have components 'x' and 'y'

Sorry, but I must be outstandingly stupid.

 
RandomWorker:
> plot(x, t = 'l')


Try this: plot(eur[1:256], t='l')

 
anonymous:


Try it this way: plot(eur[1:256], t='l')

No questions asked. I drew it. But it's a vector.

x<-ar(eur[1:256],method="mle")

Here x is not a vector. It has a formula inside it which can be used to do calculations like in the prediction, only on history

 
RandomWorker:

No questions asked. I drew it. But it's a vector.

x<-ar(eur[1:256],method="mle")

Here x is not a vector. It has a formula inside it which can be used to do calculations like in prefix, only on history


The command ?ar tells us that x is a list, not a formula. So does class(x).

The str(x) command shows the contents of the object.

The fitted(x) gives NULL, but x has a resid component (residuals for the original data) - model values can still be computed: (eur[1:256]-x$resid).

Plot(eur[1:256], t='l')

Add a line of model values: lines(eur[1:256]-x$resid, col='red')

 
anonymous:


The command ?ar tells us that x is a list, not a formula. So does class(x).

The command str(x) shows the contents of the object.

fitted(x) gives NULL, but x has a resid component (residuals for raw data) - model values can still be computed: (eur[1:256]-x$resid).

Plot(eur[1:256], t='l')

Add a line of model values: lines(eur[1:256]-x$resid, col='red')

Got it! thanks.

But somehow it's surprising that we, having a formula, indirectly calculated its value. The predicate is there, the result of the fit is not.

 

Some kind of weird fit.

> x<-ar.ols(eur[1:256], order.max = 20, demean = TRUE)

> x


call:

ar.ols(x = eur[1:256], order.max = 20, demean = TRUE)


Coefficients:

1 2 3

0.9425 0. 1967 -0.1647

Specified order.max = 20, but only three coefficients. I understand it this way:

eur = 0.9425 + 0.1967*eur(-1) + (-0.1647)*eur(-2)

Is there supposed to be 20 members?

Apart from that I changed different parameters ar always three coefficients and they are very slightly different.

Please comment on this.