Covariance
qcs.get_covariance(context, xtickers, ytickers=None, currency=None, unit='TKR')
Get the covariance matrix and levels of the allocation snapshot.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
context
|
Context
|
The context in which the covariance matrix is calculated. |
required |
xtickers
|
List[str]
|
The tickers for the rows of the covariance matrix. |
required |
ytickers
|
List[str] | None = None
|
The tickers for the columns of the covariance matrix. If not provided, defaults to xtickers. |
None
|
currency
|
CurrencyType | None
|
The currency in which tickers are computed.
If |
None
|
unit
|
Literal["TKR", "LVL", "MKT", "MAV"] = "TKR"
|
|
'TKR'
|
Returns:
| Type | Description |
|---|---|
CovarianceOutput
|
An instance of CovarianceOutput class with the following properties: - "covariance": A DataFrame representing the covariance matrix. - "meta_info": A DataFrame representing the meta information of the covariance matrix. - "context": A dict representing the context of the covariance risk computation. |
Examples:
>>> context = Context(date=date.today(), horizon="1d", local_db=my_local_db)
>>> covariance_output = qcs.get_covariance(
... context, unit="TKR", currency="USD", xtickers=["EUR", "GBP"]
... )
>>> print(covariance_output.covariance)
EUR GBP
EUR 0.000553 0.000672
GBP 0.000672 0.001071
>>> print(covariance_output.meta_info)
label level currency variance
EUR EUR to USD FX rate 1.0 USD 0.000553
GBP GBP to USD FX rate 1.0 USD 0.001071
>>> print(covariance_output.context)
{'date': '2023-10-19', 'horizon': '1d', 'annualization_factor': 15.8745079}