- Calculate the portfolio returns using the optimal weights obtained from the portfolio optimization.
- Calculate the maximum drawdown.
- Calculate the Sortino ratio.
- Calculate the ulcer index.
How to calculate risk indicator for a portfolio as maximum drawdown, sortino ratio and ulcer index?
6 次查看(过去 30 天)
显示 更早的评论
Based on the following code, is it possible to have the correct formula to calculate the maximum drawdown, the sortino ratio and the ulcer index?
clear all;
clc;
NumPorts=2000;
% Set Up the Data
open ("MatlabBOGLE.xlsx");
t = readtable("MatlabBOGLE.xlsx");
symbol = t.Properties.VariableNames(2:end);
dailyreturn= tick2ret(t(:,2:end));
dailyreturn2 = table2array(dailyreturn);
% Create a Portfolio Object (with the risk-free rate)
RiskFreeRate=0.00/252;
p = Portfolio("AssetList",symbol,"RiskFreeRate",RiskFreeRate);
x0 =[0.1,0.1,0.3,0.5,0,0];
p = setInitPort(p,x0);
p = estimateAssetMoments(p,dailyreturn);
[initialrisk,initialreturn] = estimatePortMoments(p,p.InitPort);
display(initialrisk); %"Rischio" Iniziale del lazy Portfolio con le %di allocazioni inalterate
display(initialreturn); %Rendimento Iniziale del lazy Portfolio con le %di allocazioni inalterate
clf;
portfolioexamples_plot('Asset Risks and Returns', ...
{'scatter', initialrisk,initialreturn, {'StartPort'}}, ...
{'scatter', sqrt(diag(p.AssetCovar)), p.AssetMean, p.AssetList, '.r'});
% Set Up a Portfolio Optimization Problem
p=setDefaultConstraints(p);
pwgt = estimateFrontier(p,NumPorts);
[portrisk,portret] = estimatePortMoments (p,pwgt);
figure
portfolioexamples_plot('Efficient Frontier', ...
{'line', portrisk, portret}, ...
{'scatter', initialrisk, initialreturn, {'StartPort'}}, ...
{'scatter', sqrt(diag(p.AssetCovar)), p.AssetMean, p.AssetList, '.r'});
% Maximize the Sharpe Ratio
p = setInitPort(p, x0);
swgt = estimateMaxSharpeRatio(p);
[srsk,sret] = estimatePortMoments(p,swgt);
display(swgt);
display(srsk);
display(sret);
figure
portfolioexamples_plot('Efficient Frontier with Maximum Sharpe Ratio Portfolio', ...
{'line', portrisk, portret}, ...
{'scatter', srsk, sret, {'Sharpe'}}, ...
{'scatter', initialrisk,initialreturn, {'StartPort'}}, ...
{'scatter', sqrt(diag(p.AssetCovar)), p.AssetMean, p.AssetList, '.r'});
0 个评论
采纳的回答
LeoAiE
2023-4-23
In your current code, you've implemented a portfolio optimization strategy using the Sharpe ratio. To calculate the maximum drawdown, Sortino ratio, and ulcer index, you can
% Your existing code
% ...
% Step 1: Calculate portfolio returns using the optimal weights (swgt)
portfolio_returns = dailyreturn2 * swgt;
% Step 2: Calculate maximum drawdown
cumulative_returns = cumprod(1 + portfolio_returns) - 1;
cumulative_max = cummax(cumulative_returns);
drawdowns = (cumulative_max - cumulative_returns) ./ (cumulative_max + 1);
max_drawdown = max(drawdowns);
% Step 3: Calculate Sortino ratio
target_return = 0; % Define target return (usually 0 for Sortino ratio)
excess_returns = portfolio_returns - RiskFreeRate;
downside_returns = excess_returns;
downside_returns(downside_returns > target_return) = 0;
sortino_ratio = (mean(excess_returns) - target_return) / sqrt(mean(downside_returns .^ 2));
% Step 4: Calculate Ulcer index
ulcer_index = sqrt(mean(drawdowns .^ 2));
% Display the results
display(max_drawdown);
display(sortino_ratio);
display(ulcer_index);
4 个评论
LeoAiE
2023-5-7
Volatility (annualized): Since you already have daily returns, you can calculate the annualized volatility using the standard deviation of daily returns.
volatility = std(portfolio_returns) * sqrt(252);
Upside Potential Ratio: It measures the expected value of returns above a target return.
upside_returns = excess_returns;
upside_returns(upside_returns < target_return) = 0;
upside_potential_ratio = mean(upside_returns) / sqrt(mean(downside_returns .^ 2));
Sterling Ratio: It measures the reward-to-pain ratio.
sterling_ratio = (mean(portfolio_returns) - RiskFreeRate) / (max_drawdown + 0.1); % Adding a constant to the denominator
Omega Ratio: It measures the ratio of the probability weighted gains to losses.
gain_returns = excess_returns;
gain_returns(gain_returns < target_return) = 0;
loss_returns = excess_returns;
loss_returns(loss_returns >= target_return) = 0;
omega_ratio = sum(gain_returns) / abs(sum(loss_returns));
MAR (Managed Account Reports) Ratio: It is similar to the Calmar ratio.
mar_ratio = (mean(portfolio_returns) - RiskFreeRate) / max_drawdown;
To plot the graph with the x-axis as dates, you can use the following code:
dates = t.Date(2:end); % Assuming you have dates in the first column, skipping the header
figure;
plot(dates, cumulative_returns, 'b-', 'LineWidth', 1.5);
hold on;
plot(dates, cumulative_max, 'r--', 'LineWidth', 1.5);
hold off;
legend('Cumulative Returns', 'Cumulative Maximum');
xlabel('Time');
ylabel('Cumulative Returns');
title('Drawdown Graph');
grid on;
datetick('x', 'yyyy-mm-dd', 'keepticks'); % Format the x-axis dates
更多回答(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!