Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenz-c committed Jun 25, 2013
0 parents commit 4536188
Show file tree
Hide file tree
Showing 263 changed files with 26,079 additions and 0 deletions.
13 changes: 13 additions & 0 deletions ARIMA111.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
function pred = ARIMA111(y)
predictions=1;
p=1;
q=1;
yy = y(1);
y = diff(y);
Spec = garchset('R',p,'M',q,'C',NaN,'VarianceModel','Constant');
[EstSpec,EstSE] = garchfit(Spec,y);
[sigmaForecast,meanForecast] = garchpred(EstSpec,y,predictions);
pred = cumsum([yy; y; meanForecast])
keyboard
pred = pred(end-predictions+1:end);
end
51 changes: 51 additions & 0 deletions DataImpute.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
function [Imputed_data]=DataImpute(Data,method)

% mathod: 1 : monthly mean
% 2 : interpolation

% Data format: first column : year
% Second column : month
% The value should be started from third column (there is no limitation in number of columns)

[row col]=size(Data);
Imputed_data=Data;

%% Imputing the mean monthly values to NaN values
if method==1
f1=find(Data(:,2)==1);f2=find(Data(:,2)==2);
f3=find(Data(:,2)==3);f4=find(Data(:,2)==4);
f5=find(Data(:,2)==5);f6=find(Data(:,2)==6);
f7=find(Data(:,2)==7);f8=find(Data(:,2)==8);
f9=find(Data(:,2)==9);f10=find(Data(:,2)==10);
f11=find(Data(:,2)==11);f12=find(Data(:,2)==12);
Jan1=zeros(1,col-2); Feb1=zeros(1,col-2); Mar1=zeros(1,col-2);
Apr1=zeros(1,col-2); May1=zeros(1,col-2); Jun1=zeros(1,col-2);
Jul1=zeros(1,col-2); Aug1=zeros(1,col-2); Sep1=zeros(1,col-2);
Oct1=zeros(1,col-2); Nov1=zeros(1,col-2); Dec1=zeros(1,col-2);
M_Data=zeros(12,col-2);

for i=3:col
Jan1(1,i-2)=mean(Data(f1(find(isnan(Data(f1,i))==0)),i));Feb1(1,i-2)=mean(Data(f2(find(isnan(Data(f2,i))==0)),i));
Mar1(1,i-2)=mean(Data(f3(find(isnan(Data(f2,i))==0)),i));Apr1(1,i-2)=mean(Data(f4(find(isnan(Data(f4,i))==0)),i));
May1(1,i-2)=mean(Data(f5(find(isnan(Data(f5,i))==0)),i));Jun1(1,i-2)=mean(Data(f6(find(isnan(Data(f6,i))==0)),i));
Jul1(1,i-2)=mean(Data(f7(find(isnan(Data(f7,i))==0)),i));Aug1(1,i-2)=mean(Data(f8(find(isnan(Data(f8,i))==0)),i));
Sep1(1,i-2)=mean(Data(f9(find(isnan(Data(f9,i))==0)),i));Oct1(1,i-2)=mean(Data(f10(find(isnan(Data(f10,i))==0)),i));
Nov1(1,i-2)=mean(Data(f11(find(isnan(Data(f11,i))==0)),i));Dec1(1,i-2)=mean(Data(f12(find(isnan(Data(f12,i))==0)),i));
end

M_Data=[Jan1;Feb1;Mar1;Apr1;May1;Jun1;Jul1;Aug1;Sep1;Oct1;Nov1;Dec1];


[m,n]=find(isnan(Data)==1);
for i=1:length(m)
Imputed_data(m(i),n(i))=M_Data(Data(m(i),2),n(i)-2);
end
end

%% Interpolation
if method==2
[m n]=find(isnan(Data)==1);
for i=1:length(m)
Imputed_data(m(i),n(i))=(Data(m(i)-1,n(i))+Data(m(i)+1,n(i)))/2;
end
end
74 changes: 74 additions & 0 deletions EOF.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
function [L, EOFs, EC, error, norms] = EOF( U, n, norm, varargin )
% EOF - computes EOF of a matrix.
%
% Usage: [L, EOFs, EC, error, norms] = EOF( M, num, norm, ... )
%
% M is the matrix on which to perform the EOF. num is the number of EOFs to
% return. If num='all', then all EOFs are returned. This is the default.
%
% If norm is true, then all time series are normalized by their standard
% deviation before EOFs are computed. Default is false. In this case,
% the fifth output argument will be the standard deviations of each column.
%
% ... are extra arguments to be given to the svds function. These will
% be ignored in the case that all EOFs are to be returned, in which case
% the svd function is used instead. Use these with care.
%
% Data is not detrended before handling. Use the detrend function to fix
% that.
%
% L are the eigenvalues of the covariance matrix ( ie. they are normalized
% by 1/(m-1), where m is the number of rows ). EC are the expansion
% coefficients (PCs in other terminology) and error is the reconstruction
% error (L2-norm).
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% $Id: EOF.m,v 1.3 2003/06/01 22:20:23 dmk Exp $
%
% Copyright (C) 2001 David M. Kaplan
% Licence: GPL (Gnu Public License)
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

if nargin < 2
n = 'all';
end

if nargin < 3
norm = 0==1;
end

s = size(U);
ss = min(s);

% Normalize by standard deviation if desired.
if norm
norms = std(U);
else
norms = ones([1,s(2)]);
end
U = U * diag(1./norms);

% Do SVD
if (ischar(n) & n == 'all') | n >= ss
% Use svd in case we want all EOFs - quicker.
[ C, lambda, EOFs ] = svd( full(U) );
else
% Otherwise use svds.
[ C, lambda, EOFs, flag ] = svds( U, n, varargin{:} );

if flag % Case where things did not converge - probably an error.
warning( 'HFRC_utility - Eigenvalues did not seem to converge!!!' );
end

end

% Compute EC's and L
EC = C * lambda; % Expansion coefficients.
L = diag( lambda ) .^ 2 / (s(1)-1); % eigenvalues.

% Compute error.
diff=(U-EC*EOFs');
error=sqrt( sum( diff .* conj(diff) ) );

Loading

0 comments on commit 4536188

Please sign in to comment.