The Portfolio class groups instruments for pricing, resolution, and analysis as a single unit. Portfolios can be created from lists or dictionaries (where keys are instrument names) and can be nested.
Portfolio Operations
- Creation: Pass a list of instruments or a dictionary of
{name: instrument}. - Nesting: A
Portfolio can contain other Portfolio objects. - Access: Access instruments by index (
portfolio[0]) or by name (portfolio['name']). - Aggregation:
portfolio.all_instruments returns all instruments across all nested portfolios. - Resolution:
portfolio.resolve() resolves all instruments within the portfolio in place. - Pricing:
portfolio.calc(measure) calculates risk measures (e.g., DollarPrice, IRDelta) for the entire portfolio.
from gs_quant.instrument import IRSwap, IRSwaption
from gs_quant.markets.portfolio import Portfolio
from gs_quant.risk import DollarPrice, IRDelta
# Creating from a list
swap = IRSwap('Pay', '10y', 'USD', name='USD 10y Payer')
swaption = IRSwaption('Receive', '10y', 'EUR', expiration_date='1y', name='EUR 1y10y Receiver')
portfolio = Portfolio([swap, swaption], name='My Portfolio')
# Creating from a dictionary
portfolio = Portfolio(
{
'USD 10y Payer': IRSwap('Pay', '10y', 'USD'),
'EUR 5y Receiver': IRSwap('Receive', '5y', 'EUR'),
}
)
# Nesting portfolios
book_a = Portfolio([IRSwap('Pay', '5y', 'USD')], name='Book A')
book_b = Portfolio([IRSwap('Pay', '5y', 'EUR')], name='Book B')
master = Portfolio([book_a, book_b], name='Master Book')
# Operations
master.resolve() # resolves all instruments in place
prices = master.calc(DollarPrice) # single risk measure
results = master.calc([DollarPrice, IRDelta]) # multiple risk measures