9
Plot of temperature from the beginning of 1995 to the end of 2016: 0 1000 2000 3000 4000 5000 6000 7000 8000 9000 -20 0 20 40 60 80 100 Sim ulation ofTem perature tim e tem perature Forecast of heating degree days and cooling degree days for 2016: month cdd call cdd put hdd call hdd put 1 0 50 1497.9 72 0 2 0 50 1272.2 83 0 3 0 50 968.87 02 0 4 0 50 519.57 9 0 5 0 50 145.39 21 0 6 67.829 04 0 0 48.539 61 7 247.95 28 0 0 50 8 191.99 17 0 0 50

Temperature Derivative in Minneapolis 2016

Embed Size (px)

Citation preview

Page 1: Temperature Derivative in Minneapolis 2016

Plot of temperature from the beginning of 1995 to the end of 2016:

0 1000 2000 3000 4000 5000 6000 7000 8000 9000-20

0

20

40

60

80

100Simulation of Temperature

time

tem

pera

ture

Forecast of heating degree days and cooling degree days for 2016:

month cdd call cdd put hdd call hdd put1 0 50 1497.972 02 0 50 1272.283 03 0 50 968.8702 04 0 50 519.579 05 0 50 145.3921 06 67.82904 0 0 48.539617 247.9528 0 0 508 191.9917 0 0 509 0 20.87957 4.777814 0

10 0 50 386.2779 011 0 50 816.3173 012 0 50 1243.736 0

(Assumed strike price is $50.)

Page 2: Temperature Derivative in Minneapolis 2016

Reference:

1. MATLAB code for trend

%% trendy=xlsread('Temp1.xlsx','A1:A7326');t1={'01.01.1995'};t2={'21.01.2015'};stopt={'31.12.2016'}; date1=datenum(t1,'dd.mm.yyyy');date2=datenum(t2,'dd.mm.yyyy');stopdate=datenum(stopt,'dd.mm.yyyy'); differencedays=date2-date1+1;days=date1:1:stopdate;newdifferencedays=stopdate-date2;% newdays=(date2+1):1:stopdate; outdays=datestr(days,'dd.mm.yyyy'); x=transpose(1:1:differencedays);%plot(x,y)[P,S]=polyfit(x,y,1)P =[0.0001,46.3949];t=transpose(1:1:(differencedays+newdifferencedays));trend=P(1)*x; trende=P(1)*t;%plot(x,trend)

From MATLAB command window:

P =

0.0001 46.3949

S =

R: [2x2 double]

df: 7324

normr: 1.9286e+03

Page 3: Temperature Derivative in Minneapolis 2016

2. MATLAB code for seasonal component

%% seasonaly=y-trend;f=fit(x,y,'fourier3')%plot(f,x,y)a0 = 46.64;a1 = -27.52; b1 = -9.014; a2 = -1.776; b2 = -0.2965; a3 = -0.2357; b3 = -0.7838; w = 0.0172; fm=a0 + a1*cos(x*w) + b1*sin(x*w) + a2*cos(2*x*w) + b2*sin(2*x*w) + a3*cos(3*x*w) + b3*sin(3*x*w);f_est = a0 + a1*cos(t*w) + b1*sin(t*w) + a2*cos(2*t*w) + b2*sin(2*t*w) + a3*cos(3*t*w) + b3*sin(3*t*w);%plot(t,f_est);

From MATLAB command window:

f =

General model Fourier3:

f(x) = a0 + a1*cos(x*w) + b1*sin(x*w) +

a2*cos(2*x*w) + b2*sin(2*x*w) + a3*cos(3*x*w) + b3*sin(3*x*w)

Coefficients (with 95% confidence bounds):

a0 = 46.64 (46.43, 46.85)

a1 = -27.52 (-27.87, -27.18)

b1 = -9.014 (-9.586, -8.442)

a2 = -1.776 (-2.074, -1.478)

b2 = -0.2965 (-0.6024, 0.009346)

a3 = -0.2375 (-0.5384, 0.06342)

b3 = -0.7838 (-1.083, -0.4849)

w = 0.0172 (0.0172, 0.01721)

Page 4: Temperature Derivative in Minneapolis 2016

3. MATLAB code for cyclical component

%% cyclicallogL=@(residual,vari)-sum(residual.^2 ./vari+log(2*pi*vari))/2;y=y-fm;f=fit(x,y,'fourier3')%plot(f,x,y)a0 = 0.178;a1 = -0.5722; b1 = -0.02852; a2 = -0.3635; b2 = -0.3688; a3 = -0.3985; b3 = -2.101; w = 0.0009233; fresim= a0 + a1*cos(x*w) + b1*sin(x*w) + a2*cos(2*x*w) + b2*sin(2*x*w) + a3*cos(3*x*w) + b3*sin(3*x*w);fresi_est = a0 + a1*cos(t*w) + b1*sin(t*w) + a2*cos(2*t*w) + b2*sin(2*t*w) + a3*cos(3*t*w) + b3*sin(3*t*w);%plot(t,fresi_est);y=y-fresim;logt=zeros(differencedays,1); %% fourier and GARCH on residuals, final model logt(1)=0;for i=2:differencedays logt(i)=y(i)-y(i-1);end%%innov=logt(end:-1:1);innov=logt;mu=zeros(size(innov)); % zero conditional means for residualresidual=innov-mu; theta0=[0.01,0.1,0.1]; % initial guessthetaMLE=fminsearch(@(theta)-logL(residual,garch1(residual,theta)),theta0) %% Find MLE of theta% thetaMLE =% % 0.0120 0.0516 0.9484% % est=zeros(1,differencedays);% vari=garch1(residual,thetaMLE);% vari_est=zeros(1,differencedays);% vari_est(1)=thetaMLE(1)+thetaMLE(3)*vari(differencedays)+thetaMLE(2)*residual(differencedays)^2;% for i=1:(differencedays-1)% vari_est(i+1)=vari_est(i)*(thetaMLE(2)+thetaMLE(3))+thetaMLE(1); %% Forecast of variance% end% plot(t,vari_est)mdl=garch('Constant',thetaMLE(1),'GARCH',thetaMLE(3),'ARCH',thetaMLE(2));rng default; [Vn,Yn]=simulate(mdl,differencedays+newdifferencedays,'NumPaths',10000);% figure% subplot(2,1,1)% plot(Vn)% xlim([0,differencedays])% title('Conditional Variances')% subplot(2,1,2)% plot(Yn)

Page 5: Temperature Derivative in Minneapolis 2016

% xlim([0,differencedays])% title('Innovations')innovation=mean(Yn,2);

From MATLAB command window:

f =

General model Fourier3:

f(x) = a0 + a1*cos(x*w) + b1*sin(x*w) +

a2*cos(2*x*w) + b2*sin(2*x*w) + a3*cos(3*x*w) + b3*sin(3*x*w)

Coefficients (with 95% confidence bounds):

a0 = 0.178 (-0.03616, 0.3922)

a1 = -0.5722 (-0.8718, -0.2727)

b1 = -0.02852 (-0.3318, 0.2748)

a2 = -0.3635 (-0.6764, -0.05065)

b2 = -0.3688 (-0.676, -0.06157)

a3 = -0.3985 (-0.9929, 0.1959)

b3 = -2.101 (-2.431, -1.771)

w = 0.0009233 (0.0008996, 0.000947)

thetaMLE =

0.0120 0.0516 0.9484

4. MATLAB code for Adding up three components and generate forecasts

Page 6: Temperature Derivative in Minneapolis 2016

totalT=fresi_est+trende+f_est+innovation;plot(t,totalT)title('Simulation of Temperature')xlabel('time')ylabel('temperature') estimation=totalT(7671:end);cdd=0;hdd=0;for i=1:size(estimation)if estimation(i)>65 cdd=cdd+1;else if estimation(i)<65 hdd=hdd+1; endendend hdd=zeros(12,1);cdd=zeros(12,1);hddcall=zeros(12,1);cddcall=zeros(12,1);hddput=zeros(12,1);cddput=zeros(12,1); K=50; hdd(1)=sum(max(65-totalT(7671:7701),0)); cdd(1)=sum(max(totalT(7671:7701)-65,0)); hdd(2)=sum(max(65-totalT(7702:7730),0)); cdd(2)=sum(max(totalT(7702:7730)-65,0)); hdd(3)=sum(max(65-totalT(7731:7761),0)); cdd(3)=sum(max(totalT(7731:7761)-65,0)); hdd(4)=sum(max(65-totalT(7762:7791),0)); cdd(4)=sum(max(totalT(7762:7791)-65,0)); hdd(5)=sum(max(65-totalT(7792:7822),0)); cdd(5)=sum(max(totalT(7792:7822)-65,0)); hdd(6)=sum(max(65-totalT(7823:7852),0)); cdd(6)=sum(max(totalT(7823:7852)-65,0)); hdd(7)=sum(max(65-totalT(7853:7883),0)); cdd(7)=sum(max(totalT(7853:7883)-65,0)); hdd(8)=sum(max(65-totalT(7884:7914),0)); cdd(8)=sum(max(totalT(7884:7914)-65,0)); hdd(9)=sum(max(65-totalT(7915:7944),0)); cdd(9)=sum(max(totalT(7915:7944)-65,0)); hdd(10)=sum(max(65-totalT(7945:7975),0)); cdd(10)=sum(max(totalT(7945:7975)-65,0)); hdd(11)=sum(max(65-totalT(7976:8005),0)); cdd(11)=sum(max(totalT(7976:8005)-65,0)); hdd(12)=sum(max(65-totalT(8006:8036),0)); cdd(12)=sum(max(totalT(8006:8036)-65,0)); for i=1:12 cddcall(i)=max(cdd(i)-K,0); cddput(i)=max(K-cdd(i),0); hddcall(i)=max(hdd(i)-K,0); hddput(i)=max(K-hdd(i),0);

Page 7: Temperature Derivative in Minneapolis 2016

end disp('Please think about a date of 2016 that you would like to know the daily average temperature forecast .')dates=input('Please enter it in ddmmyyyy format and enter only 8 numbers: ');s=num2str(dates);if numel(s)==7dd=s(1);mm=s(2:3);yy=s(4:7);else if numel(s)==8dd=s(1:2);mm=s(3:4);yy=s(5:8); endend s={dd,mm,yy};s=strjoin(s,'.');s=datenum(s,'dd.mm.yyyy');I=find(days==s);T=totalT(I);disp(['The daily average temperature forecast for the date you entered is ',num2str(T),'.']); choice1=input('Please choose a kind of weather derivative. Type 1 for hdd, type 2 for cdd: ');choice2=input('Please enter 3 for call or enter 4 for put:' );choice3=input('Please input a month of 2016: '); if choice1==1 if choice2==3 value=hddcall(choice3); else if choice2==4 value=hddput(choice3); end end else if choice1==2 if choice2==3 value=cddcall(choice3); else if choice2==4 value=cddput(choice3); end end endend disp(['The volume is ',num2str(value),'.']);

Page 8: Temperature Derivative in Minneapolis 2016

From MATLAB command window:

Please think about a date of 2016 that you would like to know the daily average temperature forecast .

Please enter it in ddmmyyyy format and enter only 8 numbers: 11092016

The daily average temperature forecast for the date you entered is 65.8187.

Please choose a kind of weather derivative. Type 1 for hdd, type 2 for cdd: 2

Please enter 3 for call or enter 4 for put:4

Please input a month of 2016: 9

The volume is 20.8796.