mercredi 27 janvier 2016

How do you build a list using for loops and if statements in R?

I'm trying to build a list of returns using a particular trading strategy based on an ARMA model

I have the following code:

model1<-arma(fedfunds$FFO, order=c(2,1),lag=NULL,coef=NULL,include.intercept=TRUE,series=NULL)
model_predict1<-fitted(model1)
model_returns=NULL
for (i in 3:length(model_predict1)){
  if (model_predict1[i]>fedfunds$Future[i]) {
    append(model_returns, fedfunds$FF0[i]-fedfunds$Future[i])
  }else{ 
     append(model_returns, fedfunds$Future[i]-fedfunds$FFO[i])
  }
}

The list isn't being created, any ideas on how to fix this?

Aucun commentaire:

Enregistrer un commentaire