Genetic Algorithm "WindowSize" Error Message

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 件)

カテゴリ

ヘルプ センター および File ExchangeTransaction Cost Analysis についてさらに検索

質問済み:

2020 年 1 月 10 日

コメント済み:

2020 年 1 月 10 日

Community Treasure Hunt

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

Start Hunting!

Translated by