HOME FORUMS BROKERS SOFTWARE BOOKS CONTACT US
Elite Trader Your Account  •  Become a Member  •  Help  •  Search    
    Forums ›› Technically Speaking ›› Programming ›› Vectorizing Nested FOR Loops  


Post A Reply
    
wfeagin3
 

Registered: Jul 2012
Posts: 7

 

09-10-12 01:24 AM

I am not a very experienced programmer, so I was hoping to get some useful feedback from this forum. I am coding in matlab and can code to accomplish what I need to do. It probably is not the most efficient coding, but I thought I would give it a shot to see what I could do.

I am trying to create a backtesting program in Matlab where I am doing a parameter sweep of 8 variables for a function by using a set of 8 nested for-loops.

It works fine. But the nested for-loops is a bottle-neck so it takes a very long time for the program to generate results. And it is only using 1 processor when I use nested for-loops.

I believe that I can use all processors if I vectorize my code and get rid of the for-loops entirely which would increase the run time drastically. However, I've tried to vectorize it myself with no luck. Here is the basic layout of the nested for-loops.

for a = 1:5;
for b = 1:6;
for c = 1:7;
for d = 1:8;
for e = 1:9;
for f = 1:10;
for g = 1:11;
for h = 1:12;
[value(:,a,b,c,d,e,f,g,h] = function(input,input1(a),input2(b),input3(c),input4(d),input5(e),input6(f),input7(g),input8(h));
end
end
end
end
end
end
end
end

Any help would be greatly appreciated! Thanks in advance!

    Edit/Delete Quote Complain
NYDreamer
 

Registered: Feb 2010
Posts: 42

 

09-10-12 08:51 AM

You should be making an 8-dimensional matrix (that's what vectorization means, building vectors and matrices) and apply your function to that. This operation will be a 1000 times faster that way.

http://www.mathworks.com/help/matla....html#br8fs0d-1

    Edit/Delete Quote Complain
wfeagin3
 

Registered: Jul 2012
Posts: 7

 

09-10-12 10:44 PM


Quote from NYDreamer:

You should be making an 8-dimensional matrix (that's what vectorization means, building vectors and matrices) and apply your function to that. This operation will be a 1000 times faster that way.

http://www.mathworks.com/help/matla....html#br8fs0d-1




Thanks for the reply!

I've seen all the matlab examples and have done a thorough search online of vectorization for nested for-loops. However, I haven't been able to figure out the code need to vectorize 8 for-loops.

I have visited the link above and seen it before, but I still can't figure it out. My programming experience is limited so I am not an experienced programmer in the slightest.

I need a straight forward way that is dumbed down for my level of understanding and programming.

Thanks!

    Edit/Delete Quote Complain
    
Post A Reply


Receive an email whenever a new post is added to this thread by subscribing to it.
 
Rate This Thread:

Forum Jump:
 

 

   Conduct Rules  -  Privacy Policy  -  Day Trader -  Day Trader Forum -  Best Trading Software -  Sitemap Copyright © 2013, Elite Trader. All rights reserved.    
 
WHILE YOU'RE HERE, TAKE A MINUTE TO VISIT SOME OF OUR SPONSORS:
Advantage Futures
Futures Brokerage & Clearing
AMP Global Clearing
Futures and FX Trading
Bright Trading
Professional Equities Trading
CTS
Futures Trading Software
DaytradingBias.com
Professional Trading Analytics
ECHOtrade
Professional Trading Firm
eSignal
Trading Software Provider
FXCM
Forex Trading Services
Global Futures
Futures, Options & FX Trading
Interactive Brokers
Pro Gateway to World Markets
JC Trading Group
Direct Access Trading
MB Trading
Direct Access Trading
MultiCharts
Trading Software Provider
NinjaTrader
Trading Software Provider
OANDA
Currency Trading
optionshouse
Option Trading & Education
Questrade
Canada's #1 Online Broker
Rithmic
Futures Trade Execution Platform
SpeedTrader
Direct Access Trading
SpreadProfessor
Spread Trading Instruction
thinkorswim by TD Ameritrade
Direct Access TradingAdvertisement
TradersStudio
System Building & Backtesting
Trading Technologies
Trading Software Provider
Trend Following
Trading Systems Provider