## 美式選擇權定價實作：American puts pricing using least-squares Monte Carlo method

### 一、問題描述：American puts pricing using least-squares Monte Carlo method

Write a least-squares Monte Carlo program to price American puts.

Output:

• Price and
• Standard derivation(sample)

Inputs:

• S (stock price at time 0),
• X (strike price),
• T (maturity in years),
• s (%) (annual volatility),
• r (%) (continuously compounded annual interest rate),
• n (number of periods), and
• k (number of simulation paths).

For example, when

• S = 101, X = 105, T = 1 (years), s = 15%, r = 2%, n = 50, and k = 100,000,

the price is about 7.3642 and the standard derivation is about 0.9975.

### 二、執行方式與執行結果

• LSMC_implement.R : 本次實作的主程式，可於參數區塊調整測試參數，答案(price, sd)將以標準輸出印於terminal
• LSMC_package.R : 第三方套件 LSMonteCarlo，用於驗證答案（需要安裝 LSMonteCarlo 套件）
• textbook_example.txt : 投影片講義之測試資料 http://www.csie.ntu.edu.tw/~lyuu/finance1.html

### 三、設計與實作

#### 1. Create two table : Stock Price Path Table and Stock Path Table

Generate the multivariate normal distribution for the Monte Carlo pricing of multivariate derivatives. using the formula below :

then we can generate a stock price paths table : StockPath[k,n]

and initial a cash flow table like this :

R code

# Create Stock Price Path Table
StockPath <- matrix(NA, nrow=k, ncol=n)

for(i in 1:k) {
front_para <- (r - s^2/2) * deltaT
back_para <- s * (sqrt(deltaT)) * rnorm(n, mean=0, sd=1)
StockPath[i,] <- S * exp(cumsum(front_para+back_para))
}
StockPath[ StockPath>X ] <- 0

# Create Cash Flow Table
CashFlow <- matrix(0, nrow=k, ncol=n)
CashFlow[,n] <- ifelse(StockPath[,n]!=0, X-StockPath[,n], 0)


#### 2. Backward pricing with regression

• Select in-the-money path : The cash flows at each year are the exercise value if the put is in the money.
• Regression : Only in-the-money paths will be used in the regression
• Compare : Compare Exercise value and Continuation value

R code

# Backward pricing with regression
for(m in (n-1):1){
sel_path <- which(StockPath[,m] > 0)

x_reg <- StockPath[sel_path,m]
y_reg <- vector(mode = "numeric", length = length(sel_path))

for(i in 1:length(sel_path)){
d <- min(which(CashFlow[ sel_path[i], ] > 0)) - m
y_reg[i] <- CashFlow[ sel_path[i], m+d] * discount_fac^d
}

contiuation <- predict( lm(y_reg ~ x_reg + I(x_reg^2)), x=x_reg)
exercise <- X - StockPath[which(StockPath[,m]>0), m]

CashFlow[sel_path,m] <- ifelse(exercise > contiuation, exercise, 0 )
}


### 四、結語：善用現成的工具

R code : using LSMonteCarlo package

library("LSMonteCarlo")
AmerPutLSM()
put<-AmerPutLSM(Spot = 101, Strike= 105,
mT = 1, sigma = 0.15, r = 0.02,
m = 50, n = 100000)
summary(put)


### References

Y.-D. Lyuu - Principles of Financial Computing
http://www.csie.ntu.edu.tw/~lyuu/finance1.html