addInstrument
Add instrument to portfolio of instruments
Syntax
Description
adds the instrument outPort = addInstrument(inPort,inInst)inInst to a portfolio inPort of
instruments previously created using finportfolio.
adds the instrument outPort = addInstrument(inPort,inInst,inPricer)inInst and the associated pricer
inPricer to a portfolio inPort of instruments
previously created using finportfolio.
Examples
Use finportfolio to create an empty portfolio and then use addInstrument to add instruments to the portfolio.
Create FixedBond Instrument Objects
Use fininstrument to create two FixedBond instrument objects.
FixB1 = fininstrument("FixedBond", 'Maturity',datetime(2022,9,15),'CouponRate',0.045,'Name',"fixed_bond1")
FixB1 =
FixedBond with properties:
CouponRate: 0.0450
Period: 2
Basis: 0
EndMonthRule: 1
Principal: 100
DaycountAdjustedCashFlow: 0
BusinessDayConvention: "actual"
Holidays: NaT
IssueDate: NaT
FirstCouponDate: NaT
LastCouponDate: NaT
StartDate: NaT
Maturity: 15-Sep-2022
Name: "fixed_bond1"
FixB2 = fininstrument("FixedBond", 'Maturity',datetime(2022,9,15),'CouponRate',0.035,'Name',"fixed_bond2")
FixB2 =
FixedBond with properties:
CouponRate: 0.0350
Period: 2
Basis: 0
EndMonthRule: 1
Principal: 100
DaycountAdjustedCashFlow: 0
BusinessDayConvention: "actual"
Holidays: NaT
IssueDate: NaT
FirstCouponDate: NaT
LastCouponDate: NaT
StartDate: NaT
Maturity: 15-Sep-2022
Name: "fixed_bond2"
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)
myRC =
ratecurve with properties:
Type: "zero"
Compounding: -1
Basis: 0
Dates: [10×1 datetime]
Rates: [10×1 double]
Settle: 15-Sep-2018
InterpMethod: "linear"
ShortExtrapMethod: "next"
LongExtrapMethod: "previous"
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.
DiscountPricer = finpricer("Discount", 'DiscountCurve',myRC)
DiscountPricer =
Discount with properties:
DiscountCurve: [1×1 ratecurve]
Add Instruments to finportfolio Object
Create an empty finportfolio object using finportfolio and then use addInstrument to put the FixedBond instruments into the portfolio.
f1 = finportfolio; f1 = addInstrument(f1,FixB1)
f1 =
finportfolio with properties:
Instruments: [1×1 fininstrument.FixedBond]
Pricers: [0×1 finpricer.FinPricer]
PricerIndex: NaN
Quantity: 1
f1 = addInstrument(f1,FixB2)
f1 =
finportfolio with properties:
Instruments: [2×1 fininstrument.FixedBond]
Pricers: [0×1 finpricer.FinPricer]
PricerIndex: [2×1 double]
Quantity: [2×1 double]
Set Pricer for Portfolio
Use setPricer to set the pricer for the portfolio and then use pricePortfolio to calculate the price and sensitivities for the instruments in the portfolio.
f1 = setPricer(f1,DiscountPricer,[1,2])
f1 =
finportfolio with properties:
Instruments: [2×1 fininstrument.FixedBond]
Pricers: [1×1 finpricer.Discount]
PricerIndex: [2×1 double]
Quantity: [2×1 double]
[PortPrice,InstPrice,PortSens,InstSens] = pricePortfolio(f1)
PortPrice = 224.0834
InstPrice = 2×1
114.0085
110.0749
PortSens=1×2 table
Price DV01
______ ________
224.08 0.084139
InstSens=2×2 table
Price DV01
______ ________
fixed_bond1 114.01 0.04251
fixed_bond2 110.07 0.041629
Use finportfolio to create an empty portfolio and then use addInstrument to add multiple instruments to the portfolio.
Create FixedBond Instrument Objects
Use fininstrument to create two FixedBond instrument objects each with two instruments.
FixB1 = fininstrument("FixedBond", 'Maturity',datetime([2022,9,15 ; 2022,10,15]),'CouponRate',0.045,'Name',"fixed_bond1")
FixB1=2×1 FixedBond array with properties:
CouponRate
Period
Basis
EndMonthRule
Principal
DaycountAdjustedCashFlow
BusinessDayConvention
Holidays
IssueDate
FirstCouponDate
LastCouponDate
StartDate
Maturity
Name
FixB2 = fininstrument("FixedBond", 'Maturity',datetime([2022,11,15 ; 2022,12,15]),'CouponRate',0.035,'Name',"fixed_bond2")
FixB2=2×1 FixedBond array with properties:
CouponRate
Period
Basis
EndMonthRule
Principal
DaycountAdjustedCashFlow
BusinessDayConvention
Holidays
IssueDate
FirstCouponDate
LastCouponDate
StartDate
Maturity
Name
Create ratecurve Object
Create a ratecurve object using ratecurve.
Settle = datetime(2020,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)
myRC =
ratecurve with properties:
Type: "zero"
Compounding: -1
Basis: 0
Dates: [10×1 datetime]
Rates: [10×1 double]
Settle: 15-Sep-2020
InterpMethod: "linear"
ShortExtrapMethod: "next"
LongExtrapMethod: "previous"
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.
DiscountPricer = finpricer("Discount", 'DiscountCurve',myRC)
DiscountPricer =
Discount with properties:
DiscountCurve: [1×1 ratecurve]
Add Instruments to finportfolio Object
Create an empty finportfolio object using finportfolio and then use addInstrument to put the FixedBond instruments into the portfolio.
f1 = finportfolio; f1 = addInstrument(f1,FixB1(1))
f1 =
finportfolio with properties:
Instruments: [1×1 fininstrument.FixedBond]
Pricers: [0×1 finpricer.FinPricer]
PricerIndex: NaN
Quantity: 1
f1 = addInstrument(f1,FixB1(2))
f1 =
finportfolio with properties:
Instruments: [2×1 fininstrument.FixedBond]
Pricers: [0×1 finpricer.FinPricer]
PricerIndex: [2×1 double]
Quantity: [2×1 double]
f1 = addInstrument(f1,FixB2(1))
f1 =
finportfolio with properties:
Instruments: [3×1 fininstrument.FixedBond]
Pricers: [0×1 finpricer.FinPricer]
PricerIndex: [3×1 double]
Quantity: [3×1 double]
f1 = addInstrument(f1,FixB2(2))
f1 =
finportfolio with properties:
Instruments: [4×1 fininstrument.FixedBond]
Pricers: [0×1 finpricer.FinPricer]
PricerIndex: [4×1 double]
Quantity: [4×1 double]
Set Pricer for Portfolio
Use setPricer to set the pricer for the portfolio and then use pricePortfolio to calculate the prices and sensitivities for the instruments in the portfolio.
f1 = setPricer(f1,DiscountPricer,[1,2,3,4])
f1 =
finportfolio with properties:
Instruments: [4×1 fininstrument.FixedBond]
Pricers: [1×1 finpricer.Discount]
PricerIndex: [4×1 double]
Quantity: [4×1 double]
[PortPrice,InstPrice,PortSens,InstSens] = pricePortfolio(f1)
PortPrice = 428.2788
InstPrice = 4×1
107.7226
108.0156
106.1642
106.3765
PortSens=1×2 table
Price DV01
______ ________
428.28 0.088272
InstSens=4×2 table
Price DV01
______ ________
fixed_bond1 107.72 0.020871
fixed_bond1_1 108.02 0.021761
fixed_bond2 106.16 0.022387
fixed_bond2_1 106.38 0.023253
Input Arguments
finportfolio object, specified as a scalar finportfolio object.
Data Types: object
Instrument object to add to portfolio, specified as a scalar instrument object that
is previously created using fininstrument.
Note
If the instrument object for inInst is a vector of
instruments, you must use addInstrument to add each instrument
separately.
Data Types: object
Pricer object associated with an added instrument object, specified as a scalar
pricer object or an array of pricer objects that are previously created using finpricer.
Data Types: object
Number of instruments, specified as a scalar numeric. Use a positive value for a long position and a negative value for a short position.
Data Types: double
Output Arguments
Updated finportfolio, returned as a finportfolio object.
Version History
Introduced in R2020a
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Website auswählen
Wählen Sie eine Website aus, um übersetzte Inhalte (sofern verfügbar) sowie lokale Veranstaltungen und Angebote anzuzeigen. Auf der Grundlage Ihres Standorts empfehlen wir Ihnen die folgende Auswahl: .
Sie können auch eine Website aus der folgenden Liste auswählen:
So erhalten Sie die bestmögliche Leistung auf der Website
Wählen Sie für die bestmögliche Website-Leistung die Website für China (auf Chinesisch oder Englisch). Andere landesspezifische Websites von MathWorks sind für Besuche von Ihrem Standort aus nicht optimiert.
Amerika
- América Latina (Español)
- Canada (English)
- United States (English)
Europa
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)