【RO】Box uncertainty
技術標籤:# Robust Optimization# matlabbox uncertaintyrobustmatlab
Navigator
- Constructing robust portfolios
- Formulate the robust problem by defining the Box Uncertainty Set
- Reformulate the robust counterpart with Box Uncertainty
- Matlab Code: quadprog
- Matlab Code: fmincon
- References
Constructing robust portfolios
For the portfolio problem with uncertain expected return of stocks, the robust counterpart is written as
min
w
max
u
∈
U
w
′
Σ
w
−
λ
μ
′
w
s
.
t
.
w
′
1
=
1
\min_w\max_{u\in\mathcal{U}} w'\Sigma w-\lambda\mu' w\\ s.t.\quad w'\mathbf{1}=1
wminu∈Umaxw′Σw−λμ′ws.t.w′1=1
where
U
\mathcal{U}
U is the uncertainty set for
u
u
These types of robust problems using optimization tools into the following three steps:
- Formulate a robust optimization problem of robust optimization problem by definiting an uncertainty set.
- Reformulate the robust counterpart into standard convex optimization form.
- Use optimization tools to solve the reformulated robust problem.
Formulate the robust problem by defining the Box Uncertainty Set
The box or interval uncertainty set for the expected return is defined as
{
μ
∣
∣
μ
i
−
μ
^
i
∣
≤
δ
i
,
i
=
1
,
…
,
N
}
\{\mu\mid |\mu_i-\hat{\mu}_i|\leq \delta_i, i=1,\dots, N\}
{μ∣∣μi−μ^i∣≤δi,i=1,…,N}
where
μ
^
∈
R
n
\hat{\mu}\in\mathbb{R}^n
μ^∈Rn is an estimate for the expected return, and the range of the interval is deicided by the values of
δ
∈
R
n
\delta\in\mathbb{R}^n
δ∈Rn. Hence, the robust formulation can be initially written as
min
w
max
μ
∈
{
μ
∣
∣
μ
i
−
μ
^
i
∣
≤
δ
i
}
w
′
Σ
w
−
λ
μ
′
w
s
.
t
.
w
′
1
=
1
\min_w\max_{\mu\in\{\mu\mid|\mu_i-\hat{\mu}_i|\leq \delta_i\}} w'\Sigma w-\lambda \mu'w\\ s.t.\quad w'\mathbf{1}=1
wminμ∈{μ∣∣μi−μ^i∣≤δi}maxw′Σw−λμ′ws.t.w′1=1
Since each element of
δ
\delta
δ controls the expected return of a single stock, its value should be computed individually for each stock. A simple method is to choose the variability
δ
i
\delta_i
δi from the estimate
μ
^
i
\hat{\mu}_i
μ^i by finding the historical maximum distance of return from
μ
^
i
\hat{\mu}_i
μ^i for stock
i
i
i. More commonly, the distribution of returns for a stock from historical returns is modeled, and the confidence interval of the mean decides the interval for the expected return. For example, if the stock returns are assumed to follow a normal distribution or through the central limit theorem by assuming independent and identically distributed samples, the confidence interval for the mean is computed by
(
μ
^
−
z
α
/
2
σ
T
,
μ
^
+
z
α
/
2
σ
T
)
\bigg( \hat{\mu}-\frac{z_{\alpha/2}\sigma}{\sqrt{T}},\hat{\mu}+\frac{z_{\alpha/2}\sigma}{\sqrt{T}} \bigg)
(μ^−T
zα/2σ,μ^+T
zα/2σ)
where
T
T
T is the sample size, and
z
α
/
2
z_{\alpha/2}
zα/2 is the standard normal critical point for representing
1
−
α
1-\alpha
1−α confidence level. The estimated expected return
μ
^
\hat{\mu}
μ^ is also determined with much freedom. The most common approach is to use the arithmetic mean of returns, which also coincides with the use of confidence intervals of the mean for setting the value of
δ
\delta
δ.
Reformulate the robust counterpart with Box Uncertainty
For stock
i
i
i, the range of possible returns based on the uncertainty set of equation is
μ
^
i
−
δ
i
≤
μ
i
≤
μ
^
i
+
δ
i
\hat{\mu}_i-\delta_i\leq \mu_i\leq \hat{\mu}_i+\delta_i
μ^i−δi≤μi≤μ^i+δi
and the expression for the worst return can be further summarized as
μ
^
i
w
i
−
δ
i
∣
w
i
∣
\hat{\mu}_iw_i-\delta_i|w_i|
μ^iwi−δi∣wi∣
Therefore, the robust counterpart is reformulated as
min
w
w
′
Σ
w
−
λ
(
μ
^
′
w
−
δ
′
∣
w
∣
)
s
.
t
.
w
′
1
=
1
\min_w w'\Sigma w-\lambda(\hat{\mu}'w-\delta'|w|)\\ s.t.\quad w'\mathbf{1}=1
wminw′Σw−λ(μ^′w−δ′∣w∣)s.t.w′1=1
So far, we have transformed the min-max
problem into a minimization problem. But some functions in optimization tools limit the use of absolute values in the objective function. Therefore, the explicit use of absolute values needs to be revised. By introducing an auxiliary variable
ψ
∈
R
n
\psi\in\mathbb{R}^n
ψ∈Rn, the problem becomes
min
w
,
ψ
w
′
Σ
w
−
λ
(
μ
^
′
w
−
δ
′
ψ
)
s
.
t
.
{
w
′
1
=
1
ψ
≥
w
,
ψ
≥
−
w
\min_{w, \psi} w'\Sigma w-\lambda(\hat{\mu}'w-\delta' \psi)\\ s.t. \begin{cases} w'\mathbf{1}=1\\ \psi\geq w, \psi\geq -w \end{cases}
w,ψminw′Σw−λ(μ^′w−δ′ψ)s.t.{w′1=1ψ≥w,ψ≥−w
Dividing the
w
w
w into positive component
w
+
∈
R
n
w_+\in\mathbb{R}^n
w+∈Rn and negative component
w
−
∈
R
n
w_-\in\mathbb{R}^n
w−∈Rn, where both vectors are represented as non-negative values, results in another formulation:
min
w
,
w
+
,
w
−
w
′
Σ
w
−
λ
(
μ
^
w
−
δ
′
(
w
+
−
w
−
)
)
s
.
t
.
{
w
′
1
=
1
w
=
w
+
−
w
−
w
+
≥
0
,
w
−
≥
0
\min_{w, w_+, w_-}w'\Sigma w-\lambda(\hat{\mu}w-\delta'(w_+-w_-))\\ s.t. \begin{cases} w'\mathbf{1}=1\\ w=w_+-w_-\\ w_+\geq 0, w_-\geq 0 \end{cases}
w,w+,w−minw′Σw−λ(μ^w−δ′(w+−w−))s.t.⎩⎪⎨⎪⎧w′1=1w=w+−w−w+≥0,w−≥0
It can be expressed as a problem with a single variable of length
2
n
2n
2n and proper transformation matrices.
- Instead of w w w, introduce x ∈ R 2 n x\in\mathbb{R}^{2n} x∈R2n where the first n n n elements represent the positive components of w w w, and the second n n n elements represent the negative components of w w w.
- Define two transformation matrices T ∈ R n × 2 n T\in\mathbb{R}^{n\times 2n} T∈Rn×2n and T a b s ∈ R n × 2 n T_{abs}\in\mathbb{R}^{n\times 2n} Tabs∈Rn×2n.
T
=
[
1
0
−
1
0
⋱
⋱
0
1
0
−
1
]
=
[
I
−
I
]
T= \left[ \begin{matrix} 1 & &0 &-1 & & 0\\ &\ddots & & &\ddots\\ 0 & &1& 0 & & -1 \end{matrix} \right]= \left[ \begin{matrix} I &-I \end{matrix} \right]
T=⎣⎡10⋱01−10⋱0−1⎦⎤=[I−I]
and
T
a
b
s
=
[
1
0
1
0
⋱
⋱
0
1
0
1
]
=
[
I
I
]
T_{abs}= \left[ \begin{matrix} 1 & &0 &1 & & 0\\ &\ddots & & &\ddots\\ 0 & &1& 0 & & 1 \end{matrix} \right]= \left[ \begin{matrix} I & I \end{matrix} \right]
Tabs=⎣⎡10⋱0110⋱01⎦⎤=[II]
- Define vectors
w
w
w and
∣
w
∣
|w|
∣w∣ are expressed using
T
T
T and
T
a
b
s
T_{abs}
Tabs as
{ w = T x ∣ w ∣ = T a b s x \left\{ \begin{aligned} &w=Tx\\ &|w|=T_{abs}x \end{aligned} \right. {w=Tx∣w∣=Tabsx
Since portfolio weight
w
w
w and its absolute value can be expressed in terms of
x
x
x, it becomes obvious that the objective function of the problem is given by:
x
′
T
′
Σ
T
x
−
λ
(
μ
′
T
x
−
δ
′
T
a
b
s
x
)
x'T'\Sigma Tx-\lambda(\mu'Tx-\delta'T_{abs}x)
x′T′ΣTx−λ(μ′Tx−δ′Tabsx)
and the complete robust counterpart is written as
min
x
x
′
T
′
Σ
T
x
−
λ
(
μ
^
′
T
−
δ
′
T
a
b
s
)
x
s
.
t
.
{
x
′
T
′
1
=
1
x
≥
0
\min_x x'T'\Sigma Tx-\lambda(\hat{\mu}'T-\delta'T_{abs})x\\ s.t. \begin{cases} x'T'\mathbf{1}=1\\ x\geq 0 \end{cases}
xminx′T′ΣTx−λ(μ^′T−δ′Tabs)xs.t.{x′T′1=1x≥0
Matlab Code: quadprog
function opt_port = func_box_quadprog(returns, lambda, alpha)
% Find the optimal robust portfolio with box uncertainty using
% quadprog
% input:
% returns, matrix of stock returns (each column represents a single stock)
% lambda, value of the risk-seeking coefficient
% alpha, confidence level of the uncertainty set
% output: optimal mean-variance portfolio (a column vector)
[nDays, n] = size(returns);
mu = mean(returns); % 1xn
sigma = cov(returns); % nxn
% Compute delta (use confidence interval of mean for normal distribution)
z = norminv(1-(1-alpha)/2, 0, 1);
delta = z*std(returns)/sqrt(nDays); % 1xn
I = eye(n);% nxn
T = [I, -I]; % nx2n
Tabs = [I, I];% nx2n
muT = (mu*T-delta*Tabs)'; % 2nx1
Aeq = [ones(1, n), -ones(1, n)]; % 1x2n
beq = 1;
lb = zeros(2*n, 1);
x = quadprog(2*T'*sigma*T, -lambda*muT, [], [], Aeq, beq, lb, []);
opt_port = T*x;
end
設定引數
n
=
20
n=20
n=20,
n
D
a
y
s
=
500
nDays=500
nDays=500,
λ
=
0.1
\lambda=0.1
λ=0.1,
α
=
0.8
\alpha=0.8
α=0.8,執行主函式得到optimal portfolio weights
如下
%% generate simulated data
rng(729);
n = 20;
nDays = 500;
stock_returns = randn(nDays, n); % 模擬股票市場
lambda = 0.1; % 設定risk-seeking coef.
alpha=0.8;
opt_port = func_box_quadprog(stock_returns, lambda, alpha);
得到結果如下
Matlab Code: fmincon
function opt_port = func_box_fmincon(returns, lambda, alpha)
% Find the optimal robust portfolio with box uncertainty using
% quadprog
% input:
% returns, matrix of stock returns (each column represents a single stock)
% lambda, value of the risk-seeking coefficient
% alpha, confidence level of the uncertainty set
% output: optimal mean-variance portfolio (a column vector)
[nDays, n] = size(returns);
mu = mean(returns);
sigma = cov(returns);
z = norminv(1-(1-alpha)/2, 0, 1);
delta = z*std(returns)/sqrt(nDays);
I = eye(n);% nxn
T = [I, -I]; % nx2n
Tabs = [I, I];% nx2n
muT = (mu*T-delta*Tabs); % 2nx1
Aeq = [ones(1, n), -ones(1, n)]; % 1x2n
beq = 1;
lb = zeros(2*n, 1);
% Nested function which is used as the objective function
function objValue = subfunction(x)
objValue = x'*T'*sigma*T*x-lambda * muT*x;
end
% Set the start-point: equal-weighted portfolio
x0 = [ones(n, 1)/n; zeros(n, 1)];
% Set the algorithm to interior-point method
options = optimset('Algorithm', 'interior-point');
x = fmincon(@subfunction, x0, [], [], Aeq, beq, lb, [], [], options);
opt_port = T*x;
end
兩者解相同
References
ROBUST EQUITY PORTFOLIO MANAGEMENT+WEBSITE