Plot of Option Delta over Time to Maturity

For questions and discussion related to graphs, reports, and other output, including issues related to presenting or publishing results.
alexecon
Posts: 72
Joined: Fri Oct 30, 2015 12:16 pm

Plot of Option Delta over Time to Maturity

Unread post by alexecon »

I'm trying to do the above but can't figure out how.

I have had success plotting delta, theta and gamma against the underlying asset price, as in the following program:

Code: Select all

smpl 30 70
*
* calculate BSM price
*
@BSOPTION(price=49,strike=50,rate=0.05,sigma=0.2,expire=0.3846) bsm
dis "BSM price is" bsm
*
* calculate and plot BSM prices for a range of asset prices
*
compute strike=50
compute rate=0.05
compute sigma=0.2
compute cashflow=0
compute expire=0.3846
set s = t
clear d11
clear d22
clear value
* plot of call option premium against asset price
do i=30,70
   compute d11(i)=(log(s(i)/strike)+expire*(rate-cashflow+.5*sigma**2))/(sigma*sqrt(expire))
   compute d22(i)=d11(i)-sigma*sqrt(expire)
   compute value(i)=s(i)*exp(-cashflow*expire)*%cdf(d11(i))-strike*exp(-rate*expire)*%cdf(d22(i))
end do i
graph(style=line,header="Call option premium and asset price (in $)",vlabel="Call option premium",hlabel="Asset price") $
 1
# value
*
* calculate and plot delta against asset prices
*
clear calldelta
clear putdelta
do i=30,70
   compute calldelta(i)=%cdf(d11(i))
   compute putdelta(i)=%cdf(d11(i))-1
end do i
graph(height=%cm(15),width=%cm(12),style=line,header="Call option delta and asset price",vlabel="Call option delta",hlabel="Asset price") $
 1
# calldelta
graph(height=%cm(15),width=%cm(12),style=line,header="Put option delta and asset price",vlabel="Put option delta",hlabel="Asset price") $
 1
# putdelta
*
* calculate and plot thetas for puts and calls against asset prices
*
clear calltheta
clear puttheta
do i=30,70
   compute calltheta(i)=-(49*%density(d11(i))*sigma)/(2*sqrt(expire))-(rate*strike*exp(-rate*expire))*%cdf(d22(i))
   compute puttheta(i)=-(49*%density(d11(i))*sigma)/(2*sqrt(expire))+(rate*strike*exp(-rate*expire))*%cdf(-d22(i))
end do i
graph(style=line,key=attached,klabel=||"Call","Put"||,header="Thetas and asset price",vlabel="Option Thetas",hlabel="Asset price") $
 2
# calltheta
# puttheta
*
* calculate and plot gamma for puts and calls against asset prices
*
clear callputgamma
do i=30,70
   compute callputgamma(i)=(%density(d11(i)))/(49*sigma*sqrt(expire))
end do i
graph(style=line,header="Gamma (for puts and calls) and asset price",vlabel="Option Gammma",hlabel="Asset price") $
 1
# callputgamma
Would you be able to resolve this for me? Thank you in advance.
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: Plot of Option Delta over Time to Maturity

Unread post by TomDoan »

Maybe I'm not understanding what you want, but wouldn't that just be a SCATTER instruction?
alexecon
Posts: 72
Joined: Fri Oct 30, 2015 12:16 pm

Re: Plot of Option Delta over Time to Maturity

Unread post by alexecon »

You're right, I didn't explain well what I need. Before plotting deltas over time, I need to generate them first, e.g. with something like this:

Code: Select all

do i = 1,100
compute delta(i)=%cdf((log(price/strike)+expire(i)*(rate-cashflow+.5*sigma**2))/(sigma*sqrt(expire(i))))
end do i
The problem with the above is that it loops over integers, whereas I would like it to loop over 0.01, 0.02, ..., 0.1, 0.11, ..., 1.0. For a given price, strike, rate, sigma and cashflow, delta changes with expire. Once I get these 100 values then I can plot them. Thank you for your help.
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: Plot of Option Delta over Time to Maturity

Unread post by TomDoan »

You might want to look at the portfolio.rpf example, which solves a portfolio problem over a controlled range and does a scatter gram of the solutions.
alexecon
Posts: 72
Joined: Fri Oct 30, 2015 12:16 pm

Re: Plot of Option Delta over Time to Maturity

Unread post by alexecon »

Thank you for all the input. The following shows how to plot option greek parameters against asset prices, maturity, etc. in RATS. The examples correspond to those in the chapter on the Greeks from Hull's Options, Futures and Other Derivatives.

This sets the input values for the non-dividend-paying option:

Code: Select all

smpl 30 70
compute strike=50
compute rate=0.05
compute sigma=0.2
compute cashflow=0
compute expire=0.3846
* expiry is 20/52 (weeks)
This plots the call option premium against the asset price:

Code: Select all

set s = t
clear d11
clear d22
clear value
*
do i=30,70
   compute d11(i)=(log(s(i)/strike)+expire*(rate-cashflow+.5*sigma**2))/(sigma*sqrt(expire))
   compute d22(i)=d11(i)-sigma*sqrt(expire)
   compute value(i)=s(i)*exp(-cashflow*expire)*%cdf(d11(i))-strike*exp(-rate*expire)*%cdf(d22(i))
end do i
graph(style=line,header="Call option premium and asset price (in $)",vlabel="Call option premium",hlabel="Asset price", $
width=%cm(15),height=%cm(10)) $
1
# value
Image

This calculates and plots call and put deltas against asset prices:

Code: Select all

clear calldelta
clear putdelta
do i=30,70
   compute calldelta(i)=%cdf(d11(i))
   compute putdelta(i)=%cdf(d11(i))-1
end do i
graph(height=%cm(15),width=%cm(12),style=line,header="Call option delta and asset price",vlabel="Call option delta",hlabel="Asset price") $
 1
# calldelta
graph(height=%cm(15),width=%cm(12),style=line,header="Put option delta and asset price",vlabel="Put option delta",hlabel="Asset price") $
 1
# putdelta
Image
Image

This calculates and plots (annual) thetas for puts and calls against asset prices:

Code: Select all

clear calltheta
clear puttheta
do i=30,70
   compute calltheta(i)=-(49*%density(d11(i))*sigma)/(2*sqrt(expire))-(rate*strike*exp(-rate*expire))*%cdf(d22(i))
   compute puttheta(i)=-(49*%density(d11(i))*sigma)/(2*sqrt(expire))+(rate*strike*exp(-rate*expire))*%cdf(-d22(i))
end do i
graph(style=line,key=attached,klabel=||"Call","Put"||,header="Thetas and asset price",vlabel="Option Thetas",hlabel="Asset price", $
width=%cm(15),height=%cm(10)) $
2
# calltheta
# puttheta
Image

This calculates and plots gamma for puts and calls against asset prices:

Code: Select all

clear callputgamma
do i=30,70
   compute callputgamma(i)=(%density(d11(i)))/(49*sigma*sqrt(expire))
end do i
graph(style=line,header="Gamma (for puts and calls) and asset price",vlabel="Option Gammma",hlabel="Asset price",width=%cm(15),height=%cm(10)) $
 1
# callputgamma
Image

This plots delta against the option's time to maturity for four options (deeply in the money, in the money, at the money and out of the money):

Code: Select all

smpl 1 20
clear delta1
clear delta2
clear delta3
clear delta4
do i= 1,20
compute delta1(i)=%cdf((log(55.0/50.0)+((i)/52.0)*(0.05+.5*0.2**2))/(0.2*sqrt((i)/52.0)))
compute delta2(i)=%cdf((log(51.0/50.0)+((i)/52.0)*(0.05+.5*0.2**2))/(0.2*sqrt((i)/52.0)))
compute delta3(i)=%cdf((log(50.0/50.0)+((i)/52.0)*(0.05+.5*0.2**2))/(0.2*sqrt((i)/52.0)))
compute delta4(i)=%cdf((log(48.0/50.0)+((i)/52.0)*(0.05+.5*0.2**2))/(0.2*sqrt((i)/52.0)))
end do i
set time = t
graph(style=line,header="Delta and Time",subheader= $
"In-the-money, At-the-money and Out-of-the-money Options",$
hlabel="Time",vlabel="Delta",width=%cm(15),height=%cm(10), $
key=attached,klabel=||"Price = 55 ","Price = 52", $
"Price = 50","Price = 48"||) 4
# delta1
# delta2
# delta3
# delta4
Image
Last edited by alexecon on Wed Dec 27, 2017 1:24 pm, edited 1 time in total.
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: Plot of Option Delta over Time to Maturity

Unread post by TomDoan »

Thank you for your contribution. What's the significance of the 30 to 70 range used (in SMPL's and in DO loops)?
alexecon
Posts: 72
Joined: Fri Oct 30, 2015 12:16 pm

Re: Plot of Option Delta over Time to Maturity

Unread post by alexecon »

TomDoan wrote:Thank you for your contribution. What's the significance of the 30 to 70 range used (in SMPL's and in DO loops)?
This sets the range of asset prices for which the deltas and other greeks are calculated. The horizontal axis in the relevant graphs (i.e. plots of a greek against asset price) uses this range.
Post Reply