%% Price Portfolio of Multiple Instances of Heterogeneous Instruments
% Use finportfolio and pricePorfolio to create and price a portfolio containing three FixedBond instruments and three  American Vanilla option instruments.
%% Create FixedBond Instrument Object
% Use fininstrument to create a FixedBond instrument object for three Fixed Bond instruments.

FixB = fininstrument("FixedBond",'Maturity',datetime([2022,9,15 ; 2022,10,15 ; 2022,11,15]),'CouponRate',0.05,'Name',"fixed_bond")

%
%% Create ratecurve Object
% Create a ratecurve object using ratecurve.

Settle = datetime(2018,9,15);
Type = 'zero';
ZeroTimes = [calmonths(6) calyears([1 2 3 4 5 7 10 20 30])]';
ZeroRates = [0.0052 0.0055 0.0061 0.0073 0.0094 0.0119 0.0168 0.0222 0.0293 0.0307]';
ZeroDates = Settle + ZeroTimes;
 
myRC = ratecurve('zero',Settle,ZeroDates,ZeroRates)

%% Create Discount Pricer Object for FixedBond Instruments
% Use finpricer to create a Discount pricer object and use the ratecurve object for the 'DiscountCurve' name-value pair argument.

FBPricer = finpricer("Discount",'DiscountCurve',myRC)

%% Create Vanilla Instrument Object
% Use fininstrument to create an American Vanilla instrument object for three Vanilla instruments.

Maturity = datetime([2023,9,15 ; 2023,10,15 ; 2023,11,15]);
AmericanOpt = fininstrument("Vanilla",'ExerciseDate',Maturity,'Strike',120,'ExerciseStyle',"american",'Name',"vanilla_option")

%% Create BlackScholes Model Object for Vanilla Instruments
% Use finmodel to create a BlackScholes model object.

BSModel = finmodel("BlackScholes",'Volatility',0.12)

%% Create BjerksundStensland Pricer Object for Vanilla Instruments
% Use finpricer to create an analytic pricer object for the BjerksundStensland pricing method and use the ratecurve object for the 'DiscountCurve' name-value pair argument.

BJSPricer = finpricer("analytic",'Model',BSModel,'DiscountCurve',myRC,'SpotPrice',100,'DividendValue',.02,'PricingMethod',"BjerksundStensland")

%% Add the Instruments to a finportfolio Object
% Create a finportfolio object using finportfolio and add the six instruments with their associated pricers to the portfolio.

f1 = finportfolio([AmericanOpt;FixB],[BJSPricer, BJSPricer, BJSPricer, FBPricer, FBPricer, FBPricer])

%% Price Portfolio
% Use pricePorfolio to compute the price and sensitivities for the portfolio and the instruments in the portfolio.

[PortPrice,InstPrice,PortSens,InstSens] = pricePortfolio(f1)

% Copyright 2021 The MathWorks, Inc.