You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何调整R语言二叉树欧式看涨期权代码实现美式行权最优判断

Adjusting Binomial Tree Code for American Call Options in R

Great question! The core difference between European and American call options is that American options allow early exercise. For your binomial tree model, this means at every non-terminal node, we need to compare two values:

  1. The present value of holding the option until the next period (same as the European calculation)
  2. The value of exercising the option immediately (max(S - K, 0))

We'll take the maximum of these two values at each node to get the correct American option price. Let's walk through modifying a typical European call binomial tree code step by step.

First, Let's Recap a Typical European Call Implementation

Here's a standard R function for European calls using the binomial tree method (this matches the structure you likely have):

european_call_binomial <- function(S0, K, r, sigma, T, n) {
  dt <- T / n  # Time step
  u <- exp(sigma * sqrt(dt))  # Up factor
  d <- 1 / u  # Down factor
  p <- (exp(r * dt) - d) / (u - d)  # Risk-neutral probability of up move
  
  # Terminal stock prices
  S_terminal <- S0 * u^(n:0) * d^(0:n)
  
  # Terminal option values (payoff at expiry)
  C <- pmax(S_terminal - K, 0)
  
  # Backward induction: calculate option values from expiry to today
  for (i in (n-1):0) {
    # Discount expected value from next period
    C <- (p * C[1:(i+1)] + (1-p) * C[2:(i+2)]) * exp(-r * dt)
  }
  
  return(C[1])
}

Modifications for American Call Options

The key changes are:

  • We need to track stock prices at every node (not just terminal) to calculate immediate exercise value
  • At each step of backward induction, we compare the "hold" value (European-style calculation) with the "exercise now" value, keeping the larger one

Here's the adjusted code:

american_call_binomial <- function(S0, K, r, sigma, T, n) {
  dt <- T / n
  u <- exp(sigma * sqrt(dt))
  d <- 1 / u
  p <- (exp(r * dt) - d) / (u - d)
  
  # Create a matrix to store stock prices at every node
  S <- matrix(0, nrow = n+1, ncol = n+1)
  for (period in 0:n) {
    for (node in 0:period) {
      S[node+1, period+1] <- S0 * u^(period - node) * d^node
    }
  }
  
  # Terminal option values (same as European)
  C <- pmax(S[, n+1] - K, 0)
  
  # Backward induction with early exercise check
  for (period in n:1) {
    # Calculate value if we hold the option (discounted expected value from next period)
    hold_value <- (p * C[1:period] + (1-p) * C[2:(period+1)]) * exp(-r * dt)
    # Calculate value if we exercise immediately right now
    exercise_value <- pmax(S[1:period, period] - K, 0)
    # Keep the maximum of the two values
    C <- pmax(hold_value, exercise_value)
  }
  
  return(C[1])
}

Key Explanations

  1. Tracking All Stock Prices: The matrix S stores the stock price at every node (row = node, column = period). This lets us compute the immediate exercise value at any point.
  2. Early Exercise Check: For each period going backward, we first calculate the value of holding the option (just like the European model). Then we calculate what we'd get if we exercise right now (max(S - K, 0)). We take the maximum of these two because the option holder will choose whichever gives higher value.
  3. Note on Dividends: For American call options on non-dividend-paying stocks, early exercise is never optimal—so this code will return almost the same price as the European version. But if you add dividend payments (by adjusting the stock price nodes to subtract dividends), the early exercise check will correctly account for cases where exercising before a dividend makes sense.

内容的提问来源于stack exchange,提问作者ccc

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.19 08:55:33