Choosing the best parameters for strategy with genetic algorithm
조회 수: 6 (최근 30일)
이전 댓글 표시
Diego Makasevicius Barbosa
2015년 4월 9일
편집: Diego Makasevicius Barbosa
2015년 6월 1일
Hello all, I developed a quantitative strategy, which it has a script that calling a function with seven parameters. The function uses some equity data (eg: price, volatility and so on). The function returns the 'sharpe ratio value'. The higher it is, the better is the result.
Is there a way to the Matlab help me to choose the best settings? I tried to use GA function without success.
-----------------------------------------------------------------------------
%%script example
x1=1;
x2=10;
x3=15;
x4=7;
x5=9;
x6=0.1;
x7=0.9;
load('Data.mat') % Price, Volume, Volatility
[sharpe] strategy(x1,x1,x1,x1,x1,x1,x1); %function
%end Script
-----------------------------------------------------------------------------
Thank you in advance!
댓글 수: 0
채택된 답변
Mohammad Abouali
2015년 4월 9일
편집: Mohammad Abouali
2015년 4월 9일
Let's say you have successfully coded strategy function which provided seven input parameters, it would give you the 'Sharpe Ratio Value'. From the look of it, it seems that you have designed this function as follow:
sharpe=strategy(x1,x2,x3,x4,,x5,x6,x7,x8)
You want to choose x1 to x7 in such a way that your sharpe ratio value (SRV) is maximized. You need to note two things (1) all the optimization function are minimization, so first you need to define your objective function as a minimization, and (2) different parameters should be entered to the objective function as different element of a vector (not separate variable as you have defined above.
For the reason above you can not directly feed strategy function to GA in matlab. To turn your problem from maximization to minimization, we can minimize the difference between the maximum possible sharpe ratio value to its current value which is equivalent of maximizing the sharpe value. and the second change, i.e. vector input is also easy. So define your objective function as follows:
myObjFunction=@(x) maxSRV-strategy(x(1),x(2),x(3),x(4),x(5),x(6),x(7));
where, maxSRV is the maximum value that Sharpe Ratio Value could get. If you don't know it, choose a really big number that it is going to be impossible to reach. And in your strategy code make sure that if a number above that is reached an error is produced. There are other methods to turn a maximumization into a minimization. You can try other method too.
now that you have a proper objective function pass that to GA like:
x = ga(myObjFunction,7)
that's the minimum requirement for ga, if your x1 to x7 are bounded (there is a minimum maximum value that they can get, it is always good to provide them to ga. you can do this as follows:
% Lower Bound limit
LB = {minX1,minX2,minX3,minX4,minX5,minX6,minX7];
% Upper bound
UB = {maxX1,maxX2,maxX3,maxX4,maxX5,maxX6,maxX7];
x = ga(myObjFunction,0,[],[],[],[],LB,UB)
댓글 수: 2
Mohammad Abouali
2015년 4월 17일
Fortunately MATLAB's GA already supports integer variables. All you need to do is to tell GA which parameters are integer using IntCon parameter.
x = ga(myObjFunction,0,[],[],[],[],LB,UB,[],IntCon)
IntCon lists all the parameters that are integer, for example if variable 2 and 4 can take only integer values, then set IntCon=[2, 4]. In your case if all parameters are integer simply set IntCon=1:7
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Genetic Algorithm에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!