R/writing.call.R

Defines functions writing.call

Documented in writing.call

#' Visualization of the Strategy of Sale of Standby Purchase Rights (Reverse Operation of the Strategy of Sale Standby Purchase Rights)
#' @description The write.call() function generates a graph showing the profits and losses of short call options and long stock portfolios or long call options and short stock portfolios. The reason for the strategy of selling covered call right is that it is bullish on the market, but worries about the future stock price decline. If the future stock price falls, the gains of short call right can be used to compensate for the losses. Its reverse operation is short-sighted on the market, but also worried about the future stock price rise, if the future stock price rises, we can compensate for the loss through the implementation of the right to buy.
#' @note If there is a mutual occlusion problem in the image, you can run the dev.new() command first. If there is still occlusion problem, you can directly run the writing. call command to call out the source code of the function, and eliminate the occlusion problem by modifying the corresponding graphic parameters.
#' @param K Execution price of call option
#' @param S Current stock price, default value is 42
#' @param opt The Price of Call Options
#' @param position Specify whether to use the forward redemption strategy (-C+S) or the reverse protection strategy (+C-S).
#' @examples
#' writing.call(K = 40, opt = 5, S = 42)
#' writing.call(K = 40, opt = 5, S = 42, position = "short")
#' @references
#' John C.Hull. Options, Futures, and other Derivatives 9ed
#' @seealso
#' \code{\link{protective.put}}
#' @export
writing.call <- function(K = 40, opt = 5, S = 42, position = "long"){
  if (position != "long" & position != "short")
    stop("position must equal long or short")
  x = seq(K - K/2, K + K/2, 0.01)
  if (position == "long"){
    y1 = x - S
    y2 = ifelse(x <= K, opt, K - x + opt)
    y = y1 + y2
    plot(x, y, type = "l", ann = FALSE, ylim = c(1.5*min(min(y1, y2), y), 1.5*max(max(y1, y2), y)), col = 2, lty = 1, lwd = 2)
    lines(x, y1, type = "l", col = 3, lty = 1, lwd = 1)
    lines(x, y2, type = "l", col = 4, lty = 1, lwd = 1)
    abline(h = 0, lty = 2)
    title(main = "Writing a covered call", xlab = "Stock price", ylab = "Payoff", cex.lab = 1)
    legend("bottomright", c("Portfolio payoff", "Payoff from long stock", "Payoff from short call"), col = 2:4, lty = 1, cex = 0.9)
  }
  if (position == "short"){
    y1 = S - x
    y2 = ifelse(x <= K, -opt, x - K - opt)
    y = y1 + y2
    plot(x, y, type = "l", ann = FALSE, ylim = c(1.5*min(min(y1, y2), y), 1.5*max(max(y1, y2), y)), col = 2, lty = 1, lwd = 2)
    lines(x, y1, type = "l", col = 3, lty = 1, lwd = 1)
    lines(x, y2, type = "l", col = 4, lty = 1, lwd = 1)
    abline(h = 0, lty = 2)
    title(main = "The reverse of a writing a covered call", xlab = "Stock price", ylab = "Payoff", cex.lab = 1)
    legend("topright", c("Portfolio payoff", "Payoff from short stock", "Payoff from long call"), col = 2:4, lty = 1, cex = 0.9)
  }
}
czxa/FMFE documentation built on Nov. 6, 2019, 4:58 a.m.