@yhilpisch: Need help in debugging my code for LSM. With the current code, my value of American option is lower than European option.
def option_payoff(self, stimulated_price):
temp_zeros = np.zeros_like(stimulated_price)
return np.maximum(self.option_flag * (stimulated_price - self.instrument.strike), temp_zeros)
def LSM_model(self):
_s_stimulated = self.stimulation_method()
_intrinsic_val = self.option_payoff(self.stimulation_method())
_option_value = np.zeros_like(_intrinsic_val)
_option_value[:, -1] = _intrinsic_val[:, -1]
for t in range(self.no_of_steps - 1, 0, -1):
if len(_s_stimulated[_intrinsic_val[:, t] > 0, t]) == 0:
continue
else:
_ITM_check = _intrinsic_val[:, t] > 0
_x_axis = _s_stimulated[_ITM_check, t]
_y_axis = _option_value[_ITM_check, t + 1] * self.step_disc_fact
_option_value[:, t] = _option_value[:, t + 1] * self.step_disc_fact
_rg = np.polyfit(_x_axis, _y_axis, 5)
_pv_rg = np.polyval(_rg, _x_axis)
_option_value[_ITM_check, t] = np.where(_intrinsic_val[_ITM_check, t] > _y_axis,
_intrinsic_val[_ITM_check, t], _y_axis)
_option_value[:, 0] = _option_value[:, 1] * self.step_disc_fact
return np.mean(_option_value[:, 0])
Could you please help me in figuring out what I am missing on my above code.