VBA solver doesn't run but 'steps into' custom function

  • Hello everyone,


    Solving my problem will require digging into several layers of issues, so I really appreciate your efforts should you decide to help. I have not used solver in VBA before but due to the amount of recalculations I have to do I must this time. The 'generic' loop is the following:



    If you look at the attached sheet, range D6:X11 contains market prices for options. In Range D13:X18, prices are calculated using my custom function/add-in. The custom function uses data in range d20:x25 as inputs. I would like the solver to match the calculated prices to market prices by changing data in range d20:x25. Here is the function, just in case: (i don't think it's relevant)



    When running the solver sub, the code doesn't execute but steps into the function when the code gets to -->SolverOptions. What am I overlooking? Am I missing several steps? As always, any input and guidence is greatly appreciated.


    thx
    milyenabox

  • Re: VBA solver doesn't run but 'steps into' custom function


    does anyone have any suggestions on how to proceeds?

    "Doubt everything. Find your own light." -- Gautama Buddha

  • Re: VBA solver doesn't run but 'steps into' custom function


    Have you established a reference to the Solver add-in?


    From the help files...

    Quote

    SolverOptions Function
    See Also Example Specifics
    Allows you to specify advanced options for your Solver model. This function and its arguments correspond to the options in the Solver Options dialog box.


    Before you use this function, you must establish a reference to the Solver add-in. With a Visual Basic module active, click References on the Tools menu, and then select the Solver.xla check box under Available References. If Solver.xla doesn't appear under Available References, click Browse and open Solver.xla in the \Office\Library subfolder.

    If I've been helpful, let me know. If I haven't, let me know that too. 

  • Re: VBA solver doesn't run but 'steps into' custom function


    yes, that was the first thing I checked when I tried to figure out the issue...


    It must be something with the syntax...


    I think because the cells contain the 'gk' custom function instead of formulas the syntax is not properly written....


    I am sure we can crack this...help me out fellas

    "Doubt everything. Find your own light." -- Gautama Buddha

  • Re: VBA solver doesn't run but 'steps into' custom function


    just bumping it up so people will see it..don't want this thread to sink. I need to find a solution to my problem, so hopefully someone can help. thanks

    "Doubt everything. Find your own light." -- Gautama Buddha

  • Re: VBA solver doesn't run but 'steps into' custom function


    Hi milyenabox,


    Not sure I fully understand what you a trying to do but the revised routine will at least now run.


    No need for the Range() reference as your variables are already ranges.

    [h4]Cheers
    Andy
    [/h4]

  • Re: VBA solver doesn't run but 'steps into' custom function


    Thanks for the response Andy.... one can always count on Andy.


    But unfortunately, eventhough the code does execute the routine none of the values are changing. Without going into 'option pricing and other fun stuff', in a nutshell this is what should happen:


    All the values (implied volatilites) in range D20: X25 should be changed by the solver so all values in range D6:X11 and D13:X18 match. In other words D6 should equal D13, E6 should equal E13 etc...but it's not happenning. I am not sure what the solver does when it runs.


    Any ideas?


    Let me know if you need more info.

    "Doubt everything. Find your own light." -- Gautama Buddha

  • Re: VBA solver doesn't run but 'steps into' custom function


    Try this revised routine.

    [h4]Cheers
    Andy
    [/h4]

  • Re: VBA solver doesn't run but 'steps into' custom function


    it runs smoothly now, although it takes some time to finish, it works properly.
    it looks like I did not set a number of options for the solver, I will look into these as I don't know what each represent.


    as always, I appreciate the time you spent on this...I am very grateful

    "Doubt everything. Find your own light." -- Gautama Buddha

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!