1 简介
阿基米德优化算法( Archimedes optimization algorithm, AOA)是一种基于群体的启发式算法.现实世界数值优化问题的难度和复杂性已经成倍增加,这就需要有效的优化方法。 迄今为止,已经引入了各种元启发式方法,但只有少数在研究界得到认可。 在本文中,引入了一种称为阿基米德优化算法(AOA)的新元启发式算法来解决优化问题。 AOA 的设计灵感来自一个有趣的物理定律阿基米德原理。 它模拟了向上施加在物体上的浮力原理,部分或完全浸入流体中,与被排出流体的重量成正比。
随着国民经济的发展,投资理财已成为常态,股票投资顺势成为许多人的选择,其中股票价格预测成为投资者最关心的问题.股票市场中各种因素错综复杂,主次关系变化不定,股票价格不仅受买卖双方的影响,也与国内外政策,投资者的主观意识等因素有直接关系.所以股票价格具有随机性较强的特点,因此研究一种正确率较高的股票价格预测模型具有十分重要的现实意义.本文采用BP神经网络与阿基米德优化算法结合的方法对股票价格预测进行研究.最后通过MATLAB编程实现了本文所给出的股价预测模型,并使用真实的股票数据进行股价预测,通过仿真分析可知,本文所给出的预测模型具有较高的预测精度。
2 部分代码
function [Best_FF,Best_P,Conv_curve]=AOA(N,M_Iter,LB,UB,Dim,F_obj)
display('AOA Working');
%Two variables to keep the positions and the fitness value of the best-obtained solution
Best_P=zeros(1,Dim);
Best_FF=inf;
Conv_curve=zeros(1,M_Iter);
%Initialize the positions of solution
X=initialization(N,Dim,UB,LB);
Xnew=X;
Ffun=zeros(1,size(X,1));% (fitness values)
Ffun_new=zeros(1,size(Xnew,1));% (fitness values)
MOP_Max=1;
MOP_Min=0.2;
C_Iter=1;
Alpha=5;
Mu=0.499;
for i=1:size(X,1)
Ffun(1,i)=F_obj(X(i,:)); %Calculate the fitness values of solutions
if Ffun(1,i)<Best_FF
Best_FF=Ffun(1,i);
Best_P=X(i,:);
end
end
while C_Iter<M_Iter+1 %Main loop
MOP=1-((C_Iter)^(1/Alpha)/(M_Iter)^(1/Alpha)); % Probability Ratio
MOA=MOP_Min+C_Iter*((MOP_Max-MOP_Min)/M_Iter); %Accelerated function
%Update the Position of solutions
for i=1:size(X,1) % if each of the UB and LB has a just value
for j=1:size(X,2)
r1=rand();
if (size(LB,2)==1)
if r1<MOA
r2=rand();
if r2>0.5
Xnew(i,j)=Best_P(1,j)/(MOP+eps)*((UB-LB)*Mu+LB);
else
Xnew(i,j)=Best_P(1,j)*MOP*((UB-LB)*Mu+LB);
end
else
r3=rand();
if r3>0.5
Xnew(i,j)=Best_P(1,j)-MOP*((UB-LB)*Mu+LB);
else
Xnew(i,j)=Best_P(1,j)+MOP*((UB-LB)*Mu+LB);
end
end
end
if (size(LB,2)~=1) % if each of the UB and LB has more than one value
r1=rand();
if r1<MOA
r2=rand();
if r2>0.5
Xnew(i,j)=Best_P(1,j)/(MOP+eps)*((UB(j)-LB(j))*Mu+LB(j));
else
Xnew(i,j)=Best_P(1,j)*MOP*((UB(j)-LB(j))*Mu+LB(j));
end
else
r3=rand();
if r3>0.5
Xnew(i,j)=Best_P(1,j)-MOP*((UB(j)-LB(j))*Mu+LB(j));
else
Xnew(i,j)=Best_P(1,j)+MOP*((UB(j)-LB(j))*Mu+LB(j));
end
end
end
end
Flag_UB=Xnew(i,:)>UB; % check if they exceed (up) the boundaries
Flag_LB=Xnew(i,:)<LB; % check if they exceed (down) the boundaries
Xnew(i,:)=(Xnew(i,:).*(~(Flag_UB+Flag_LB)))+UB.*Flag_UB+LB.*Flag_LB;
Ffun_new(1,i)=F_obj(Xnew(i,:)); % calculate Fitness function
if Ffun_new(1,i)<Ffun(1,i)
X(i,:)=Xnew(i,:);
Ffun(1,i)=Ffun_new(1,i);
end
if Ffun(1,i)<Best_FF
Best_FF=Ffun(1,i);
Best_P=X(i,:);
end
end
%Update the convergence curve
Conv_curve(C_Iter)=Best_FF;
%Print the best solution details after every 50 iterations
if mod(C_Iter,50)==0
display(['At iteration ', num2str(C_Iter), ' the best solution fitness is ', num2str(Best_FF)]);
end
C_Iter=C_Iter+1; % incremental iteration
end
3 仿真结果
a4 参考文献
[1]任浩然. 基于自适应遗传算法优化的BP神经网络股价预测模型[D]. 延安大学.