I need help in customizing the smoothing to my time series data. The code below smooths the data using sm.regression
and approx
functions, but the degree of smoothing is not user controlled, i.e. By changing function parameters I want the ability to control whether the smoothed curve follows the underlying data more closely or less closely.
find.extrema <- function(x)
{
if(is.xts(x)) {
y = as.vector( Cl(x) )
} else {
y = x
}
n = len(y)
t = 1:n
h = h.select(t, y, method = 'cv')
temp = sm.regression(t, y, h=h, display = 'none')
mhat = approx(temp$eval.points, temp$estimate, t, method='linear')$y
#mhat = y #to exactly match underlying data
return (mhat)
}
Any help would be appreciated.
Thanks.