gs-quant icon indicating copy to clipboard operation
gs-quant copied to clipboard

Portfolios

Open DerekTiggelaar opened this issue 6 years ago • 4 comments

Describe the problem. What is the best way to represent a Portfolio that can consists of so many types of investments?

Describe the solution you'd like I would like to leverage the concept of an Instrument to describe a Position in a gs-quant Portfolio. An Instrument is an object with industry-standard required fields that all-together describe a unique investment. Using instruments to represent positions in a portfolio will allow a gs-quant user to quickly understand how to add investments of any type to their portfolio and calculate analytics such as pricing or risk in a way that is agnostic to the portfolio's contents.

Here are a few code examples:

Example 1:

from gs_quant.session import *
from gs_quant.portfolio import GsPositionSet, GsPortfolio
from gs_quant.instrument import IRSwaption, EqOption
import matplotlib.pyplot as plt

with GsSession.get(Environment.PROD):

    positions = GsPositionSet([
        IRSwaption(PayReceive.Receive, '5y', 'USD', expirationDate='13m', strike='atm+40', notionalAmount=1e8),
        EqOption('SPX', date(2020, 12, 31), 2800, OptionType.Call, OptionStyle.European)
    ], date(2019, 05, 10))

    positions.calculate_prices('USD')

    portfolio = GsPortfolio('Derek's Example Portfolio', 'USD', [positions])
    portfolio.create_performance_report()
    portfolio.schedule_reports()
    
    performance = portfolio.get_normalized_performance()
    plt.plot(performance, label='Portfolio Performance')
    plt.show()

Example 2:

from gs_quant.session import *
from gs_quant.portfolio import GsPositionSet
from gs_quant.index import GsBasket
from gs_quant.instrument import Equity

with GsSession.get(Environment.PROD):

    positions = GsPositionSet([
        Equity('GS', 24222, AssetIdentifier.TICKER),
        Equity('AAPL', 23984, AssetIdentifier.TICKER)
    ], date(2019, 05, 10))

    positions.calculate_prices('USD')
    positions.calculate_liquidity('APEX', '.10') # 10% participation rate

    SPX = SecurityMaster.get_asset("SPX", AssetIdentifier.TICKER, asset_type=AssetType.INDEX)
    hedge = positions.hedge('Replicate Performance', universe=SPX.getUnderlyingAssetIds())

    hedge_positions = GsPositionSet(hedge.get_constituents())
    hedge_positions.calculate_liquidity('APEX', '.10') # 10% participation rate

    hedge_positions = [p for p in hedge_positions if p['adv22DayPct'] < 5.0]
    hedge_positions = [p for p in hedge_positions if p['transactionCostBps'] < 14.50]

    hedge_basket = GsBasket(
        "GSCBMARQ",
        "Basket From Hedge",
        hedge_positions,
        PublishParameters(False, False, False),
        100
    )

    hedge_basket.create()

Are you willing to contribute Yes

Additional context Let's build context from the ground up...

  • Position - A unique notional investment at a given point-in-time.
  • PositionSet - A set of Positions you're invested at a given point-in-time.
  • Portfolio - A set of PositionSets that you've invested in at different points in time.

DerekTiggelaar avatar May 10 '19 20:05 DerekTiggelaar

Cool stuff. I think we can drop the 'Gs' from the GsPositionSet? Definition doesn't have to be GS specific I think. Same for GsBasket.

francisg77 avatar May 10 '19 21:05 francisg77

some questions / comments on this:

  • Agree this should just be Portfolio rather than GsPortfolio
  • Equity should use the Stock class in gs_quant. we should also determine how we handle securities (e.g. is the stock position settled?
  • What's the third param to the portfolio? Looks like a list of PositionSets, but should this be something more structured? e.g. what if i add two PositionSets for the same date?
  • Perhaps we should line up the functions with instruments? e.g. price(), dollar_price(), calculate( ..metric ..)
  • Stylistically, should we allow pricing operations on PositionSet and Portfolio? interesting question. At the moment your replication flow implies that I compute historical performance for a fixed set of positions backwards through time. easier for stocks than other instruments which have complex aging
  • Not sure the report stuff is entirely intuitive at this stage. let's consult a couple more people

@nick-young-gs please also take a look!

andrewphillipsn avatar May 10 '19 23:05 andrewphillipsn

  • I agree with both of you. I'll drop the GS from GsPortfolio and GsPositionSet.
  • I was thinking that a Portfolio could only have one PositionSet per date. What would be the use-case for multiple PositionSets on a given date? It seems this would be more-so for managing a "Book" that encompasses multiple Portfolios. Implementing the concept of a Book could allow users to calculate things such as combined overall performance for a set of different Portfolios.
  • Pricing derivative positions in a portfolio (multiple dates in the past) is an interesting question that i'll revert to @nick-young-gs. But i'd assume it would be as straightforward as pricing those derivatives as of the positionDate it falls on.
  • Calculating historical performance for a spot PositionSet with derivatives backwards through time is very unclear to me. I'll also revert to @nick-young-gs on this.

DerekTiggelaar avatar May 14 '19 17:05 DerekTiggelaar

  • mutliple positionsets per date would be for different position fixings / snaps. e.g. open, close, etc
  • can you touch base with @nick-young-gs to close out some of the open questions? thanks

andrewphillipsn avatar Aug 09 '19 14:08 andrewphillipsn