FactorRiskReport¶
- class FactorRiskReport(risk_model_id=None, fx_hedged=True, benchmark_id=None, report_id=None, name=None, position_source_id=None, position_source_type=None, report_type=None, earliest_start_date=None, latest_end_date=None, latest_execution_time=None, status=ReportStatus.new, percentage_complete=None, **kwargs)[source]¶
Historical analyses on both the risk and attribution of a portfolio or asset to various factors determined by the specified risk model
Methods
- __init__(risk_model_id=None, fx_hedged=True, benchmark_id=None, report_id=None, name=None, position_source_id=None, position_source_type=None, report_type=None, earliest_start_date=None, latest_end_date=None, latest_execution_time=None, status=ReportStatus.new, percentage_complete=None, **kwargs)[source]¶
Historical analyses on both the risk and attribution of a portfolio or asset to various factors determined by the specified risk model
- Parameters:
risk_model_id (
Optional
[str
]) – risk model IDfx_hedged (
bool
) – if position source is FX hedgedbenchmark_id (
Optional
[str
]) – optional benchmark asset ID to include in resultsreport_id (
Optional
[str
]) – Marquee report IDname (
Optional
[str
]) – report nameposition_source_id (
Optional
[str
]) – position source IDposition_source_type (
Union
[str
,PositionSourceType
,None
]) – position source (i.e. ‘Portfolio’, ‘Asset’, or ‘Hedge’)report_type (
Union
[str
,ReportType
,None
]) – report type (i.e. ‘Asset Factor Risk’ or ‘Portfolio Factor Risk’)earliest_start_date (
Optional
[date
]) – start date of reportlatest_end_date (
Optional
[date
]) – end date of reportlatest_execution_time (
Optional
[datetime
]) – date of the latest executionstatus (
Union
[str
,ReportStatus
]) – status of of report (i.e. ‘ready’, ‘executing’, or ‘done’)percentage_complete (
Optional
[float
]) – percent of the report that is complete
Examples
>>> risk_report = FactorRiskReport( >>> risk_model_id='RISKMODELID', >>> fx_hedged=True, >>> benchmark_id=benchmark.get_marquee_id(), >>> position_source_id='PORTFOLIOID', >>> position_source_type=PositionSourceType.Portfolio >>> )
- delete()¶
Delete a report from Marquee
- classmethod get(report_id, **kwargs)[source]¶
Get a factor risk report from the unique report identifier
- Parameters:
report_id (
str
) – Marquee report ID- Returns:
returns a FactorRiskReport object that correlates to the Marquee report
- get_annual_risk(factor_names=None, start_date=None, end_date=None, currency=None)[source]¶
Get historical annual risk
- Parameters:
factor_names (
Optional
[List
[str
]]) – optional list of factor names; must be from the following: “Factor”, “Specific”, “Total”start_date (
Optional
[date
]) – start dateend_date (
Optional
[date
]) – end datecurrency (
Optional
[Currency
]) – currency
- Return type:
DataFrame
- Returns:
a Pandas DataFrame with the results
- get_benchmark_id()[source]¶
- Return type:
str
- Returns:
the unique Marquee identifier of the benchmark associated with the factor risk report
- get_daily_risk(factor_names=None, start_date=None, end_date=None, currency=None)[source]¶
Get historical daily risk
- Parameters:
factor_names (
Optional
[List
[str
]]) – optional list of factor names; must be from the following: “Factor”, “Specific”, “Total”start_date (
Optional
[date
]) – start dateend_date (
Optional
[date
]) – end datecurrency (
Optional
[Currency
]) – currency
- Return type:
DataFrame
- Returns:
a Pandas DataFrame with the results
- get_ex_ante_var(confidence_interval=95.0, start_date=None, end_date=None, currency=None)[source]¶
Get ex-ante Value at Risk as defined by the risk model
- Parameters:
confidence_interval (
float
) – the VaR confidence interval as a percentstart_date (
Optional
[date
]) – start dateend_date (
Optional
[date
]) – end datecurrency (
Optional
[Currency
]) – currency
- Return type:
DataFrame
- Returns:
a Pandas DataFrame with the results
- get_factor_exposure(mode=FactorRiskResultsMode.Portfolio, factor_names=None, factor_categories=None, start_date=None, end_date=None, currency=None, unit=FactorRiskUnit.Notional)[source]¶
Get historical factor exposure
- Parameters:
mode (
FactorRiskResultsMode
) – results mode; defaults to the portfolio levelfactor_names (
Optional
[List
[str
]]) – optional list of factor names; defaults to all of themfactor_categories (
Optional
[List
[str
]]) – optional list of factor categories; defaults to all of themstart_date (
Optional
[date
]) – start dateend_date (
Optional
[date
]) – end datecurrency (
Optional
[Currency
]) – currency
- Param:
unit: return the results in terms of notional or percent (defaults to notional)
- Return type:
DataFrame
- Returns:
a Pandas DataFrame with the results
- get_factor_pnl(mode=FactorRiskResultsMode.Portfolio, factor_names=None, factor_categories=None, start_date=None, end_date=None, currency=None, unit=FactorRiskUnit.Notional)[source]¶
Get historical factor PnL
- Parameters:
mode (
FactorRiskResultsMode
) – results mode; defaults to the portfolio levelfactor_names (
Optional
[List
[str
]]) – optional list of factor names; defaults to all of themfactor_categories (
Optional
[List
[str
]]) – optional list of factor categories; defaults to all of themstart_date (
Optional
[date
]) – start dateend_date (
Optional
[date
]) – end datecurrency (
Optional
[Currency
]) – currency
- Param:
unit: return the results in terms of notional or percent (defaults to notional)
- Return type:
DataFrame
- Returns:
a Pandas DataFrame with the results
- get_factor_proportion_of_risk(factor_names=None, factor_categories=None, start_date=None, end_date=None, currency=None)[source]¶
Get historical factor proportion of risk
- Parameters:
factor_names (
Optional
[List
[str
]]) – optional list of factor names; defaults to all of themfactor_categories (
Optional
[List
[str
]]) – optional list of factor categories; defaults to all of themstart_date (
Optional
[date
]) – start dateend_date (
Optional
[date
]) – end datecurrency (
Optional
[Currency
]) – currency
- Return type:
DataFrame
- Returns:
a Pandas DataFrame with the results
- get_most_recent_job()¶
Retrieve the most current report job
- get_results(mode=FactorRiskResultsMode.Portfolio, factors=None, factor_categories=None, start_date=None, end_date=None, currency=None, return_format=ReturnFormat.DATA_FRAME, unit=FactorRiskUnit.Notional)[source]¶
Get the raw results associated with the factor risk report
- Parameters:
mode (
FactorRiskResultsMode
) – results mode; defaults to the portfolio levelfactors (
Optional
[List
[str
]]) – optional list of factors; defaults to all of themfactor_categories (
Optional
[List
[str
]]) – optional list of factor categories; defaults to all of themstart_date (
Optional
[date
]) – start dateend_date (
Optional
[date
]) – end datecurrency (
Optional
[Currency
]) – currencyreturn_format (
ReturnFormat
) – return format; defaults to a Pandas DataFrame, but can be manually
set to ReturnFormat.JSON :param: unit: return the results in terms of notional or percent (defaults to notional) :rtype:
Union
[Dict
,DataFrame
] :return: risk report resultsExamples
>>> factor_and_total_results = risk_report.get_results( >>> factors=['Factor', 'Specific'], >>> start_date=dt.date(2022, 1, 1), >>> end_date=dt.date(2021, 1, 1) >>> ) >>> print(factor_and_total_results)
- get_risk_model_id()[source]¶
- Return type:
str
- Returns:
the ID of the risk model associated with the factor risk report
- get_table(mode, factors=None, factor_categories=None, date=None, start_date=None, end_date=None, unit=None, currency=None, order_by_column=None, order_type=None, return_format=ReturnFormat.DATA_FRAME)[source]¶
Get the results associated with the factor risk report formatted for the asset level table on the interface
- Parameters:
mode (
FactorRiskTableMode
) – tables modefactors (
Optional
[List
[str
]]) – optional list of factors to filter by; defaults to allfactor_categories (
Optional
[List
[str
]]) – optional list of factor categories to filter by; defaults to alldate (
Optional
[date
]) – date for modes requiring snapshot data (defaults to the latest available date)start_date (
Optional
[date
]) – start date for modes requiring date range (defaults to 1 month before the end date)end_date (
Optional
[date
]) – end date for modes requiring date range (defaults to the latest available date)unit (
Optional
[FactorRiskUnit
]) – return the results in terms of notional or percent (defaults to notional)currency (
Optional
[Currency
]) – currencyorder_by_column (
Optional
[str
]) – column to order the rows by (defaults to name)order_type (
Optional
[OrderType
]) – order ascending or descending (defaults to ascending)
- Return type:
Union
[Dict
,DataFrame
]- Returns:
risk report table at asset level
Examples
>>> pnl_table = risk_report.get_table( >>> mode=FactorRiskTableMode.Pnl, >>> start_date=risk_report.earliest_start_date, >>> end_date=risk_report.latest_end_date >>> ) >>> display(pd.DataFrame(pnl_table))
- get_view(mode, factor=None, factor_category=None, start_date=None, end_date=None, currency=None, unit=FactorRiskUnit.Notional)[source]¶
Get the results associated with the factor risk report as seen on the Marquee user interface
- Parameters:
mode (
FactorRiskViewsMode
) – views modefactor (
Optional
[str
]) – optional factor namefactor_category (
Optional
[str
]) – optional factor categorystart_date (
Optional
[date
]) – start dateend_date (
Optional
[date
]) – end datecurrency (
Optional
[Currency
]) – currency
- Param:
unit: return the results in terms of notional or percent (defaults to notional)
- Return type:
Dict
- Returns:
risk report results
Examples
>>> category_table = risk_report.get_view( >>> mode=FactorRiskViewsMode.Risk, >>> start_date=risk_report.latest_end_date, >>> end_date=risk_report.latest_end_date, >>> unit=FactorRiskUnit.Notional >>> ).get('factorCategoriesTable') >>> category_df = pd.DataFrame(category_table).filter(items=[ >>> 'name', >>> 'proportionOfRisk', >>> 'marginalContributionToRiskPercent', >>> 'relativeMarginalContributionToRisk', >>> 'exposure', >>> 'avgProportionOfRisk' >>> ]) >>> display(category_df)
- run(start_date=None, end_date=None, backcast=False, is_async=True)¶
Run a report with the given date range
- Parameters:
start_date (
Optional
[date
]) – start date (optional)end_date (
Optional
[date
]) – end date (optional)backcast (
bool
) – set to true if the report should be backcasted; defaults to falseis_async (
bool
) – return immediately (true) or wait for results (false); defaults to true
- save()¶
Create a report in Marquee if it doesn’t exist. Update the report if it does.
- schedule(start_date=None, end_date=None, backcast=None)¶
Schedule a report with the given date range
- Parameters:
start_date (
Optional
[date
]) – start date (optional)end_date (
Optional
[date
]) – end date (optional)backcast (
Optional
[bool
]) – set to true if the report should be backcasted
- set_position_source(entity_id)¶
Set position source type and position source ID