Using risk models is simple!
You simply pass instantiated risk model instances into your desired investment strategy:
import investos as inv
from investos.portfolio.risk_model import *
risk_model = FactorRisk(
factor_covariance=df_factor_covar,
factor_loadings=df_loadings,
idiosyncratic_variance=df_idio,
exclude_assets=["cash"]
)
strategy = inv.portfolio.strategy.SPO(
actual_returns=df_actual_returns,
...
risk_model=risk_model,
)
and that's it!
Note: some simple investment strategies do not support risk models. If you pass a risk model to one of these strategies, it will have no effect.
All risk models take the following optional arguments:
exclude_assets
: [str]include_assets
: [str]
gamma
: float = 1
InvestOS provides the following risk models:
FactorRisk is a multi-factor risk model.
To instantiate FactorRisk you will need to set the following arguments:
factor_covariance
: pd.DataFrame
factor_loadings
: pd.DataFrame
idiosyncratic_variance
: pd.DataFrame | pd.Series
StatFactorRisk creates a PCA-factor based risk model from actual_returns
. To use this model, there must be more periods in actual_returns
than assets in your investment strategy.
To instantiate StatFactorRisk you will need to set the following arguments:
actual_returns
: pd.DataFrameYou may optionally set the following arguments:
n_factors
: integer = 5start_date
: datetime = actual_returns.index[0]end_date
: datetime = actual_returns.index[-1]recalc_each_i_periods
: integer|boolean = Falsetimedelta
: pd.Timedelta = pd.Timedelta("730 days")
Want to explore an end-to-end example? Check out Single Period Optimization.
Want to learn more about what guides are coming next? Check out Guides Under Development.