library("finance")
data=read("XFGJan1997.dat")
names=readm("XFGkeyJan1997.dat")
date=names.text[,1]
type=names.text[,2]
l=list(date,type,data)
ind=(l.date=="02.01.1997")&&(l.data[,2]==0.25)&&(l.type=="C")
smdata=paf(l.data,ind)
vola=smdata[,1]
tau=smdata[,2]
m=smdata[,3]
r=smdata[,4]./100
s=smdata[,5]
F=s.*exp(r.*tau)
K=m.*F
data=m~vola
div=0
;create a finer grid to match local polynomial SPD
bw=0.001
m2=grid(min(m),bw,(max(m)-min(m))/bw+1)
;original strike grid only has 9 points
;the grid must be reconstructed to allow for the interpolated points
;multiply by the scalar mean(F) since for one day worth of options F remains constant
k=m2.*mean(F)
bsspd=spdbs(k,mean(s),mean(r),div,mean(vola),mean(tau))
;rescaling SPD so it can be expressed in terms of moneyness
r2=m2~(bsspd.fbs.*mean(F))
;plotting Black-Scholes SPD
res2 = setmask(r2, "line","blue")
d=createdisplay(1,1)
show(d,1,1,res2)
title="Black-Scholes SPD: 02-01-1997 tau=0.25"
xlabel="moneyness"
ylabel="density"
setgopt(d,1,1,"title",title,"xlabel",xlabel,"ylabel",ylabel)