Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Following code from referred textbook #1

Open
michellebieger opened this issue Aug 10, 2018 · 7 comments
Open

Following code from referred textbook #1

michellebieger opened this issue Aug 10, 2018 · 7 comments

Comments

@michellebieger
Copy link

Heya, thanks for creating your GRG and making it available!

I'm curious; in your constraint you have two equations rather than an equation and an equality. If I follow the referred textbook correctly, problems with a constraint in the form of an equation and an equality should be able to be solved with the GRG method, too. Did you have an equality constraint in your original problem to go with the equations you have in code, and where did you express that?

@ishank011
Copy link
Owner

Hi,

As mentioned in the reference book, the Generalized Reduced Gradient method is used to solve nonlinear equality-constrained optimization problems, which are of the form 'Minimize f(x), subject to h_k(x) = 0, k = 1, 2, 3..., K'

In the code, f(x) is defined on line 12 (fx = 4 * x1 - x2 ** 2 + x3 ** 2 - 12) and the equality constraints are defined as hxs on line 13 (hxs = [20 - x1 ** 2 - x2 ** 2, x1 + x3 - 7] ). Here the two constraints are 20 - x1^2 - x2^2 = 0 and x1 + x3 - 7 = 0.

Hope this helps!

@michellebieger
Copy link
Author

michellebieger commented Aug 13, 2018 via email

@ishank011
Copy link
Owner

Hi,

The code would work for as many constraints as possible. For only a single constraint, just update hxs as a single-member list, for example, hxs = [20 - x1 ** 2 - x2 ** 2]. You can add more than two constraints as well.

@michellebieger
Copy link
Author

michellebieger commented Aug 22, 2018 via email

@ishank011
Copy link
Owner

That might be due to the fact that it may have attained its optimum value in one iteration itself, or may be that the hyperparameter values, i.e., alpha, gamma, in this case, need to be tuned for the optimization iterations to proceed.

@michellebieger
Copy link
Author

michellebieger commented Aug 23, 2018 via email

@plemphers
Copy link

Hi,
Im working on a project for a hedge fund where we need to replace the Solver function in Excel to calculate the optimal holding per security for a bunch of securities in a portfolio to achieve a target portfolio return based on stock level lower and upper boundaries and portfolio level boundary constraints using generalized reduced gradient nonlinear.

I have attached a csv file showing sample data and my goal it to calculate the Optimized Hldg in col J (in the attached Sample.zip) using your code.

Would you be able to kindly assist?

PS: Im a business analyst and am way out of my depth here. Am really seeking a black box solution to feed inputs and get outputs that match the current Excel Solver Add-in.

Thank you
sample.zip

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants