; 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)