Sub-optimum results from Solver

JenniferMurphy

Well-known Member
Joined
Jul 23, 2011
Messages
2,525
Office Version
  1. 365
Platform
  1. Windows
I have some money to invest in an existing portfolio that comprises three mutual funds that I try to keep "balanced" at 50%, 40%, and 10% respectfully. In the past, whenever I've had a chance to add to my investments, I try to "rebalance" the funds. That is, I put more into the funds that are below their intended percentage and less into those that are over.

I have always done this by trial and error. My son told me about the Solver in Excel, so I thought I would see if I could get it to calculate the best possible way to distribute the new money across the existing funds so as to rebalance them as closely as possible to the intended percentages.

I set up a sample portfolio as a learning device and to test the Solver. It contains three funds (A, B, C) with total assets of $1,000. The intended distribution percentages are 50%, 40%, and 10%. I gave each fund a current balance ($400, $400, and $200) so that they are out of balance. I then defined an amount for the new investment to be allocated among the three funds so as to bring them as close to in balance as possible.

It worked for several test cases, but then I came across one where The Solver did not find the best solution.

In the example above, Fund C should have 10% of the total assets. But it has double that ($200 of $1,000). If I increase the total assets by double (by investing an additional $1,000), I can bring the portfolio into balance by allocating all of the new money to Funds A and B. The Solver correctly finds this solution.

But when I increase the new investment to $1,100, it fails. A new investment of $1,000 can be thought of as $1,000 (allocated as above) plus $100 (allocated according to the target percentages, since the portfolio is in balance after the $1,000).

Here's the the sheet for that example:

BCDEFG
3$1,000Current Total Holdings
4$1,100New Investment
5$2,100New Total Holdings
6
7HoldingsFund AFund BFund CTotals
8Target Holding %s50%40%10%100%
9Current Holdings$400.000$400.000$200.000$1,000.000Formulas (Col C)
10Current Holding %s40.000%40.000%20.000%100.000%=C9/$F9
11Current Target Holdings$500.000$400.000$100.000$1,000.000=CurrentTotal*C8
12Current Holding Errors-$100.000$0.000+$100.000$200.000=C9-C11
13Current Holding % Errors-20.000%0.000%+100.000%1.2000=(C9/C11)-1
14New Target Holdings$1,050.000$840.000$210.000$2,100.000=NewTotal*C8
15New Investments$687.499$402.501$10.000$1,100.000Solver
16New Holdings$1,087.499$802.501$210.000$2,100.000=C9+C15
17New Holding %s51.786%38.214%10.000%100.000%=C16/$F16
18New Holding Errors-$37.499+$37.499-$0.000$74.999=C14-C16
19New Holding % Errors+3.5714%-4.4642%+0.0000%0.0804=(C16/C14)-1

<tbody>
</tbody>

The Solver target cell is F19, which is the sum of the absolute values of the percentage differences between the actual holdings and the balanced holdings. It is displayed as a number, not a percentage, because of the absolute value.

The Solver (Changing) cells are C15:E15, which are the amount allocated to each fund.

The criteria are that the new find balances must be at least at large as the old ones and all of the new money must be invested.

This may not be clear given the restrictions on this board on attachments, so I've created a PDF explaining what I did in detail. I uploaded it to this Dropbox page:

https://www.dropbox.com/sh/r5mxhfttv29ucpj/AABw-B4VJsOBTsFD-_5KNqyba?dl=0

I would like to know if my Solver setup is correct and, if not, how to fix it.

If it is and the problem has to do with the initial conditions (guesses), I would like to know how to choose better initial conditions.

Thanks
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
Hi,

Thanks for the puzzle!

I had not used Solver until I came across your question. At first I thought it must be easy to do analytically. Then the reality of linear programming dawned :(

Eventually I made Solver do what I wanted it to. I am going to try and describe what I did in words. I am not sure if it solves all your problems but it does produce answers and does not seem to be dependent on initial conditions. The spreadsheet looks like this:


A
B
C
D
E
F
1
400
400
200
1000
start
2
50.00%
40.00%
10.00%
%
3
1100
650
440
10
0
split
4
1050
840
210

answer
5
1050
840
210

ideal
6
1050
840
210
check

<tbody>
</tbody>

My starting investments are in B1:D1.
E1 is the total of that row and is used later.
Row 2 has the desired percentages.
A3 is the total new amount to be invested.
B3:D3 are the rows calculated by solver.
E3 has the formula =A3-SUM(B3:D3) so goes to zero when the answer is arrived at.
Row 4 is the starting values in row 1 added to the figures calculated by Solver so is the final amounts in the funds.
Row 5 is the optimum answer based on the total amount of money in the system (i.e. starting values plus new investment). The formula in B5 is: =SUM($E$1,$A$3)*B2 and should be dragged across to C5 and D5.
Row 6 has some deviousness. B6 contains: =IF(B1>B5,B1,B5) So, if the starting value in the fund is greater than the optimum value then the starting value is used as the target. On the other hand, if the optimum target is larger than the starting value then the optimum vaue is used. The formula in B6 is copied across to C6 and D6.

Solver has its Objective as cell E3 and its target value is 0.
Changing values: B3:D3.
Constraints:
B4 <= B6
C4 <= C6
D4 <= D6

Make Unconstrained Variables Non-Negative is ticked.

I hope this helps.
 
Upvote 0
Rick,

Your solution works. I cannot figure out why mine doesn't. Any clues?

Thanks

PS: I used =max(B1,B5) instead of your IF statement. Any reason that is not better (at least clearer)?
 
Last edited:
Upvote 0
Good news!

Thanks for the feedback.

I think I prefer max() as well. Never having used Solver before I really struggled with working out how to do it. I made several abortive attempts before I could make something hang together. I knew a question had to be asked about which was the larger so my mind thought: IF. I did think there might be other questions but it turned out not. So, yes, use max().

I am sorry but your solution looked far too long and I had enough trouble with mine so I will have to leave the "failure investigation" to you.

Regards,
 
Upvote 0
This is a rising tide distribution with renaming of the inputs; it doesn't require Solver:

C​
D​
E​
F​
G​
H​
I​
7​
5. New Investment
8​
$ 1,100.00
9​
10​
Total​
Total Value​
Total Allocated​
11​
100​
$ 1,000.00​
$ 1,100.00​
12​
13​
1. Name
2. Desired Ratio
3. Current Value
Prior % Recovery​
Breakpts​
6. Investment Distribution
7. New Ratio
14​
Fund A
50
$ 400
800.0%​
$ -​
$ 650.00
50.0%
15​
Fund B
40
$ 400
1000.0%​
$ 100.00​
$ 440.00
40.0%
16​
Fund C
10
$ 200
2000.0%​
$ 1,000.00​
$ 10.00
10.0%
There's a workbook at https://app.box.com/s/a03b2051a19e8006280e.
 
Upvote 0
"rising tide distribution"

Thank you for bringing that to my attention. I had not heard of it before.

However, as part of my puzzling, I did go through a stage where I had normalised the three funds such that 50, 40 and 10 would all be the same height. So, the wrong percentages would all be different values. Then I thought of the resulting figures as rods of different lengths. I bundled the rods together and realised that putting them in water and increasing the level was the solution I needed. But I could not figure out how to do it!

Good to know that I was on the right path and that greater minds can solve it.
 
Upvote 0
Forgive me, but I'm struggling to understand why the solution requires Solver or any third-party product. Isn't it as simple as the following table?


A
B
C
D
E
1

Fund A Fund B Fund CTOTAL
2
Target %50%40%10%
3
Current Holding4004002001000
4
Change Holding


1100
5
Target Holding10508402102100
6
Change Holding65044010

<tbody>
</tbody>

Formulas:
E3: =SUM(B3:D3)
E5: =SUM(E3:E4)
B5: =$E$5*B2
B6: =B5-B3

Copy B5 into C5:D5, and copy B6 into C6:D6.

E4 can be a positive or negative number.

PS.... Of course, it would be prudent to add round formulas in order to fit real-world constraints. If that is the challenge, I can offer simple solutions.
 
Last edited:
Upvote 0
The criteria are that the new fund balances must be at least at large as the old ones and all of the new money must be invested.

Change E4 to something less than $1000:

A​
B​
C​
D​
E​
1​
Fund A​
Fund B​
Fund C​
TOTAL​
2​
Target %
50%​
40%​
10%​
3​
Current Holding
$400​
$400​
$200​
$1,000
4​
Change Holding
$900​
5​
Target Holding
$950
$760
$190
$1,900
6​
Change Holding
$550
$360
($10)
 
Last edited:
Upvote 0
Forgive me, but I'm struggling to understand why the solution requires Solver or any third-party product. Isn't it as simple as the following table?


A
B
C
D
E
1

Fund A Fund B Fund CTOTAL
2
Target %50%40%10%
3
Current Holding4004002001000
4
Change Holding


1100
5
Target Holding10508402102100
6
Change Holding65044010

<tbody>
</tbody>

Formulas:
E3: =SUM(B3:D3)
E5: =SUM(E3:E4)
B5: =$E$5*B2
B6: =B5-B3

Copy B5 into C5:D5, and copy B6 into C6:D6.

E4 can be a positive or negative number.

PS.... Of course, it would be prudent to add round formulas in order to fit real-world constraints. If that is the challenge, I can offer simple solutions.

This solution works only under one of two conditions:

  1. When none of the funds have a current holding that exceeds the target holding including the new investment.
  2. When selling shares is an acceptable option.

Option #2 is not acceptable to me.

Using these initial conditions, your solution will only work for any new investment of at least $1,000. If you plug in anything less than that, the value in D6 will be negative, which means selling shares, which I do not want to do.

If you plug in $500, D6 will be -$50. If you plug in $0, D6 will be -$100.
 
Upvote 0
This solution works only under one of two conditions:

  1. [....]
  2. When selling shares is an acceptable option.
Option #2 is not acceptable to me.

Sorry, I overlooked that limitation, and I misread your goal out of context ("put more into the funds that are below their intended percentage and less into those that are over").
 
Upvote 0

Forum statistics

Threads
1,214,570
Messages
6,120,297
Members
448,954
Latest member
EmmeEnne1979

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