/
TolBenNGPlots.m
113 lines (92 loc) · 2.89 KB
/
TolBenNGPlots.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
% In this file, we will perform some statistical tests
% to ensure that the data collected is i.i.d. and
% follows a Normal Distribution.
%% Step 1. Collect the data from csv file.
% Collect data from csv file.
Data = csvread('TolBenNGPrices.csv',1,1);
% Separate data by type of commodity.
Benzene = Data(:,1);
Toluene = Data(:,2);
NaturalGas = Data(:,3);
%% Step 2. Construct plot for price data.
% Collect date vectors for plot
startdate = datenum('01-Feb-2011','dd-mm-yyyy');
enddate = datenum('01-Jan-2013','dd-mm-yyyy');
DateVector = linspace(startdate,enddate,24);
% Make plot of the prices of the commodities.
figure(1)
plot(DateVector,Benzene,DateVector,Toluene,'r',DateVector,NaturalGas,'g')
title('Price Plot for Commodities involved in the HDA Process')
legend('Benzene','Toluene','Natural Gas')
ylabel('Prices')
xlabel('Dates')
datetick('x','mmm-yy')
%% Step 3. Calculate log-returns and perform statistical analysis.
% Compute log returns for the prices of all the commodities.
for i = 2 : length(Benzene)
LRBenzene(:,i-1) = log(Benzene(i)/Benzene(i-1));
LRToluene(:,i-1) = log(Toluene(i)/Toluene(i-1));
LRNG(:,i-1) = log(NaturalGas(i)/NaturalGas(i-1));
end
% Make plot of the prices of the commodities.
figure(2)
subplot(3,3,[1 2 3])
plot(DateVector(2:end),LRBenzene)
title('Log Return Plot for Commodities involved in the HDA Process')
legend('Benzene')
ylabel('Log Returns')
xlabel('Dates')
datetick('x','mmm-yy')
% Construct a lag plot for the prices.
subplot(3,3,4)
LagBenzene = lagmatrix(LRBenzene,[0,1]);
scatter(LagBenzene(:,1),LagBenzene(:,2),'fill')
axis 'equal'
axis 'square'
% Construct Histograms for the log returns.
subplot(3,3,[5 6])
histfit(LRBenzene(:),10);
subplot(3,3,[7 8 9])
autocorr(LRBenzene)
% Make plot of the prices of the commodities.
figure(3)
subplot(3,3,[1 2 3])
plot(DateVector(2:end),LRToluene,'r')
title('Log Return Plot for Commodities involved in the HDA Process')
legend('Toluene')
ylabel('Log Returns')
xlabel('Dates')
datetick('x','mmm-yy')
% Construct a lag plot for the prices.
subplot(3,3,4)
LagToluene = lagmatrix(LRToluene,[0,1]);
scatter(LagToluene(:,1),LagToluene(:,2),'fill')
axis 'equal'
axis 'square'
% Construct Histograms for the log returns.
subplot(3,3,[5 6])
histfit(LRToluene(:),10,'normal');
subplot(3,3,[7 8 9])
autocorr(LRToluene)
% Make plot of the prices of the commodities.
figure(4)
subplot(3,3,[1 2 3])
plot(DateVector(2:end),LRNG,'g')
title('Log Return Plot for Commodities involved in the HDA Process')
legend('Natural Gas')
ylabel('Log Returns')
xlabel('Dates')
datetick('x','mmm-yy')
% Construct a lag plot for the prices.
subplot(3,3,4)
LagNG = lagmatrix(LRNG,[0,1]);
scatter(LagNG(:,1),LagNG(:,2),'fill')
axis 'equal'
axis 'square'
% Construct Histograms for the log returns.
subplot(3,3,[5 6])
histfit(LRNG(:),10);
subplot(3,3,[7 8 9])
autocorr(LRNG)
%%
LR = [LRBenzene(:),LRToluene(:),LRNG(:)]