Help me improve the efficiency of my code

Silvrhelm

Board Regular
Joined
Sep 21, 2011
Messages
54
Good morning,

This is a complex problem and part of a much larger model but I have highlighted the section of code that is slowing down my full macro and created a test workbook that has a data sample and the code I am currently using which is linked here: MEGA

To explain what I am doing there are three key parts

1. A matrix that goes from years 0 to 70 and in each year an allocation (adding up to 100%) between 10 asset classes (Matrix Tab)

2. A 2 column list going from years 0 to 70 that maps a number from 1-20 for each year. (Data Map Tab)

3. Underlying data that has 1000 scenarios spanning over 20 years with each year in each scenario having an investment return (Underlying Data). I call these 21000 row columns "Return Streams"

What I am doing is creating a new return stream based on the allocations in the matrix tab that extends out to 70 years per scenario. As the data only goes up to year 20 after that i am repeating a random years returns as per the 2nd column in the Data Map tab.

Right now my code creates an array from the allocation and an array from the underlying data and uses sumproduct to calculate the return. This is looped 70 times for each of the 1000 scenarios.

This takes a few seconds but the actual data runs out to 10000 scenarios and takes about 45 seconds.

I am thinking there is probably a more efficient way to do this with matrices that would speed it up significantly but I cant think through exactly how to do it.

If anyone is so inclined as to take a look at my code and my data and suggest ways to improve the speed I would be extremely grateful.

Thanks
Nick
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
Bad etiquette to bump my own post but this is an interesting problem that I'm sure someone can help with. If there is information missing or something is difficult to understand please let me know so I can explain better.
 
Upvote 0

Forum statistics

Threads
1,215,461
Messages
6,124,955
Members
449,200
Latest member
indiansth

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top