🌐
Cvxpy
cvxpy.org › examples
Examples -
⏱️ Help us benchmark CVXPY solvers! Contribute problems and results to the Solver Benchmarks project. 📅 The CVXPY developers are hosting listening sessions to learn more about what you are using CVXPY for and how we can better serve you. These examples show many different ways to use CVXPY.
🌐
Cvxpy
cvxpy.org › tutorial
User Guide -
What is CVXPY? Changing the problem · Infeasible and unbounded problems · Other problem statuses · Vectors and matrices · Constraints · Parameters · Custom Labels · Next steps · Atomic Functions · Operators · Scalar functions · Functions along an axis · Elementwise functions · Vector/matrix functions · Disciplined Convex Programming · Expressions · Sign · Curvature · Curvature rules · Infix operators · Example 1 ·
🌐
CVXPY
cvxpy.org
Cvxpy
CVXPY is an open source Python-embedded modeling language for convex optimization problems. It lets you express your problem in a natural way that follows the math, rather than in the restrictive standard form required by solvers. For example, the following code solves a least-squares problem with box constraints:
🌐
Cvxpy
cvxpy.org › tutorial › advanced › index.html
Advanced Features -
CVXPY now supports N-dimensional expressions. This allows one to define variables, parameters, and constants with arbitrary number of dimensions. This new feature enables users to model problems with multi-dimensional data in a more natural way. In the example below, we consider a problem where the goal is to optimize the usage of a resource across multiple locations, days, and hours.
🌐
Cvxpy
cvxpy.org › tutorial › intro › index.html
What is CVXPY? -
import cvxpy as cp import numpy as np # Create variables weights = cp.Variable(3, name="weights") # Create constraints with custom labels constraints = [ (weights >= 0).set_label("non_negative_weights"), (cp.sum(weights) == 1).set_label("budget_constraint"), (weights <= 0.4).set_label("concentration_limits") ] # Create expressions with custom labels (portfolio example) # Expected returns and covariance (toy data for illustration) mu = np.array([0.08, 0.10, 0.07]) Sigma = np.array([[0.10, 0.02, 0.01], [0.02, 0.08, 0.03], [0.01, 0.03, 0.09]]) expected_return = (mu @ weights).set_label("expected_
🌐
Cvxpy
cvxpy.org › examples › index.html
Examples - CVXPY
⏱️ Help us benchmark CVXPY solvers! Contribute problems and results to the Solver Benchmarks project. 📅 The CVXPY developers are hosting listening sessions to learn more about what you are using CVXPY for and how we can better serve you. These examples show many different ways to use CVXPY.
🌐
GitHub
github.com › cvxpy › cvxpy
GitHub - cvxpy/cvxpy: A Python-embedded modeling language for convex optimization problems. · GitHub
CVXPY is a Python-embedded modeling language for convex optimization problems. It allows you to express your problem in a natural way that follows the math, rather than in the restrictive standard form required by solvers. For example, the following code solves a least-squares problem where the variable is constrained by lower and upper bounds:
Starred by 6.1K users
Forked by 1.2K users
Languages   C++ 63.7% | Python 34.7% | C 1.4% | Linear Programming 0.1% | Makefile 0.1% | Shell 0.0%
🌐
Cvxpy
cvxpy.org › examples › basic › linear_program.html
Linear program -
For example, we might have \(n\) different products, each constructed out of \(m\) components. Each entry \(A_{ij}\) is the amount of component \(i\) required to build one unit of product \(j\). Each entry \(b_i\) is the total amount of component \(i\) available.
Find elsewhere
🌐
Cvxpy
cvxpy.org › tutorial › index.html
User Guide - CVXPY
What is CVXPY? Changing the problem · Infeasible and unbounded problems · Other problem statuses · Vectors and matrices · Constraints · Parameters · Atomic Functions · Operators · Scalar functions · Functions along an axis · Elementwise functions · Vector/matrix functions · Disciplined Convex Programming · Expressions · Sign · Curvature · Curvature rules · Infix operators · Example 1 ·
🌐
Cvxpy
cvxpy.org › tutorial › functions › index.html
Atomic Functions -
Indexing drops dimensions while slicing preserves dimensions. For example, x = cvxpy.Variable(5) print("0 dimensional", x[0].shape) print("1 dimensional", x[0:1].shape)
🌐
Cvxpy
cvxpy.org › tutorial › dcp › index.html
Disciplined Convex Programming -
The infix operators +, -, *, / and matrix multiplication @ are treated exactly like functions. The infix operators + and - are affine, so the rules above are used to flag the curvature. For example, expr1 + expr2 is flagged as convex if expr1 and expr2 are convex.
🌐
Cvxpy
cvxpy.org › examples › basic › quadratic_program.html
Quadratic program -
A simple example of a quadratic program arises in finance. Suppose we have \(n\) different stocks, an estimate \(r \in \mathcal{R}^n\) of the expected return on each stock, and an estimate \(\Sigma \in \mathcal{S}^{n}_+\) of the covariance of the returns.
🌐
Snyk
snyk.io › advisor › cvxpy › cvxpy code examples
Top 5 cvxpy Code Examples | Snyk
# np.log(trAtA) ]) # Add row to matrix A A = spa.vstack((A, spa.csc_matrix(A_temp)), 'csc') # Add bounds on v l = np.log(problem['rho_min'].iloc[0]) u = np.log(problem['rho_max'].iloc[0]) v_l = np.append(v_l, l) v_u = np.append(v_u, u) # # Define CVXPY problem alpha = cvxpy.Variable(n_params) v = cvxpy.Variable(n_problems) constraints = [v_l &lt;= v, v &lt;= v_u] cost = cvxpy.norm(A * alpha - v) objective = cvxpy.Minimize(cost) problem = cvxpy.Problem(objective, constraints) # Solve problem print("Solving problem with CVXPY and GUROBI") problem.solve(solver=cvxpy.MOSEK, verbose=True) print("Solution status: %s" % problem.status) # Get learned alpha alpha_fit = np.asarray(alpha.value).flatten()
🌐
Cvxpy
cvxpy.org › version › 1.2 › examples › index.html
Examples — CVXPY 1.2 documentation
The Basic examples section shows how to solve some common optimization problems in CVXPY.
🌐
Cvxpy
cvxpy.org › examples › applications › OOCO.html
Object Oriented Convex Optimization -
To see the object-oriented approach applied to more complex flow problems, look in the cvxpy/examples/flows/ directory.
🌐
Princeton University
princeton.edu › ~aaa › Public › Teaching › ORF523 › cvxpy_examples.ipynb
cvxpy_examples.ipynb
ckages (from cvxpy) (1.11.2)\n", "Requirement already satisfied: setuptools>65.5.1 in /usr/local/lib/python3.10/dist-packages (from cvxpy) (67.7.2)\n", "Requirement already satisfied: qdldl in /usr/local/lib/python3.10/dist-packages (from osqp>=0.4.1->cvxpy) (0.1.7.post0)\n" ] } ] }, { "cell_type": "markdown", "source": [ "You will generally just need to run pip install for cvxpy.
🌐
Readthedocs
ajfriendcvxpy.readthedocs.io › en › latest › examples
Examples — CVXPY 0.2.25 documentation - Read the Docs
These examples show many different ways to use CVXPY. The Basic Examples section shows how to solve some common optimization problems in CVXPY.
🌐
GitHub
github.com › cvxpy › cvxpy › blob › master › examples › notebooks › WWW › sparse_solution.ipynb
cvxpy/examples/notebooks/WWW/sparse_solution.ipynb at master · cvxpy/cvxpy
A Python-embedded modeling language for convex optimization problems. - cvxpy/examples/notebooks/WWW/sparse_solution.ipynb at master · cvxpy/cvxpy
Author   cvxpy
🌐
Kaggle
kaggle.com › code › marketneutral › cvxpy-portfolio-optimization-example
[CVXPY] Portfolio Optimization Example
Checking your browser before accessing www.kaggle.com · Click here if you are not automatically redirected after 5 seconds