cvxgrp/cvxportfolio

Pulling out F parameter in FactorModelCovariance

Closed this issue · 0 comments

Discussed in https://github.com/cvxgrp/cvxportfolio/discussions/96

Originally posted by bast0320 June 16, 2023
Hi - and thanks for a great package.
I have started my project from the hello_world.py from the repo. I have made small changes to the objective function and constraints. Attached below.

Since I'm letting the model estimate my factor covariance matrix, F, I would like to see what this estimate is. Since I'm not sure this estimation gets passed all the way through to the result variable, how is a good way of doing this i.e. a good way of extracting the factor matrix, F, and idiosyncratic risk, d.

Thank you!

import cvxportfolio as cvx
import matplotlib.pyplot as plt
import numpy as np

gamma = 3       # risk aversion parameter (Chapter 4.2)
# kappa = 0.05    # covariance forecast error risk parameter (Chapter 4.3)
objective = cvx.ReturnsForecast() - gamma *cvx.FactorModelCovariance(num_factors=3)  - cvx.TransactionCost() 
constraints = [cvx.LeverageLimit(1), cvx.LongOnly()]

policy = cvx.SinglePeriodOptimization(objective, constraints, planning_horizon=1)

simulator = cvx.MarketSimulator(['AAPL', 'AMZN', 'TSLA', 'GM', 'CVX', 'NKE', 'GME'])

result = simulator.backtest(policy, start_time='2020-01-01')
```</div>