Portfolio optimization -- estimateCu​stomObject​ivePortfol​io equivalent in R2021b?

18 次查看(过去 30 天)
Hello, Matlab community. I am working on a portfolio optimization exercise, and I'm looking for a way to incorporate a user-defined objective function in the usual Portfolio object workflow. The "estimateCustomObjectivePortfolio" function seems to be exactly what I need, but unfortunately it was introduced in R2022b. I am using a corporate R2021b Matlab license, so my IT department may not let me just upgrade to get the new functionality (I'm checking on that as well).
Assuming I have to live with R2021b for now, I'll give you an example of what I'm trying to accomplish. Consider a fixed-income-only universe of asset classes, and durations for each:
- IG corporate duration = 7 years
- high yield corporate duration = 3 years
- treasury duration = 10 years
- etc.
In the portfolio optimization, I'd like to be able to have a stated duration target for the resulting portfolio. But, the duration of any hypothetical portfolio depends on the portfolio weights the optimizer is considering in any given iteration, and I don't see a way (in my version of Matlab) to state that duration target as a constraint or objective.
Thanks in advance for any thoughts you may have.

采纳的回答

MULI
MULI 2024-6-18
Hi Jeremy,
I understand that you need to perform portfolio optimization without using "estimateCustomObjectivePortfolio" function. This can be achieved using `fmincon` function where,
  • The Objective Function is defined inline within the fmincon call as, which minimizes the portfolio variance.
  • The Nonlinear Constraint is also defined inline within the fmincon call which ensures that the difference between the portfolio's duration and the target duration is zero (an equality constraint).
Below is the MATLAB Code that helps in achieving the requirement:
% Example Data
numAssets = 3; % Adjust based on your actual number of assets
covMatrix = rand(numAssets)*0.01; % Replace with your actual covariance matrix
covMatrix = covMatrix + covMatrix' - diag(diag(covMatrix)); % Making symmetric
assetDurations = [7; 3; 10]; % Example durations for each asset
targetDuration = 5; % Target portfolio duration
% Initial guess for the weights
initialWeights = ones(numAssets, 1) / numAssets;
% Bounds for the weights
lb = zeros(numAssets, 1); % Lower bound of 0
ub = ones(numAssets, 1); % Upper bound of 1
% Equality constraint for the sum of weights
Aeq = ones(1, numAssets);
beq = 1;
% Optimization options
options = optimoptions('fmincon', 'Display', 'iter', 'Algorithm', 'sqp');
% Solve the optimization problem
[optimalWeights, optimalValue] = fmincon(@(weights) weights' * covMatrix * weights, ...
initialWeights, [], [], Aeq, beq, lb, ub, ...
@(weights) deal([], sum(weights .* assetDurations) - targetDuration), options);
% Display the optimal weights
disp('Optimal Weights:');
disp(optimalWeights);
You may refer to this documentation link for more information related to fmincon function.
Hope this answers your query!
  1 个评论
jeremy gogos
jeremy gogos 2024-6-26,19:58
Muli, thank you so much for the guidance! Your illustration of how to run this problem through the optimizer was exactly what I needed.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Portfolio Optimization and Asset Allocation 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by