You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Name of QuantLet : STFloss09Published in : Statistical Tools for Finance and InsuranceDescription : 'Plots the quarterly number of losses for the Danish fire data and the aggregatenumber of losses and the mean value funtion E(N_t) of the calibrated HPP and NHPP. Clearly thelatter model gives a better fit to the data (dfl.dat/ dfl.txt). Requires getQnumber.m from Quantnetwebsite.'Keywords : pareto, model, loss function, empirical, graphical representation, visualizationSee also : 'STFloss01, STFloss02, STFloss03, STFloss04, STFloss05, STFloss06, STFloss07, STFloss08,getQnumber'Author : Joanna Janczura, Awdesch MelzerSubmitted : Fri, December 07 2012 by Dedy Dwi PrastyoDatafile : dfl.dat, dfl.txtExample : 'getQnumber.m produces these plots of the Number of Events and Aggregate number of losses/ Mean value function over time.'
R Code:
# clear variables and close windows
rm(list= ls(all=TRUE))
graphics.off()
#################################### Subroutine getQnumber(x) #####getQnumber=function(x) {
# GETQNUMBER Auxiliary function for STF2loss9 y=getQnumber(x) returns the quarterly number of losses.maxx= max(x)
l= length(x)
y=matrix(0, maxx, 1)
i=1q=1while (i<=l) {
if (x[i] ==q) {
y[q] =y[q] +1i=i+1
} else {
q=q+1
}
}
return(y)
}
############################ main calculation #####m= read.table("dfl.txt")
v=m[which(m[, 5] !=0), 5:6]
n= getQnumber(v[, 2])
# Qnumberst= (1:length(n))/4
plot(t, n, type="l", col="blue3", lwd=2, xlab="Time (years)", ylab="Number of events", xlim= c(0, 23))
# Mean value functionncum= cumsum(n)
dev.new()
plot(t, ncum, type="l", lty=2, col="blue3", lwd=2, xlab="Time (years)", ylab="Aggregate number of losses / Mean value function",
xlim= c(0, 23))
lines(t, (100.2394*t), col="black", lwd=2)
lines(t, 17.9937*t+3.5759*t^2, col="red3", lty=3, lwd=2)
MATLAB Code:
% clear variables and close windowsclearallcloseallclc
m = load('dfl.dat');
v = m(find(m(:,5)~=0),5:6);
n = getQnumber(v(:,2));
% Qnumbers
t = (1:length(n))/4;
plot(t,n, 'LineWidth',2);
xlabel('Time (years)','FontSize',16,'FontWeight','Bold');
ylabel('Number of events','FontSize',16,'FontWeight','Bold');
xlim([0,23]);
set(gca,'LineWidth',1.6,'FontSize',16,'FontWeight','Bold');
boxon% to save the plot in pdf or png please uncomment next 2 lines:%print -painters -dpdf -r600 STFloss09_01.pdf%print -painters -dpng -r600 STFloss09_01.png% Mean value function
ncum = cumsum(n);
figure
plot(t,ncum,'--', 'LineWidth',2);
holdon
plot(t,(100.2394*t),'k', 'LineWidth',2);
plot(t,17.9937*t+3.5759*t.^2,'-.r', 'LineWidth',2)
% ylim([0,700])
xlim([0,23]);
xlabel('Time (years)','FontSize',16,'FontWeight','Bold');
ylabel('Aggregate number of losses / Mean value function','FontSize',16,'FontWeight','Bold');
set(gca,'LineWidth',1.6,'FontSize',16,'FontWeight','Bold');
boxon% to save the plot in pdf or png please uncomment next 2 lines:%print -painters -dpdf -r600 STFloss09_02.pdf%print -painters -dpng -r600 STFloss09_02.png