Create and Price Portfolio of Instruments
Use finportfolio and pricePortfolio to create and price a portfolio of interest-rate and equity instruments. The portfolio contains a vanilla FixedBond, an OptionEmbeddedFixedBond, a Vanilla European call option, a Vanilla American call option, and an Asian call option.   
Create ratecurve Object
Create a ratecurve object using ratecurve.
Settle = datetime(2018,9,15);
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;
ZeroCurve = ratecurve("zero",Settle,ZeroDates,ZeroRates);Create the Instrument Objects
Use fininstrument to create the instrument objects.
% Vanilla FixedBond CouponRate = 0.0325; Maturity = datetime(2038,3,15); Period = 1; VanillaBond = fininstrument("FixedBond",'Maturity',Maturity,'CouponRate',CouponRate, ... 'Period',Period,'Name',"VanillaBond")
VanillaBond = 
  FixedBond with properties:
                  CouponRate: 0.0325
                      Period: 1
                       Basis: 0
                EndMonthRule: 1
                   Principal: 100
    DaycountAdjustedCashFlow: 0
       BusinessDayConvention: "actual"
                    Holidays: NaT
                   IssueDate: NaT
             FirstCouponDate: NaT
              LastCouponDate: NaT
                   StartDate: NaT
                    Maturity: 15-Mar-2038
                        Name: "VanillaBond"
% OptionEmbeddedBond Maturity = datetime(2024,9,15); CouponRate = 0.035; Strike = 100; ExerciseDates = datetime(2023,9,15); CallSchedule = timetable(ExerciseDates,Strike,'VariableNames',{'Strike Schedule'}); Period = 1; CallableBond = fininstrument("OptionEmbeddedFixedBond", "Maturity",Maturity, ... 'CouponRate',CouponRate,'Period',Period, ... 'CallSchedule',CallSchedule, ... 'Name',"CallableBond"); % Vanilla European call option ExerciseDate = datetime(2022,1,1); Strike = 96; OptionType = 'call'; CallOpt = fininstrument("Vanilla",'ExerciseDate',ExerciseDate,'Strike',Strike, ... 'OptionType',OptionType, 'Name',"EuropeanCallOption")
CallOpt = 
  Vanilla with properties:
       OptionType: "call"
    ExerciseStyle: "european"
     ExerciseDate: 01-Jan-2022
           Strike: 96
             Name: "EuropeanCallOption"
% Vanilla American call option ExerciseDate = datetime(2023,1,1); Strike = 97; OptionType = 'call'; CallOpt_American = fininstrument("Vanilla",'ExerciseDate',ExerciseDate,'Strike',Strike, ... 'OptionType',OptionType, 'ExerciseStyle', "american", ... 'Name',"AmericanCallOption")
CallOpt_American = 
  Vanilla with properties:
       OptionType: "call"
    ExerciseStyle: "american"
     ExerciseDate: 01-Jan-2023
           Strike: 97
             Name: "AmericanCallOption"
% Asian call option ExerciseDate = datetime(2023,1,1); Strike = 102; OptionType = 'call'; CallOpt_Asian = fininstrument("Asian",'ExerciseDate',ExerciseDate,'Strike',Strike, ... 'OptionType',OptionType,'Name',"AsianCall")
CallOpt_Asian = 
  Asian with properties:
          OptionType: "call"
              Strike: 102
         AverageType: "arithmetic"
        AveragePrice: 0
    AverageStartDate: NaT
       ExerciseStyle: "european"
        ExerciseDate: 01-Jan-2023
                Name: "AsianCall"
Create Model Objects
Use finmodel to create HullWhite and BlackScholes model objects.
% Create the Hull-White model. Vol = 0.01; Alpha = 0.1; HWModel = finmodel("hullwhite",'alpha',Alpha,'sigma',Vol); % Create the Black-Scholes model. Vol = .1; SpotPrice = 95; BlackScholesModel = finmodel("BlackScholes",'Volatility',Vol);
Create Pricer Objects
Use finpricer to create Discount, IRTree, BlackScholes, Levy, and BjerksundStensland pricer objects and use the ratecurve object for the 'DiscountCurve' name-value argument.
% Create the Discount pricer. DiscPricer = finpricer("Discount","DiscountCurve",ZeroCurve); % Create the Hull-White tree pricer. TreeDates = Settle + calyears(1:30); HWTreePricer = finpricer("IRTree",'Model',HWModel,'DiscountCurve',ZeroCurve, ... 'TreeDates',TreeDates'); % Create the BlackScholes, Levy, and BjerksundStensland pricers. BLSPricer = finpricer("analytic",'DiscountCurve',ZeroCurve,'Model',BlackScholesModel,'SpotPrice',SpotPrice); LevyPricer = finpricer("analytic",'DiscountCurve',ZeroCurve,'Model',BlackScholesModel, ... 'SpotPrice',SpotPrice,'PricingMethod',"Levy"); BJSpricer = finpricer("analytic",'DiscountCurve',ZeroCurve,'Model',BlackScholesModel, ... 'SpotPrice',SpotPrice,'PricingMethod',"BjerksundStensland");
Create finportfolio Object
Create a finportfolio object that contains all of the instrument and pricer objects using finportfolio.
myPort = finportfolio([VanillaBond CallableBond CallOpt CallOpt_American CallOpt_Asian]', ...
                            [DiscPricer HWTreePricer BLSPricer BJSpricer LevyPricer]')myPort = 
  finportfolio with properties:
    Instruments: [5×1 fininstrument.FinInstrument]
        Pricers: [5×1 finpricer.FinPricer]
    PricerIndex: [5×1 double]
       Quantity: [5×1 double]
Price Portfolio
Use pricePortfolio to compute the price and sensitivities for the portfolio and the instruments in the portfolio.
[PortPrice,InstPrice,PortSens,InstSens] = pricePortfolio(myPort)
PortPrice = 237.3275
InstPrice = 5×1
  107.4220
  110.8389
    7.5838
    8.8705
    2.6123
PortSens=1×8 table
    Price      Delta     Gamma    Lambda     Vega      Theta      Rho       DV01 
    ______    _______    _____    ______    ______    _______    ______    ______
    237.33    -546.39    2840     26.354    124.28    -4.0673    418.68    0.1579
InstSens=5×8 table
                          Price      Delta      Gamma      Lambda     Vega       Theta       Rho       DV01 
                          ______    _______    ________    ______    _______    ________    ______    ______
    VanillaBond           107.42        NaN         NaN       NaN        NaN         NaN       NaN    0.1579
    CallableBond          110.84     -547.9      2839.9       NaN    -62.532         NaN       NaN       NaN
    EuropeanCallOption    7.5838    0.57026    0.022762    7.1435     67.763     -1.3962    153.68       NaN
    AmericanCallOption    8.8705     0.5845    0.019797    6.2597     76.808     -1.8677    200.68       NaN
    AsianCall             2.6123    0.35611    0.032053     12.95     42.238    -0.80342     64.31       NaN