crams
crams

Reputation: 325

Excel solver, variable cell to change adjusts data set

I am new to excel solver and I'm trying use it for what I think fairly simple task but it just won't work.

I have 3 columns as follows:

%CHNG   |   PnL  |  Criteria met
  1     |    1   |      1         
 .5     |    2   |      2         
  2     |   -1   |      -1         
  3     |    6   |      6         
 -1     |   .5   |                
-.2     |   -5   |               

and the following 2 cells:

Criteria:   0

Total: =sum of criteria met column

When the number in the 'criteria' cell is changed the value in the 'criteria met' column is posted from the PnL column only if the value in the '%CHNG' column is greater than the value in the 'criteria' cell using an if statement.

The 'total' cell is then the sum of the 'Criteria met' column. (The PnL values that are greater than the criteria value)

I am trying to get solver to maximize the 'Total' cell, by changing the value in the 'criteria' cell, however everytime I try this it leaves the criteria cell unchanged and claims a solution has been found. No matter what value I initially have in the criteria cell the solver claims that is the solution when it is run.

Is there any way to get this to work? preferably without VBA

Thank you

Upvotes: 0

Views: 1349

Answers (3)

xidgel
xidgel

Reputation: 3145

Here's a way to get the maximum over a range. This is called the Maximum Subarray Problem see here.

As before I assume that your %CHNG and PnL data in A2:B7. First you'll need to sort the data based on %CHNG. Column D will hold "maximum ending here" and column E will hold "maximum so far". We'll also have "First" in column F and "Last" in column G --- these are the first and last values of %CHNG that correspond to the maximum sum.

In D2 through G2 enter these formulas:

=B2
=B2
=A2
=A2

Now in D3 through G3 enter these formulas:

=IF(D2+B3>=B3,D2+B3,B3)
=MAX(D3,E2)
=IF(D2+B3>=B3,F2,A3)
=IF(E3=D3,A3,G2)

Copy/paste those formulas down to the end of your data. Cell E7 gives the maximum sum. Cells F7 and G7 give the values of %CHNG over which PnL is summed to get the maximum sum.

Hope this helps.

Upvotes: 1

kindoflost
kindoflost

Reputation: 91

If you want to do it with Solver, then use the "Evolutionary" Solver and not the default "Simplex LP" Solver.
And cell C2 should be
=IF(A2>=criteria,B2,"")
etc
If the Solver wants the variables bounded just limit "criteria" to between -100 and 100.
HTH

Upvotes: 1

xidgel
xidgel

Reputation: 3145

A way to do this without Solver: With your %CHNG and PnL data in A2:B7, in D2 use this formula to create a score if Criteria equals A2:

=SUM(IF($A$2:$A$7>A2,$B$2:$B$7,0))

(entered as an array formula: CTRL-SHIFT-ENTER). Copy/paste that formula into D3:D7 to get a score for the other %CHNG values. For this set of data, this gives a max score of 8 when %CHNG is -0.2.

A formula to get the max of all the scores is:

=MAX(D2:D7)

And a formula to get the %CHNG value associated with the max is:

=INDEX(A2:A7,MATCH(MAX(D2:D7),D2:D7,0))

Hope that helps.

Upvotes: 1

Related Questions