[R-SIG-Finance] Non-financial "seasonality"

Panov, Evgeny evgeny.panov at citi.com
Fri Dec 28 14:54:52 CET 2007


Here is a little function that filters out the base frequency and harmonics.
It should be very performant even for data sets of large sizes.

trim.harmonics <- function(time.series, base.frequency, n.modes = 1)
{
	len <- length(time.series)
	harmonic.space.basis <- matrix(ncol = 2 * n.modes, nrow = len)
	for(mode.n in 1:n.modes)
	{
		harmonic.space.basis[, 2 * mode.n - 1] <- sin(0.5 / pi * base.frequency * mode.n * c(1:len))
		harmonic.space.basis[, 2 * mode.n] <- cos(0.5 / pi * base.frequency * mode.n * c(1:len))
	}
	lsfit(harmonic.space.basis, time.series)$residuals
}

...and here is how you can test that it works:

trim.harmonics.test <- function()
{
	# creating the time series which has a harmonic with frequency 0.1 per period
	test.time.series <- 1:1000 + 4000 * sin(0.1 * 0.5 / pi * (1:1000))

	# filtering out the harmonics of frequencies 0.1, 0.2 and 0.3
	filtered.time.series <- trim.harmonics(test.time.series, base.frequency = 0.1, n.modes = 3)
	
	# plotting the original time series in black
	plot(x = test.time.series, type = "l")

	# plotting the filtered time series in blue
	lines(x = filtered.time.series, type = "l", col = 6)
}

At least this works in Splus.

Regards,
Gene

-----Original Message-----
From: r-sig-finance-bounces at stat.math.ethz.ch
[mailto:r-sig-finance-bounces at stat.math.ethz.ch]On Behalf Of Walt
Keneipp
Sent: Wednesday, December 26, 2007 7:58 PM
To: r-sig-finance at stat.math.ethz.ch
Subject: [R-SIG-Finance] Non-financial "seasonality"


We have a dataset with frequency from 40 to 1200 MHz in .01 MHz
increments, and corresponding amplitude in db.  There are spikes in
amplitude near 60 Hz and its harmonics caused by the AC line.  The
spikes are not necessarily AT 60 Hz, but vary between 59 and 61.  Is
there a good way to filter out these spikes?  If not, would smoothing be
the way to go?

Walt Keneipp
wkeneipp at stormproducts.com

_______________________________________________
R-SIG-Finance at 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.



More information about the R-SIG-Finance mailing list