Genetic Algorithm "WindowSize" Error Message
1 次查看(过去 30 天)
显示 更早的评论
Greetings,
I'm trying for the first time to run a genetic algorithm optimization for an algorithmic trading university project. My fitness function returns a negative sharpe-ratio, and the goal is to find the best set of parameters that minimize the negative sharpe ratio. I have 4 decision parameters. When I try to run the optimization, I get the error message:
"The value of 'WindowSize' is invalid. Expected %K Periods to be integer-valued". Unfortunately, i do not understand the error message, I already searched in Google but did not find a similar problem. I have attached a screenshot with the Error Message. Other than defining the number of variables and the constraints, I have not made any changes to the default settings.
Below you find my objective function. The objective function seems to work properly. I used 2 nestled function I created called "leadlag" and "rsi_strat" which generate trading signals that are either 1 or -1. Any help is greatly appreciated!!!
%%MA + RSI strategy
function[sh]=marsi(decision)
%import Open, High Low Close data
load('data.mat')
%get Closing Prices
Close=data(:,1);
lead=decision(1); % define shorter Moving Average
lag=lead+decision(2); % define longer Moving Average
thresh=decision(3); % define threshhold for Relative strengh Index
frame=decision(4); % define lookbackwindow for Relative strengh Index
%creates trading signal based on moving averages
[sig1,~,~]=leadlag(Close,lead,lag);
%creates trading signal based on RSI
[sig2,~,~]=rsi_strat(Close,thresh,frame);
s=(sig1+sig2)/2; %creates new trading signal if previous signals are equal
r = [0; s(1:end-1).*diff(Close)]; %calculates returns from strategy
sh = -sqrt(250)*sharpe(r,0); % calculates negative sharpe ratio
2 个评论
Alan Weiss
2020-1-10
Please show us your ga call and any options that you set.
Alan Weiss
MATLAB mathematical toolbox documentation
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Financial Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!