Thursday, 30 May 2013

Scenario analysis for option strategies.

Introduction to the project I am working on at the moment. It is more a playground for option strategies than "project" at this stage.

The idea is to develop accurate scenario analysis on portfolio, which is based on a single underlying. In the past I have written some code on simply plotting the payoffs at maturity, then followed a small piece of code, which was improved in a way that specific date could have been chosen for which the payoff is plotted.

For my current project I think the output will be self explanatory. The code is just the running bit to give a feeling of what it does and how it does what it does:

######################## GEN PARAMETERS ###############################
gen.par  <- vaGenPar(date.start=Sys.Date(), 
              date.end=Sys.Date()+days(359),r=0.05, cal="UnitedStates")
 
######################## STOCK PARAMETERS #############################
AAPL   <- vaSPar("AAPL", s0=100, date=Sys.Date(), vol=0.3720573)
# AMZN   <- vaSPar("AMZN", s0=100, date=Sys.Date(), vol=0.4548506)
stock.par  <- vaStockPar(AAPL)
 
######################## INSTRUMENTS ##################################
rmi()
# equity_s("AAPL","USD", num=1)
# equity_f("AAPL_fut",  "AAPL", "USD", Sys.Date()+days(180), num=1)
equity_o("AAPL1", "AAPL", "USD", Sys.Date()+days(360), 80, 0, 0, "vanilla", num=1)
equity_o("AAPL2",  "AAPL", "USD", Sys.Date()+days(360), 100, 0, 0, "vanilla", num=-2)
equity_o("AAPL3",  "AAPL", "USD", Sys.Date()+days(360), 120, 0, 0, "vanilla", num=1)
instruments <- vaInstruments()
 
######################## RUN ###########################################
output <- main.aggregate(gen.par, stock.par, instruments, nsd=2, step=0.005, nstd=1.5)
play3d(spin3d(axis=c(0,0,1), rpm=5), duration=12)


The range of the stock values are 2 standard deviations that were plugged into GBM, which was obviously adjusted for risk neutrality as we are in pricing framework. The red line indicates 1.5 standard deviation line. "step" is increment of possible stock prices via volatility.
Furthermore, it returns a function which does an interpolation over the surface, so analysis at each time point can simply be done.

x=50:300
y=outfun(Sys.Date()+days(185), x)
plot(x,y,"l")


For now, the interest rates used are flat as well as implied volatility surface. However, the needed space was made so both can be easily implemented. Also, it is restructured in such way, that new pricing functions can be added effortlessly.

Implementing multiple assets can also be easily done, however I did not figure out, how to aggregate total pnl. One way to do it would be taking 1 stock as a reference, and using beta coefficients to sum the pnl. However, this would flaw the output via false assumption of constant beta with 0 variation.

Other derivatives in my mind are american options, powers, barriers or index linked notes that are possible to price via known pricing functions. In general, anything that could be priced without needing to calibrate model with more than one source of risk.

Comments and suggestions are welcome.