Keywords - Function groups - @ A B C D E F G H I J K L M N O P Q R S T U V W X Y Z

Library: finance
See also: spdopt

Quantlet: spdest2
Description: estimates the state price density from the prices of European call and put options.

Reference(s):

Usage: out = spdest2(ddd,ppp,mat,rfree{,opt})
Input:
ddd 2 x n matrix, the European call option prices
ppp 2 x n matrix, the European put option prices
mat scalar, maturity (days/360)
rfree scalar, risk free interest rate
opt list, contains optional parameters (see spdopt.xpl)
Output:
out list, contains the following elements:
out.lrcal, out.lrput estimates of call and put prices with order restrictions
out.nrcal, out.nrput estimates of call and put prices without order restrictions
out.lrder first derivative from the prices with order restrictions
out.nrder first derivative from the prices without order restriction
out.lrspd second derivative from the prices with order restriction
out.nrspd second derivative from the prices without order restriction
out.inlr confidence interval with order restriction
out.innr confidence interval without order restriction

Example:
; load necessary libraries
library("finance")
; no maturity and no risk-free interest rate
mat=0
rfree=0
; set random seed
randomize(1)
; generate data
x=(10:16)
L=rows(x)
spd=pdfn(x-13)+normal(L,3)/20
xx=x|x|x
ddd=sort((xx-1)~vec(cumsum(cumsum(spd[L:1]))[L:1]),1)
ppp=sort((xx+1)~vec(cumsum(cumsum(spd))),1)
;opt = spdopt("ci")
{lrcal,lrput,nrcal,nrput,lrder,nrder,lrspd,nrspd,inlr,innr}=spdest2(ddd,ppp,mat,rfree)
; true  value, the unconstrained and the constrained estimate
"true  value, the unconstrained and the constrained estimate"
setenv("outputformat","% 12.6f")
pdfn(x-13)~lrspd[,2]~nrspd[,2]
; and some nice plots
abst=1
values=(min(x)-1):(max(x)+1)
derplot=setmask(lrder,"line","blue")
nlderpl=setmask(nrder,"line","red","thin")
axes=graxes(nrder|lrder|((min(values)-abst)~(1))|(max(values)~-0.05),"origin",7.5,"xtextpos",6,"ytextpos",9,"xticks",values,"yticks",0|0.5|1,"xfmtstr","%4.0f")
axesoff()
di1=createdisplay(3, 1)
show(di1,2,1,derplot,nlderpl,axes)
clplot=setmask(lrcal,"line","blue")
plplot=setmask(lrput,"line","blue")
cnplot=setmask(nrcal,"line","red","thin")
pnplot=setmask(nrput,"line","red","thin")
dddplot=setmask(ddd,"small","cross")
pppplot=setmask(ppp,"small","cross")
axes2=graxes(lrcal|lrput|nrcal|nrput|ddd|((min(values)-abst)~(0))|(max(values)~0),"origin",7.5,"xtextpos",6,"ytextpos",9,"xticks",values,"xfmtstr","%4.0f")
show(di1,1,1,clplot,plplot,cnplot,pnplot,dddplot,pppplot,axes2)
lrspdplot=setmask(lrspd,"line","blue")
nrspdplot=setmask(nrspd,"line","red","thin")
axes3=graxes(lrspd|nrspd|((min(values)-abst)~(0))|(max(values)~0),"origin",(min(values)-abst)|(0),"xtextpos",6,"ytextpos",9,"xticks",values,"xfmtstr","%4.0f")
show(di1,3,1,axes3,lrspdplot,nrspdplot)

Result:
Contents of test

[1,] "H0: same spd from puts and calls; p-val = 0.9999"

Contents of _tmp

[1,] "true  value, the unconstrained and the constrained estimate"

Contents of _tmp

[1,]     0.004432    -0.034870     0.000000
[2,]     0.053991     0.098603     0.040848
[3,]     0.241971     0.254076     0.260188
[4,]     0.398942     0.404734     0.396031
[5,]     0.241971     0.244230     0.250381
[6,]     0.053991     0.110909     0.052553
[7,]     0.004432    -0.035521     0.000000

Display shows the put and call option prices (first graph), first derivatives (second graph)
and spd (third graph). The blue line is for the unconstrained estimates, the thin red line for the
constrained estimates.



Author: Z. Hlavka 20040219 license MD*Tech
(C) MD*TECH Method and Data Technologies, 05.02.2006