Longstaff–Schwartz and Neural Networks for American Option Pricing
Summary
The document presents an attempted Monte Carlo implementation of Longstaff–Schwartz for an American put, then describes an effort to replace polynomial continuation-value regression with a neural network. The accompanying response questions whether the polynomial code implements the method correctly: Longstaff–Schwartz estimates continuation values during a backward pass, then uses a forward Monte Carlo valuation step. A single output for one parameter set is not enough to establish correctness; comparisons with known European and American option prices are suggested.
The neural-network example appears to reverse the intended input and target roles, requests more input features than its arrays supply, and does not show a complete pricing procedure. The discussion therefore serves mainly as a code review and modeling caution, rather than a validated implementation. It also questions whether a neural network is warranted for the continuation-value function in this example. No reliable neural-network price or comparative evidence is reported.
Key ideas
- Longstaff–Schwartz combines backward continuation-value estimation with a forward Monte Carlo pricing step.
- A single computed price does not verify that an option-pricing implementation is correct.
- The neural-network example appears to use the continuation value and spot price in reversed roles.
- Input dimensions must match the features supplied to a neural-network regression model.
- Benchmarking against established option prices helps assess an implementation before changing its regression method.
Tags
Full text
# Least-Squares-Monte-Carlo by Neural Network Estimator for pricing American Option Python
# Least-Squares-Monte-Carlo by Neural Network Estimator for pricing American Option Python
First I did the LSM (Longstaff-Schwartz) to understand how its work to price an American option.
code for standard_normal
```
def gen_sn(M,I,anti_paths=True,mo_match=True):
if anti_paths is True:
sn= npr.standard_normal((M+1,np.int(I/2) ))
sn= np.concatenate((sn,-sn),axis=1)
else:
sn=npr.standard_normal((M+1,I))
if mo_match is True:
sn = (sn-sn.mean())/sn.std()
return sn
```
then, for the simulation and the pricing
```
def amer(K,S0,r,sigma,T,M,I):
dt = T/M
df = np.exp(-r*dt)
S=np.zeros((M+1 ,I))
S[0]=S0
sn= gen_sn(M,I)
for t in range(1,M+1):
S[t] = S[t-1] * np.exp((r-0.5*sigma**2)*dt + sigma * np.sqrt(dt) * sn[t]) #brown
h = np.maximum(K-S,0)
#LSM Algo
V=np.copy(h)
for t in range(M-1,0,-1): #von 12 bis 0 in -1 schritten -> 12,11,10,9,..,0
reg = np.polyfit(S[t], V[t+1] * df, 3) #least-squares-polynomial-fit /sum(Y-X)^2
C = np.polyval(reg,S[t])
V[t] = np.where(C > h[t], V[t+1]* df, h[t])
#MCS estimator
C0 = df * 1/I *np.sum(V[1])
return C0
```
So I use this parameters and get this estimated price
```
amer(90.,100,0.05,0.25,1.0,12,2000) -> 3.6793077
```
I think this code is ok
So now I will use the Keras Library for neural network regression estimator My results make no sense for me , I am very confused now
```
def amer(K,S0,r,sigma,T,M,I):
dt = T/M
df = np.exp(-r*dt)
S=np.zeros((M+1 ,I))
S[0]=S0
sn= gen_sn(M,I)
for t in range(1,M+1):
S[t] = S[t-1] * np.exp((r-0.5*sigma**2)*dt + sigma * np.sqrt(dt) * sn[t])
h = np.maximum(K-S,0)
V = np.copy(h)
num_features=13
model=Sequential()
init_w= RandomUniform(minval=-1.0, maxval=1.0) #weight
init_b = Constant(value=0.0) #bias
for t in range(M-1,0,-1):
model.add(Dense(4, kernel_initializer=init_w, bias_initializer=init_b, input_shape=(num_features,)))
model.add(Activation("sigmoid"))
model.add(Dense(2, kernel_initializer=init_w, bias_initializer=init_b))
model.summary()
lr = 0.005
optimizer = Adam(lr=lr)
model.compile(loss="mse", optimizer=optimizer, metrics=['accuracy'])
X= V[t+1] * df
x_train=X[:1000]
x_test = X[1000:2000]
y= S[t]
y_train = y[:1000]
y_test = y[1000:2000]
model.fit(x=x_train, y=y_train, verbose=1, epochs=100, validation_data=[x_test,y_test])
score = model.evaluate(,y)
return score
```
## Answer by Ezy (score 3)
https://quant.stackexchange.com/a/43312
In the non nn case your code does not implement the longstaff-schwartz algorithm so i am not sure what makes why you think it does. Longstaff-Schwartz is a Monte-Carlo method and you seem to be implementing some backward pricing scheme so this does not make much sense at all to me.
Longstaff-Schwartz has 2 phases: 1 backward pricing step to calibrate the continuation value estimator and a regular MC forward pricing step to actually price the option.
You seem to have tested that for some value of the input your procedure returns some double value but this is far from being a test that your procedure is correct! You should benchmark your code against known results for european and american payoffs in order to take any sort of conclusion regarding the “ok-ness” of your code.
So overall, you should spend more time checking that your pricing algo actually makes sense before using NN as an alternative fitting algo for the continuation value. It is not even clear what you are trying to achieve here because the continuation value of an american is not so non-linear as to justify using a NN algo to fit it so it is not even clear what your motivation is here.
NB: you keras procedure seem not even to make sense as you seem to use the continuation value as “X” and the spot value as “Y” so it is not even clear what you are trying to do at all here. There is not even any pricing logic.
In addition you seem to be hitting an error where a basic input array having the wrong shape for your keras fit to work as you are asking for 13 features but provide a single dimenion array as input for X so you must have a basic input incorrectly setup. So probably you want to make some basic tests that you know how to use this fitter before asking how to use it inside some sort of american option pricing algo.
## Answer by hallo12 (score 0)
https://quant.stackexchange.com/a/43351
ok, sorry but i am not understanding what u are trying. Here is a paper, i think it can be helpful for u. But there is one problem what is not clear for me. The features Matrix X ("feature_matrix_from_current_state), he used the chebyshev polynomials with degree 4. So if u want to use neural network , i think u must change this feature matrix , but i dont know how u can do it. https://ipythonquant.wordpress.com/2018/06/01/pricing-bermudan-options-in-tensorflow-learning-an-optimal-early-exercise-strategy/Shown in full with attribution under the source's licence. Licence: CC BY-SA 4.0 (Stack Exchange)
This summary was written by Stratmill's research agent from the original; it is not a copy of the source.