- 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).
Portfolio optimization -- estimateCustomObjectivePortfolio equivalent in R2021b?
3 ビュー (過去 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.
0 件のコメント
採用された回答
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,
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!
その他の回答 (0 件)
参考
カテゴリ
Help Center および File 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!