Genetic Algorithm "WindowSize" Error Message

조회 수: 6 (최근 30일)
Andriy Artemyev
Andriy Artemyev 2020년 1월 10일
댓글: Andriy Artemyev 2020년 1월 10일
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
Alan Weiss 2020년 1월 10일
Please show us your ga call and any options that you set.
Alan Weiss
MATLAB mathematical toolbox documentation
Andriy Artemyev
Andriy Artemyev 2020년 1월 10일
Thank you for your response!
I have figured out what the problem is. My parameters are only allowed to have integer values, and I have not made any constraints for them to be integers. Now that I included these constraints, the optimization works!

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Transaction Cost Analysis에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by