基于元启发式算法的130 - 30投资组合构建与优化
1. 130 - 30投资组合构建的DE HOF算法
DE HOF是一种基于种群的元启发式搜索过程,用于构建最优的130 - 30投资组合。其具体步骤为:
-
初始化
:从代表候选解集的初始随机种群开始。
-
转换
:通过权重修复或其他策略将其转换为可行解集种群。
-
生成试验向量与交叉
:获取试验向量并进行交叉操作,生成子代个体种群。
-
选择
:在亲代和子代种群之间采用适当的选择机制,生成下一代个体种群。
-
竞争
:将新一代中的最佳个体与名人堂中的个体竞争。
-
循环
:触发一系列的生成周期,直到满足终止准则,此时名人堂中的个体被视为“最优”解。
在130 - 30投资组合构建中,DE HOF有以下特定差异:
1.
采用Rand4/Best/Dir5变异算子
:通过在差分向量的公式中采用五个不同的方向,扩大搜索过程。公式为:
[t = V_{best} + \varphi \cdot (5 \cdot V_{best} - IND - V_1 - V_2 - V_3 - V_4)]
其中,(\varphi = \beta_S / 5),(\beta_S)是动态比例因子,在每一代中使用抖动技术随机选择在([0.5, 1])之间。
2.
使用动态比例因子
:采用抖动技术,为每一代或每个差分向量随机选择比例因子(\beta)在([0.5, 1])之间,确保策略的收敛行为有显著改善。
3.
采用专门的权重修复策略
:处理130 - 30投资组合的多头和空头头寸所施加的预算和边界约束。
4.
使用定制的适应度函数
:适合130 - 30投资组合模型,结合Joines和Houcke的惩罚函数策略为问题模型规定的惩罚目标函数。
2. 实验结果
对采用动态比例因子的DE HOF(Rand5/Best/Dir4)策略在S&P BSE200指数(1999年3月 - 2009年3月)的大型投资组合数据集上进行了研究。具体步骤如下:
1.
数据处理
:使用股票宇宙的平均收益率和收益率的方差 - 协方差矩阵作为聚类算法的特征,对S&P BSE200宇宙进行k - 均值聚类(k = 90),并从每个聚类中随机选择一个资产纳入投资组合。
2.
参数设置
:计算相关资产的贝塔值,将印度市场在此期间的平均无风险利率(Rf)设置为6.5%,设置资产的平均收益率(\mu_{[1×90]})和方差 - 协方差矩阵(V_{(90×90)}),设置多头和空头头寸的杠杆边界。
3.
优化目标
:在保持所有其他约束(如投资组合预算、多头和空头头寸预算以及投资组合贝塔约束)不变的情况下,使用DE HOF求解由[6.12] - [6.19]定义的适当数学模型,以获得所考虑的k - 投资组合的最优约束130 - 30投资组合。
控制参数如下表所示:
| 参数 | 描述 |
| ---- | ---- |
| 种群大小 | 1000 |
| 个体长度 | 90 (k = 90) |
| 代数 | 8000 |
| 动态比例因子(\beta_S)(每代使用抖动) | [0.5, 1] |
| 重组概率(pr) | 0.87 |
| (C, α, β) | (0.5, 2, 2) |
多次运行元启发式算法,在特定的k - 投资组合上获得了关于最大夏普比率的高度一致的结果。通过观察在生成周期中被选入名人堂的个体的适应度函数值(通常是惩罚目标函数值),研究了DE HOF(Rand4/Best/Dir5)策略的收敛情况。结果表明,在大约3000代时达到收敛,适应度函数值稳定,此后不再有利于将更好的个体选入名人堂。
3. MATLAB演示
通过MATLAB函数或代码片段,演示了与DE HOF(Rand4/Best/Dir5)策略相关的以下概念:
1.
Rand4/Best/Dir5算子的实现
:
function trialvector_popln =
DE_Rand4BestDir5_Operator(popln, fitness_val,
beta_val, popln_size, individual_length)
% initialization
differential_vec_indx(1:5) = 0;
V_b(1,1:individual_length) = 0;
V(1:4,1:individual_length) = 0;
trialvector_popln(1:popln_size, 1:individual_length) =0;
for i = 1 : popln_size
% set IND the current individual in the population
% indicated by i
IND = popln(i,:);
% prepare rand_indx, random indices for each
% population individual, to enable it choose five
% random individuals from the population, without
% repeating itself.
rand_indx = randperm(popln_size);
for t=1:popln_size
if (rand_indx(t)==i)
elimx = t;
end
end
rand_indx(elimx)=[];
% select five random individuals from the population
for u=1:5
differential_vec_indx(u) = rand_indx(u);
end
% Obtain Vb the best individual with the maximal
% objective function and represent the rest as
% V1, V2, V3 and V4 as defined in equation [6.20]
[~, max_obj_indx] =
max( [fitness_val(differential_vec_indx(1)),
fitness_val(differential_vec_indx(2)),
fitness_val(differential_vec_indx(3)),
fitness_val(differential_vec_indx(4)),
fitness_val(differential_vec_indx(5))]);
j=1;
for z=1:5
if (differential_vec_indx(z) ==
differential_vec_indx(max_obj_indx))
V_b(1,:) = popln(differential_vec_indx(z), :);
else
V(j,:) = popln(differential_vec_indx(z),:);
j=j+1;
end
end
% obtain trial vector for each of the parent vector
% individual
trialvector_popln(i,:) = V_b(1,:) + beta_val/5 *
(5*V_b(1,:) - IND - V(1,:)-V(2,:)-V(3,:)-V(4,:));
end
end
- 权重修复策略阶段1的实现 :
function std_weight_mat =
weight_std_130_30_boundsconstr(weight_mat, low_up_bounds)
[row_mat, col_mat]=size(weight_mat);
[~, up_bound] = size(low_up_bounds);
% Steps 1 and 2 of Weight Repair Strategy Phase 1
% standardize weights to satisfy their lower bounds while
% summing up to 1
for i=1: row_mat
% R: those weights which are less than their
% respective lower bounds
R=[];
c_R=0;
for j=1:col_mat
if (weight_mat(i,j)< low_up_bounds(1,j))
weight_mat(i,j)= low_up_bounds(1,j);
c_R = c_R+1;
R(c_R) = j;
end
end
% Q: those weights which satisfy their respective
% lower bounds
Q = setdiff([1:col_mat], R);
F = 1 - sum(low_up_bounds(1,R))-
sum(low_up_bounds(1,Q));
L = sum(abs(weight_mat(i,Q)));
if (L==0)
term = F / length(Q);
weight_mat(i,Q)= low_up_bounds(1,Q)+ term;
else
term = F / L;
weight_mat(i,Q) = low_up_bounds(1,Q)+
abs(weight_mat(i,Q))* term;
end
end
% Steps 3-6 of Weight Repair Strategy Phase 1
% standardize upper bounds so that weights ultimately
% satisfy both upper and lower bounds and sum up to 1
for i = 1: row_mat
kr = 1;
r = [];
ex_flag = true;
q = setdiff([1:col_mat], r);
while (ex_flag == true)
ex_flag = false;
for j = 1: length(q)
if ( weight_mat(i, q(j)) <= low_up_bounds(2, q(j)))
continue;
else
ex_flag = true;
r(kr) = q(j);
kr = kr+1;
end
end
q = setdiff([1:col_mat], r);
if (ex_flag == true)
L = sum(abs(weight_mat(i,q)));
F = 1 - ( sum(low_up_bounds(1,q))+ sum(
low_up_bounds(2,r)) );
if (L==0)
term = F;
weight_mat(i,q(1))= term;
else
term = F/L;
weight_mat(i,q) = low_up_bounds(1,q) +
(abs(weight_mat(i,q))* term);
end
weight_mat(i,r)=low_up_bounds(2,r);
end
end
std_weight_mat = weight_mat;
end
- 权重修复策略阶段2的实现 :
function std_weight_mat =
weight_std_130_30_budgetconstr(weight_mat,
long_low_up_bounds, short_low_up_bounds)
[row_mat, col_mat]= size(weight_mat);
% budgets for long positions
eta = 1.3;
gamma = 0;
for p = 1:row_mat
H = group_assets_130_30(col_mat, weight_mat(p,:));
% adjust weights representing long positions
deposit_wgts =0;
h=1;
sum_wgts = sum(weight_mat(p,H{h}));
% check if sum of weights of long positions lie
% within limits
if (sum_wgts <= eta ) && (sum_wgts >= gamma)
continue;
else
deposit_wgts = deposit_wgts + (sum_wgts-eta);
MP = eta;
weight_mat(p,:) =
std_wgts_asset_130_30_longclass(weight_mat(p,:),
H{h}, sum_wgts, MP, long_low_up_bounds);
end
% adjust weights representing short positions
if (deposit_wgts ==0) continue;
else
h = 2;
sum_wgts = sum(weight_mat(p,H{h}));
abs_sum_wgts = sum(abs(weight_mat(p,H{h})) );
deposit_wgts = deposit_wgts + sum_wgts;
weight_mat(p,:) =
std_wgts_asset_130_30_shortclass(weight_mat(p,:),
H{h}, abs_sum_wgts, deposit_wgts,
short_low_up_bounds);
end
end
std_weight_mat = weight_mat;
end
- 约束违反函数和适应度值函数的实现 :
function [psi, G] = ConstrViolnFun_130_30( weight_mat,
betas_assets, C_param, alpha_param, beta_param,
gencount)
[row_mat, ~]= size(weight_mat);
epsilon = 0.001;
for i=1:row_mat
x_chromo = weight_mat(i,:);
% compute penalty function G
portfolio_beta_term = sum(betas_assets.* x_chromo);
g1_term = abs((portfolio_beta_term) - 1)-epsilon;
if (g1_term <=0 )
G(i)=0;
else
G(i)=1;
end
% compute constraint violation function
penalty_term= power(C_param*gencount, alpha_param);
psi(i) = penalty_term *( G(i)*power(g1_term,
beta_param));
end
end
function popln_fitness = CompFitness_130_30(popln_mat,
return_dat, covariance_dat, riskfree, psi_fun)
[popln_size, ~]=size(popln_mat);
for i = 1: popln_size
weight = popln_mat(i,:);
popln_fitness(i) = (((return_dat * weight')-riskfree)/
sqrt(weight*covariance_dat * weight')) - psi_fun(i);
end
end
- DE HOF(Rand4/Best/Dir5)策略在130 - 30投资组合优化期间的生成周期 :
% while loop for generation cycles begins
while (gen_indx <= total_generations)
% dynamic beta for each generation
dynamic_beta = 0.5+(1-0.5)*rand(1,1);
% obtain trial vector population
trial_vector_popln =
DE_Rand4BestDir5_Operator(feas_parent_popln,
feas_parent_popln_fitness,dynamic_beta,
popln_size, chromosm_length);
% obtain offspring population
offsprng_popln = DE_bin_Crossover(feas_parent_popln,
trial_vector_popln, pr_recombi,
chromosm_length);
% undertake weight repair strategy Phase 1
mutat_popln_bound =
weight_std_130_30_boundsconstr(offsprng_popln,
bounds);
% undertake weight repair strategy Phase 2
feas_mutat_popln =
weight_std_130_30_budgetconstr(mutat_popln_bound,
long_pos_bounds, short_pos_bounds);
% compute constraint violation function
[feas_mutat_popln_psi, feas_mutat_popln_G1] =
ConstrViolnFun_130_30 (feas_mutat_popln,
Beta_assets, C_dp, alpha_dp, beta_dp,
gen_indx);
% compute fitness function values
feas_mutat_popln_fitness =
CompFitness_130_30(feas_mutat_popln, mean_data,
cov_data, riskfree, feas_mutat_popln_psi);
% set the population for the next generation
[next_gen_pool, next_gen_pool_fitness, Psi_fun ] =
DE_selection_penalty_13030 (feas_parent_popln,
feas_parent_popln_fitness, feas_parent_popln_psi,
feas_mutat_popln, feas_mutat_popln_fitness,
feas_mutat_popln_psi, popln_size);
% induct best individual into Hall of Fame
for i=1:popln_size
if (Psi_fun(i)== 0)
if (next_gen_pool_fitness(i) > HOF_fitness)
HOF_fitness = next_gen_pool_fitness(i);
HOF_individual = next_gen_pool(i,:);
end
else
continue;
end
end
% increment generation counter
gen_indx = gen_indx + 1;
% form the parent population for the next generation
feas_parent_popln = next_gen_pool;
feas_parent_popln_fitness = next_gen_pool_fitness;
end % while loop for generations ends
4. 项目探索
为了探索Gordon Fowler的断言,可以进行以下操作:
1.
下载数据
:从可靠的金融网站下载所选股票指数的历史数据集。
2.
实现优化策略
:使用MATLAB的Financial Toolbox™中的Portfolio对象,在所选的股票宇宙上实现130 - 30、140 - 40、150 - 50、160 - 60投资组合优化策略。
3.
计算信息比率
:计算这些投资组合的信息比率。
4.
性能比较
:将这些投资组合的性能与其仅多头的对应组合进行比较,判断是否表现更好。
5.
算法修改
:修改DE HOF(Rand4/Best/Dir5)算法,使其适用于130 - 30、140 - 40、150 - 50和160 - 60策略的约束优化,并观察结果。
6.
风险预算探索
:考虑对130 - 30投资组合施加风险预算,探索其影响。
综上所述,通过DE HOF算法和MATLAB的实现,我们可以有效地构建和优化130 - 30投资组合,并通过实验和进一步的探索,深入了解不同策略和参数对投资组合性能的影响。
基于元启发式算法的130 - 30投资组合构建与优化
5. 权重修复策略各阶段详细分析
在前面提到的权重修复策略的两个阶段中,每个阶段都有其独特的作用和实现方式。下面将详细分析这两个阶段的具体操作和意义。
5.1 权重修复策略阶段1
此阶段主要是让投资组合的权重满足个体边界约束,同时保证权重总和为1。其具体步骤如下:
1.
处理低于下限的权重
:找出权重矩阵中低于对应下限的权重,将其调整为下限值,并记录这些权重的索引。
2.
调整满足下限的权重
:计算需要调整的权重总和,根据满足下限的权重总和进行比例调整,使得所有权重总和为1。
3.
处理高于上限的权重
:找出高于上限的权重,将其调整为上限值,并重新分配剩余的权重,以保证权重总和仍为1。
以下是实现该阶段的MATLAB代码:
function std_weight_mat =
weight_std_130_30_boundsconstr(weight_mat, low_up_bounds)
[row_mat, col_mat]=size(weight_mat);
[~, up_bound] = size(low_up_bounds);
% Steps 1 and 2 of Weight Repair Strategy Phase 1
% standardize weights to satisfy their lower bounds while
% summing up to 1
for i=1: row_mat
% R: those weights which are less than their
% respective lower bounds
R=[];
c_R=0;
for j=1:col_mat
if (weight_mat(i,j)< low_up_bounds(1,j))
weight_mat(i,j)= low_up_bounds(1,j);
c_R = c_R+1;
R(c_R) = j;
end
end
% Q: those weights which satisfy their respective
% lower bounds
Q = setdiff([1:col_mat], R);
F = 1 - sum(low_up_bounds(1,R))-
sum(low_up_bounds(1,Q));
L = sum(abs(weight_mat(i,Q)));
if (L==0)
term = F / length(Q);
weight_mat(i,Q)= low_up_bounds(1,Q)+ term;
else
term = F / L;
weight_mat(i,Q) = low_up_bounds(1,Q)+
abs(weight_mat(i,Q))* term;
end
end
% Steps 3-6 of Weight Repair Strategy Phase 1
% standardize upper bounds so that weights ultimately
% satisfy both upper and lower bounds and sum up to 1
for i = 1: row_mat
kr = 1;
r = [];
ex_flag = true;
q = setdiff([1:col_mat], r);
while (ex_flag == true)
ex_flag = false;
for j = 1: length(q)
if ( weight_mat(i, q(j)) <= low_up_bounds(2, q(j)))
continue;
else
ex_flag = true;
r(kr) = q(j);
kr = kr+1;
end
end
q = setdiff([1:col_mat], r);
if (ex_flag == true)
L = sum(abs(weight_mat(i,q)));
F = 1 - ( sum(low_up_bounds(1,q))+ sum(
low_up_bounds(2,r)) );
if (L==0)
term = F;
weight_mat(i,q(1))= term;
else
term = F/L;
weight_mat(i,q) = low_up_bounds(1,q) +
(abs(weight_mat(i,q))* term);
end
weight_mat(i,r)=low_up_bounds(2,r);
end
end
std_weight_mat = weight_mat;
end
5.2 权重修复策略阶段2
该阶段主要是让投资组合满足多头和空头头寸的预算约束。其具体步骤如下:
1.
分离多头和空头头寸
:将权重矩阵中的多头和空头头寸分离出来。
2.
调整多头头寸权重
:检查多头头寸权重总和是否在预算范围内,若不在则进行调整。
3.
调整空头头寸权重
:根据多头头寸调整后剩余的权重,调整空头头寸权重,使其满足预算约束。
以下是实现该阶段的MATLAB代码:
function std_weight_mat =
weight_std_130_30_budgetconstr(weight_mat,
long_low_up_bounds, short_low_up_bounds)
[row_mat, col_mat]= size(weight_mat);
% budgets for long positions
eta = 1.3;
gamma = 0;
for p = 1:row_mat
H = group_assets_130_30(col_mat, weight_mat(p,:));
% adjust weights representing long positions
deposit_wgts =0;
h=1;
sum_wgts = sum(weight_mat(p,H{h}));
% check if sum of weights of long positions lie
% within limits
if (sum_wgts <= eta ) && (sum_wgts >= gamma)
continue;
else
deposit_wgts = deposit_wgts + (sum_wgts-eta);
MP = eta;
weight_mat(p,:) =
std_wgts_asset_130_30_longclass(weight_mat(p,:),
H{h}, sum_wgts, MP, long_low_up_bounds);
end
% adjust weights representing short positions
if (deposit_wgts ==0) continue;
else
h = 2;
sum_wgts = sum(weight_mat(p,H{h}));
abs_sum_wgts = sum(abs(weight_mat(p,H{h})) );
deposit_wgts = deposit_wgts + sum_wgts;
weight_mat(p,:) =
std_wgts_asset_130_30_shortclass(weight_mat(p,:),
H{h}, abs_sum_wgts, deposit_wgts,
short_low_up_bounds);
end
end
std_weight_mat = weight_mat;
end
6. 约束违反函数和适应度值函数的作用
约束违反函数和适应度值函数在130 - 30投资组合优化中起着关键作用。
6.1 约束违反函数
约束违反函数用于检查投资组合是否满足约束条件,如投资组合的贝塔值是否接近1。如果不满足约束条件,则会产生惩罚项。以下是计算约束违反函数的MATLAB代码:
function [psi, G] = ConstrViolnFun_130_30( weight_mat,
betas_assets, C_param, alpha_param, beta_param,
gencount)
[row_mat, ~]= size(weight_mat);
epsilon = 0.001;
for i=1:row_mat
x_chromo = weight_mat(i,:);
% compute penalty function G
portfolio_beta_term = sum(betas_assets.* x_chromo);
g1_term = abs((portfolio_beta_term) - 1)-epsilon;
if (g1_term <=0 )
G(i)=0;
else
G(i)=1;
end
% compute constraint violation function
penalty_term= power(C_param*gencount, alpha_param);
psi(i) = penalty_term *( G(i)*power(g1_term,
beta_param));
end
end
6.2 适应度值函数
适应度值函数用于评估投资组合的优劣,通常考虑投资组合的收益率、风险和约束违反情况。以下是计算适应度值函数的MATLAB代码:
function popln_fitness = CompFitness_130_30(popln_mat,
return_dat, covariance_dat, riskfree, psi_fun)
[popln_size, ~]=size(popln_mat);
for i = 1: popln_size
weight = popln_mat(i,:);
popln_fitness(i) = (((return_dat * weight')-riskfree)/
sqrt(weight*covariance_dat * weight')) - psi_fun(i);
end
end
7. 生成周期流程分析
DE HOF(Rand4/Best/Dir5)策略在130 - 30投资组合优化期间的生成周期流程如下:
1.
初始化动态比例因子
:为每一代随机选择动态比例因子(\beta_S)。
2.
生成试验向量种群
:使用Rand4/Best/Dir5算子生成试验向量种群。
3.
生成子代种群
:通过交叉操作生成子代种群。
4.
权重修复
:对代种群进行权重修复,使其满足约束条件。
5.
计算约束违反和适应度值
:计算子代种群的约束违反函数值和适应度值。
6.
选择下一代个体
:从亲代和子代种群中选择最优个体组成下一代种群。
7.
更新名人堂个体
:将下一代种群中的最优个体与名人堂中的个体竞争,更新名人堂个体。
以下是实现生成周期的MATLAB代码:
% while loop for generation cycles begins
while (gen_indx <= total_generations)
% dynamic beta for each generation
dynamic_beta = 0.5+(1-0.5)*rand(1,1);
% obtain trial vector population
trial_vector_popln =
DE_Rand4BestDir5_Operator(feas_parent_popln,
feas_parent_popln_fitness,dynamic_beta,
popln_size, chromosm_length);
% obtain offspring population
offsprng_popln = DE_bin_Crossover(feas_parent_popln,
trial_vector_popln, pr_recombi,
chromosm_length);
% undertake weight repair strategy Phase 1
mutat_popln_bound =
weight_std_130_30_boundsconstr(offsprng_popln,
bounds);
% undertake weight repair strategy Phase 2
feas_mutat_popln =
weight_std_130_30_budgetconstr(mutat_popln_bound,
long_pos_bounds, short_pos_bounds);
% compute constraint violation function
[feas_mutat_popln_psi, feas_mutat_popln_G1] =
ConstrViolnFun_130_30 (feas_mutat_popln,
Beta_assets, C_dp, alpha_dp, beta_dp,
gen_indx);
% compute fitness function values
feas_mutat_popln_fitness =
CompFitness_130_30(feas_mutat_popln, mean_data,
cov_data, riskfree, feas_mutat_popln_psi);
% set the population for the next generation
[next_gen_pool, next_gen_pool_fitness, Psi_fun ] =
DE_selection_penalty_13030 (feas_parent_popln,
feas_parent_popln_fitness, feas_parent_popln_psi,
feas_mutat_popln, feas_mutat_popln_fitness,
feas_mutat_popln_psi, popln_size);
% induct best individual into Hall of Fame
for i=1:popln_size
if (Psi_fun(i)== 0)
if (next_gen_pool_fitness(i) > HOF_fitness)
HOF_fitness = next_gen_pool_fitness(i);
HOF_individual = next_gen_pool(i,:);
end
else
continue;
end
end
% increment generation counter
gen_indx = gen_indx + 1;
% form the parent population for the next generation
feas_parent_popln = next_gen_pool;
feas_parent_popln_fitness = next_gen_pool_fitness;
end % while loop for generations ends
8. 总结与展望
通过上述的研究和实验,我们可以看到DE HOF(Rand4/Best/Dir5)策略在130 - 30投资组合优化中具有较好的效果。通过合理设置参数和采用有效的权重修复策略,可以使投资组合满足各种约束条件,并获得较高的夏普比率。
未来的研究可以进一步探索不同的元启发式算法和策略,以提高投资组合的优化效果。同时,可以考虑引入更多的约束条件和目标函数,如风险预算、交易成本等,使投资组合更加符合实际需求。此外,还可以对不同市场环境下的投资组合优化进行研究,以提高策略的适应性和稳定性。
总之,130 - 30投资组合优化是一个具有挑战性和实际应用价值的研究领域,通过不断的探索和创新,有望为投资者提供更加有效的投资策略和决策支持。
以下是DE HOF(Rand4/Best/Dir5)策略在130 - 30投资组合优化期间的生成周期流程图:
graph TD;
A[初始化动态比例因子] --> B[生成试验向量种群];
B --> C[生成子代种群];
C --> D[权重修复];
D --> E[计算约束违反和适应度值];
E --> F[选择下一代个体];
F --> G[更新名人堂个体];
G --> A;
通过这个流程图,可以更直观地了解生成周期的整个过程,有助于我们更好地理解和实现该策略。
基于DE HOF算法的130-30投资组合优化
超级会员免费看
913

被折叠的 条评论
为什么被折叠?



