When you create and upload positions to a portfolio in Marquee, GS Quant makes it easy to pull historical performance data with just a few lines of code.
Before you begin this tutorial, you must have a portfolio in Marquee with positions and reports that have already been scheduled and completed. If that's not the case, please navigate to our tutorial on creating a new portfolio and/or updating positions and running reports.
Your application also needs to have the run_analytics scope. If it doesn't, please request it on your My Applications Page. If you have any other questions please reach out to the Marquee sales team.
First you will import the necessary modules and add your client id and client secret.
from gs_quant.markets.portfolio_manager import PortfolioManager
from gs_quant.markets.report import PerformanceReport
from gs_quant.session import GsSession, Environment
client = 'ENTER CLIENT ID'
secret = 'ENTER CLIENT SECRET'
GsSession.use(Environment.PROD, client_id=client, client_secret=secret, scopes=('run_analytics',))
The PortfolioManager
class allows for easy retrieval and scheduling of portfolio reports. Simply running:
all_reports = PortfolioManager('ENTER PORTFOLIO ID').get_reports()
will return a list of Report
objects that represent the reports associated with the portfolio.
The GS Quant Report
class is inherited by report subclasses, like FactorRiskReport
and PerformanceReport
, each of which corresponds to a type of Marquee report. Each subclass then has additional functions specific to its report type. In this case, we'd like to find the PerformanceReport
associated with this portfolio, and leverage its functions to retrieve data. In this example, we will pull all historical PnL, gross exposure, and net exposure available.
performance_report = list(filter(lambda report: isinstance(report, PerformanceReport), all_reports))[0]
pnl = performance_report.get_pnl()
gross_exposure = performance_report.get_gross_exposure()
net_exposure = performance_report.get_net_exposure()
print(f'PnL: \n{pnl.__str__()}')
print(f'Gross Exposure: \n{gross_exposure.__str__()}')
print(f'Net Exposure: \n{net_exposure.__str__()}')
If you would like to pull multiple performance measures in one dataframe, you can use the get_many_measures
function:
aggregated_performance_results = performance_report.get_many_measures(measures=['pnl', 'grossExposure', 'netExposure'])
print(aggregated_performance_results)
If you would only like to pull data for a specific date range, all the functions used above also take in function parameters start_date
and end_date
, in which you can pass datetime.date
objects to specify the range you would like.
Other questions? Reach out to the Portfolio Analytics team!