%% Set Put Exercise Policy for Specific Option Embedded Fixed Bond Instrument
% This example shows how to use setPutExercisePolicy to maintain consistency between the exercise schedule and exercise style when using a OptionEmbeddedFixedBond instrument object with three OptionEmbeddedFixedBond instruments.
%
%% Create OptionEmbeddedFixedBond Instrument Object
% Use fininstrument to create an OptionEmbeddedFixedBond instrument object for three Option Embedded Fixed Bond instruments with American exercise styles.

Maturity = datetime([2024,1,1 ; 2024,4,1 ; 2024,8,1]);
Strike = [100;100];
ExerciseDates = [datetime(2020,1,1); datetime(2024,1,1)];
Period = 1;
PutSchedule =  timetable(ExerciseDates,Strike,'VariableNames',{'Strike Schedule'}); 

PuttableBond = fininstrument("OptionEmbeddedFixedBond",'Maturity',Maturity,...
                              'CouponRate',0.025,'Period',Period, ...
                              'PutSchedule',PutSchedule)
PuttableBond.PutExerciseStyle

% The PutExerciseStyle is "American" because the fininstrument syntax does not contain a PutExercideStyle specification and there are two exercise dates defined in the PutSchedule.
%% Set Exercise Style to Bermudan
% Use setPutExercisePolicy to define PutExerciseStyle as Bermudan for the second (PuttableBond(2)) instrument.

PuttableBond(2) = setPutExercisePolicy(PuttableBond(2), PutSchedule, "Bermudan") 
PuttableBond.PutExerciseStyle

% Use setPutExercisePolicy to modify PutSchedule and continue using a Bermudan exercise style.

Strike = [100; 101;102;103];
ExerciseDates = [datetime(2018,1,1);datetime(2020,1,1);datetime(2022,1,1);datetime(2024,1,1)];

PutSchedule =  timetable(ExerciseDates,Strike,'VariableNames',{'Strike Schedule'}); 

PuttableBond(2) = setPutExercisePolicy(PuttableBond(2), PutSchedule)   
PuttableBond.PutExerciseStyle

% Copyright 2021 The MathWorks, Inc.