[R-SIG-Finance] smoothing quarterly data and extract data on each day

Gabor Grothendieck ggrothendieck at gmail.com
Fri Nov 2 15:33:59 CET 2012


On Fri, Nov 2, 2012 at 8:59 AM, 袁振飞 <zfyuan at mail.ustc.edu.cn> wrote:
> Hi, everybody
>
> I have a quarterly zoo object named "dat1" as below. xyplot(dat1) and xyplot(dat1,type="smooth") may
> obtain both original and smoothed plot, and these two plots are just what I need, however I also
> need those smoothed values on each day, and I have no idea how to extract from the smoothed curve.
> I think there must be some convinent way to deal with this kind of problem. Anyone knows about it?
>
> Thanks a lot!
>
>> dat1
> X1       X2       X3       X4        X5
> 2008 Q1 3482.858 1250.236 3548.769 4931.883  497.3590
> 2008 Q2 3531.582 1355.288 3645.622 5054.060  524.8273
> 2008 Q3 3783.050 1380.224 3719.840 4827.296  626.0529
> 2008 Q4 4372.995 1565.386 3827.486 5014.124  769.9170
> 2009 Q1 4485.311 1778.264 4486.163 5759.063  891.0500
> 2009 Q2 4506.971 1920.969 4704.324 6026.117  934.0728
> 2009 Q3 4791.432 1904.100 4837.732 6101.084  884.6493
> 2009 Q4 5393.146 1917.826 4971.702 6178.358  888.6124
> 2010 Q1 5377.333 2034.175 5222.298 6620.797  918.8237
> 2010 Q2 5651.565 2117.686 5273.992 6789.510  964.9723
> 2010 Q3 5905.428 2138.144 5382.343 6959.202 1107.4141
> 2010 Q4 6420.900 2248.762 5485.862 7003.115 1228.2340
> 2011 Q1 6595.900 2328.679 5745.658 7567.216 1284.2346
> 2011 Q2 6679.854 2474.070 5973.663 7920.905 1430.5884
> 2011 Q3 6523.676 2473.112 6016.118 8057.043 1479.7814
> 2011 Q4 7195.303 2632.994 6337.770 8259.334 1582.4205
> 2012 Q1 7137.809 2824.209 6950.471 8969.470 1647.5123
> 2012 Q2 7084.198 2989.912 6997.699 9314.090 1798.0352
>

Try this:

library(zoo)
library(lattice)
set.seed(123)
z <- zooreg(matrix(rnorm(50), 10), as.yearqtr(2008), freq = 4)

tt <- time(z)
zoo(sapply(z, function(z) loess.smooth(tt, z, eval = length(tt))$y), tt)

-- 
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com



More information about the R-SIG-Finance mailing list