Data Seasonal Adjustment using Cubic Splines
3 次查看(过去 30 天)
显示 更早的评论
Hello everybody,
Im trying to calculate the intraday seasonal factor of my data set using a cubic spline. I have 90 days and each day has 24 observations, so in total I have 2160 observations.
My data for one day looks like this:
Hr Vol
00 880
01 950
02 789
03 680
.....
22 990
23 1000
24 890
I used a cubic spline to fit my data and try to get the seasonal factor, but after I do this I have no idea of how to seasonally adjust my dataset. I want to use a multiplicative model, so my adjusted data would have the form of y_adjusted = y / seasonal_factor.Do you have any suggestions of how could I do this? I have read that the seasonal factor should be the sum of the trading volumes from 00-24 hours, but when I divide my y by this total sum of trading volumes, it doesnt make sense because I get trading volumes of 0.6 or so.
clear all
clc
data = load('91days.txt');
buy90 = data ( 1 : 2160 , 1);
x = 1 : 1: 24; % Number of Knots
xx = linspace(1,24);
y = reshape( buy90, length(x), []);
for j = 1 : 1 : 75
a = y( : , j : j + 15);
mean_16d = mean ( a , 2 );
mean_day = mean(mean_16d);
pp_24 = spline(x,mean_16d);
v = ppval(pp_24,xx);
plot(x,mean_16d(x))
hold on
plot(xx,v,'r');
end
I hope you can give me a hint. Thank you and have a nice day,
Lu
0 个评论
回答(1 个)
Thomas
2012-4-11
I'm assuming this is what you are looking for
c=rand(2160,1); % random data 2160 observation
q=reshape(c,24,[]); % reshaping 24 observations for 90 days 24x90 matrix
out=spline(1:90,q,r); % this uses the matlab cubic spline fcn.
% any given hour to check the season variation
plot(1:24,q(:,1),'o',1:24,out(1,:)) % this plots the variation across the 90 days for hour 1 (00)
etc..
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Spline Postprocessing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!