-
Notifications
You must be signed in to change notification settings - Fork 0
/
arima_MATLAB.m
42 lines (25 loc) · 2.7 KB
/
arima_MATLAB.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
clear all, clc
%DEFINE DATASET
% dataset_y = [1,2,3,4,3,2,1,2,3,4,3,2,1]';
% dataset_y = [-0.00102531950789011 0.0130796054941718 0.0271831194962334 0.0412838134982946 0.0553802765003553 0.0694710985024151 0.0835548715044738 0.0976301865065314 0.111695640508587 0.125749810510642 0.139791310512695 0.153818730514745 0.167830660516793 0.181825710518839 0.195802480520882 0.209759560522922 0.223695560524960 0.237609090526994 0.251498760529024 0.265363170531051 0.279200950533073 0.293010710535092 0.306791060537107 0.320540630539116 0.334258040541122 0.347941920543122 0.361590910545117 0.375203640547107 0.388778750549092 0.402314870551070 0.415810660553043 0.429264770555010 0.442675850556970 0.456042560558924 0.469363560560871 0.482637530562812 0.495863120564745 0.509039040566671 0.522163940568590 0.535236530570501 0.548255490572404 0.561219520574299 0.574127330576186 0.586977620578064 0.599769110579934 0.612500530581795 0.625170590583647 0.637778030585490 0.650321600587324 0.662800030589148 0.675212080590962 0.687556500592767 0.699832070594561 0.712037550596346 0.724171730598119 0.736233380599883 0.748221310601635 0.760134320603376 0.771971220605107 0.783730810606826 0.795411930608533 0.807013400610229 0.818534070611913 0.829972790613585 0.841328410615245 0.852599790616893 0.863785810618528 0.874885350620151 0.885897310621760 0.896820560623357 0.907654040624941 0.918396650626511 0.929047310628068 0.939604970629611 0.950068570631141 0.960437060632657 0.970709410634158 0.980884580635646 0.990961560637119 1.00093938063858 1.01081688064002 1.02059338064145 1.03026758064286 1.03983868064426 1.04930568064565 1.05866768064702 1.06792378064837 1.07707288064971 1.08611418065103 1.09504678065233 1.10386978065362 1.11258238065490 1.12118348065615 1.12967248065740 1.13804828065862 1.14631028065983 1.15445748066102 1.16248918066219 1.17040448066335 1.17820268066449]';
% test_forecast
% 3AC0021C
% dataset_y = [11 14 28 37 43 52 62 71 76 85 93 103 105 110 117 115 114 118 121 119 118 117 114 118 118 118 118 121 125 125 127 127 129 130 126 129 127 129 131 134 133 135 136 130 129 126 124 118 115 103 92 110 107 110 123 123 135 130]';
% 3AC0324A
dataset_y = [9;16;29;34;35;37;41;46;49;47;48;48;46;43;42;44;43;42;44;43;45;46;46;43;42;42;42;42;41;41;42;42;42;42;46;47;51;54;54;55;56;54;54;47;50;50;36;38;34;34;40;59;64;44;37];
%FIT MODEL
num_predictions = 20;
modelo = arima(7,0,1);
[estModel,EstParamCov,logL,info] = estimate(modelo, dataset_y);
%PREDICT NEW VALUES
[Y, YMSE, V] = forecast(estModel, num_predictions, 'Y0', dataset_y);
%Figure stuff
figure()
hold on
plot(dataset_y,'b-o')
a = length(dataset_y)+1 : length(dataset_y)+length(Y);
plot( a,Y, 'r-o')
plot(a,Y + 1.96*sqrt(YMSE),'g-')
plot(a,Y - 1.96*sqrt(YMSE),'g-')
grid
hold off