MATLAB Answers

Errors in Simulated Annealing (simulannealbnd) algorithm.

3 views (last 30 days)
Thegiuso on 25 May 2020
Commented: Thegiuso on 28 May 2020
Hi guys!
I have a problem applying this optimization algorithm to my function.
My function, basically, is a Forex Trading algorithm that takes as input a 10-parameter X vector which must be optimized through simulated annealing, in fact the data on which to perform the trading analysis are passed to the program as global variables .
Once I try to perform the optimization I get this series of errors that I can't understand the source of the problem in order to solve them.
I would be very grateful if you would help me with this.


Sign in to comment.

Accepted Answer

Geoff Hayes
Geoff Hayes on 25 May 2020
Giuseppe - the error message is telling you that the code in your ForexFun is NOT using positive integers or logical values when indexing into arrays at the line
if askW(idx)>askW(idx-X(9)) + min(MFL(idx-1),MFL(idx-2))
Presumably idx is an integer and that askW and MFL are arrays (or is one a function?). Since X is the ten element array and you are subtracting the ninth element from idx, what guarantees are there that idx - X(9) is a positive integer? Are you assuming that this is the case or maybe you need to round up to the nearest integer? Or maybe the error is with something else in this line. I recommend that you put a break point at this l ine or add some logging (via fprintf) to write out the indices before this line of code so that you can get an idea of what is happening.


Show 8 older comments
Thegiuso on 27 May 2020
I get it, I'll try to round values of interest to not to create problems in the simulation.
Thank you so much for your interest in my problem, I appreciate it very much. I appreciate your commitment to helping me understand the various problems, surely now I can proceed safely.
Thank you!
Geoff Hayes
Geoff Hayes on 28 May 2020
Glad that it worked out! It's been years since I've thought about simulated annearling. :)
Thegiuso on 28 May 2020
Yes, in my simulation your solution is acceptable!
I think this is the only way to "impose" integer variables in simulated annealing.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!