iterative script – solver mimic – circular reference
Im trying to mimic the “Solver” function defining a script which I can run with a button (and not open the solver in my boss’ nose hahaha).
I have two cells with values (“a” and “b”). I want the difference to be zero (a-b=0) or very close, lets say (a-b) <0.01.
Then I have a Rate that by changing its own value, changes values of “a” and “b”. So at some point the rate’s value makes a-b=0 (its a swap model).
So I defined a function “Iter_Rate” which input is that diference “a-b” and I call it DIfAbs.
Then I rename DifAbs (which would be the initial diference between “a” and “b”) as “diference” so i can work in the loop. I define a FixedRate=0, and “increment” that I will add to the FixedRate, since this value, returned as Rate, is the one making “a-b”=0.
I run a while loop while diference >0.01. Then my FixedRate starts at 0 and I add 0.00001 on each loop, and when the while stops (diference <0.01) then I return Fixed Rate (goes to the matrix to fill cell Rate).
The model says “circular reference” obviously, but I dont know how to start the process again so the returned FixedRate goes to Rate, calculates a-b again and then I restart my loop.
here below the script:
double Iter_Rate (double DifAbs)
def double diference=DifAbs
def double FixedRate=0
def double increment=0.00001
while (diference> 0.01)
Any help more than welcome!!!!!!