Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ## description available at: http://reakkt.com
- rm(list = ls()) # clear all
- ### sample strategies
- # ## Put Hedging
- #
- # assetsN <- 2
- #
- # current.price <- 40
- #
- # assets.mat <- matrix(NA,assetsN,5)
- # colnames(assets.mat) <- c("trans","type","strike","price","amount")
- #
- # assets.mat[1,] <- c("buy", "base", 40, 0, 1) # buy underlying
- # assets.mat[2,] <- c("buy", "put", 35, 2, 1) # hedge with a OTM put
- #
- # price.range <- c(10,80)
- # price.step <- 1
- ## Sell short base
- assetsN <- 2
- current.price <- 40
- assets.mat <- matrix(NA,assetsN,5)
- colnames(assets.mat) <- c("trans","type","strike","price","amount")
- assets.mat[1,] <- c("sell", "base", 40, 0, 1) # sell underlying
- assets.mat[2,] <- c("buy", "call", 35, 2, 1) # hedge with a ITM call
- price.range <- c(10,80)
- price.step <- 1
- # ## Bull Call Spread
- # # http://www.theoptionsguide.com/bull-call-spread.aspx
- #
- # assetsN <- 2
- #
- # current.price <- 42
- #
- # assets.mat <- matrix(NA,assetsN,5)
- # colnames(assets.mat) <- c("trans","type","strike","price","amount")
- #
- # assets.mat[1,] <- c("buy", "call", 40, 3, 1) # ITM call
- # assets.mat[2,] <- c("sell", "call", 45, 1, 1) # OTM call
- #
- # price.range <- c(35,50)
- # price.step <- 1
- # ## Call Backspread
- # # http://www.theoptionsguide.com/call-backspread.aspx
- #
- # assetsN <- 2
- #
- # current.price <- 43
- #
- # assets.mat <- matrix(NA,assetsN,5)
- # colnames(assets.mat) <- c("trans","type","strike","price","amount")
- #
- # assets.mat[1,] <- c("sell", "call", 40, 4, 1) # ITM call
- # assets.mat[2,] <- c("buy", "call", 45, 2, 2) # OTM call
- # ## Condor
- # # http://www.theoptionsguide.com/condor.aspx
- #
- # assetsN <- 4
- #
- # current.price <- 45
- #
- # assets.mat <- matrix(NA,assetsN,5)
- # colnames(assets.mat) <- c("trans","type","strike","price","amount")
- #
- # assets.mat[1,] <- c("buy", "call", 35, 11, 1)
- # assets.mat[2,] <- c("buy", "call", 55, 1, 1)
- # assets.mat[3,] <- c("sell", "call", 40, 7, 1)
- # assets.mat[4,] <- c("sell", "call", 50, 2, 1)
- # ## some other strategy
- # assetsN <- 3
- #
- # assets.mat <- matrix(NA,assetsN,5)
- # colnames(assets.mat) <- c("trans","type","strike","price","amount")
- #
- # assets.mat[1,] <- c("sell", "put", 500, 5, 1)
- # assets.mat[2,] <- c("sell", "put", 700, 10, 1)
- # assets.mat[3,] <- c("buy", "call", 1000, 15, 1)
- ###
- if (!exists("price.range")) {
- price.range <- range(as.numeric(assets.mat[,"strike"]))*c(0.8,1.2)
- price.step <- 0.1
- }
- x <- seq(price.range[1],price.range[2],price.step)
- options.val <- matrix(NA,assetsN,length(x))
- ###
- OptionVal <- function(x,trans,type,strike,premium,amount=1) {
- strike <- as.numeric(strike)
- premium <- as.numeric(premium)
- amount <- as.numeric(amount)
- if (trans=="buy" && type=="base") value <- x-strike-premium
- if (trans=="sell" && type=="base") value <- strike-x-premium
- if (trans=="buy" && type=="call") value <- max(x-strike,0)-premium
- if (trans=="sell" && type=="call") value <- premium-max(x-strike,0)
- if (trans=="buy" && type=="put") value <- max(strike-x,0)-premium
- if (trans=="sell" && type=="put") value <- premium-max(strike-x,0)
- return( amount*value )
- }
- for (i in 1:assetsN)
- options.val[i,] <- sapply( x, function(x)
- OptionVal(x,
- assets.mat[i,"trans"],
- assets.mat[i,"type"],
- assets.mat[i,"strike"],
- assets.mat[i,"price"],
- assets.mat[i,"amount"]) )
- options.all <- colSums(options.val)
- # rbind(x,options.all)
- plot(options.all,
- main="Payoff",ylab="profit/loss",xlab="price",
- type="l",xaxt="n")
- if (!is.null(current.price)) abline(v=which(x==current.price),col="Green",lwd=2)
- abline(v=sapply(as.numeric(assets.mat[,"strike"]), function(s) which(x==s)),col="Blue",lty="dotted")
- abline(h=0,col="Red",lty="dashed")
- axis(1,seq(0,length(x),length.out=5),round(seq(min(x),max(x),length.out=5)))
- assets.mat
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement