Raghu,

It appears that your function or MACD need a vector (1st try) not a xts obejct (2nd)

library(ttrTests)

 y <- (getYahooData("SPY",start="20060101",end="20081231")[,"Close"])

 yourGOODttr <- function(x,params=c(12,26,1,9,1),burn=0,short=TRUE)
 {
x<-as.vector(x)
     s<-MACD(x,params[1],params[2],params[4],maType="EMA")
     s<-(na.omit(s))
     s<-s[,1]
     pos <-
(ifelse(s>params[5],1,0)+ifelse(s<=(-params[5]),1,0)*ifelse(short,-1,0))
     pos[1:(burn+1)] <- 0
     return(pos)

 }
 rs <- returnStats(y,ttr=yourGOODttr,params=c(12,26,1,9,1),burn=0,short=TRUE,condition=NULL)
 
behave the same way as your 1st try.

Robert 

--------------------------------------------------
From: "Raghu" <r.raghuraman@gmail.com>
Sent: Sunday, July 11, 2010 6:27 AM
To: "R-Finance" <r-sig-finance@stat.math.ethz.ch>
Subject: [R-SIG-Finance] same function behaves dfferently in a differentinstant?

> I ran the following function and returnStats() was giving an output albeit
> with a warning because lenght(s) != length(x). But I ran the same stuff
> again and it showed an error. Could someone pls assist?
> 
> 
> x <-
> as.vector(getYahooData("SPY",start="20060101",end="20081231")[,"Close"])
>>
>> yourGOODttr <- function(x,params=c(12,26,1,9,1),burn=0,short=TRUE)
> + {
> +
> +     s<-MACD(x,params[1],params[2],params[4],maType="EMA")
> +     s<-(na.omit(s))
> +     s<-s[,1]
> +     pos <-
> (ifelse(s>params[5],1,0)+ifelse(s<=(-params[5]),1,0)*ifelse(short,-1,0))
> +     pos[1:(burn+1)] <- 0
> +     return(pos)
> +
> + }
>> rs <-
> returnStats(x,ttr=yourGOODttr,params=c(12,26,1,9,1),burn=0,short=TRUE,condition=NULL)
> Benchmark is: hold
> TTR is: from function
> Summary Statistics: n, mean, stddev, Sharpe(0), skew, kurt, acf(1-5)
> 
> **************************************
> 
> Benchmark return statistics: 755 -0.0003768373 0.01649305 -0.02284825
> 0.1090061 14.58123 -0.1108398 -0.1985695 0.1238147 -0.06197286 -0.05611263
> Conditional return statistics: 755 0.0006207193 0.01128876 0.0549856
> 0.00664948 46.11834 -0.1068183 -0.2159060 0.1549785 -0.003083948 0.1131917
> 
> **************************************
> 
> Long return statistics: 67 0.001879617 0.01024867 0.1834011 0.4184961
> 2.505614
> Short return statistics: 151 -0.002269594 0.02428043 -0.09347421 0.2254311
> 8.427571
> Neutral return statistics: 537 -0.0001261411 0.01424889 -0.0088527 0.1450882
> 14.14102
> 
> **************************************
> 
> Excess return statistics: 755 0.0009975566 0.02483144 0.04017313 -0.05565833
> 31.65565
> Excess return adjusted for trading costs: 0.0009578215
> Warning message:
> In s * condition :
>  longer object length is not a multiple of shorter object length
> 
> ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
> library(ttrTests)
>>
>> x <- (getYahooData("SPY",start="20060101",end="20081231")[,"Close"])
>>
>> yourGOODttr <- function(x,params=c(12,26,1,9,1),burn=0,short=TRUE)
> + {
> +
> +     s<-MACD(x,params[1],params[2],params[4],maType="EMA")
> +     s<-(na.omit(s))
> +     s<-s[,1]
> +     pos <-
> (ifelse(s>params[5],1,0)+ifelse(s<=(-params[5]),1,0)*ifelse(short,-1,0))
> +     pos[1:(burn+1)] <- 0
> +     return(pos)
> +
> + }
>> rs <-
> returnStats(x,ttr=yourGOODttr,params=c(12,26,1,9,1),burn=0,short=TRUE,condition=NULL)
> Error in NextMethod(.Generic) :
>  dims [product 722] do not match the length of object [755]
> In addition: Warning message:
> In `*.default`(s, condition) :
>  longer object length is not a multiple of shorter object length
> 
> 
> 
> -- 
> 'Raghu'
> 
> [[alternative HTML version deleted]]
> 
> _______________________________________________
> R-SIG-Finance@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-finance
> -- Subscriber-posting only. If you want to post, subscribe first.
> -- Also note that this is not the r-help list where general R questions should go.
>
	[[alternative HTML version deleted]]

