def optimize(exp_rets, covs):
_cov_inv = np.linalg.inv(covs)        <EOL>_u = np.ones((len(exp_rets)))<EOL>_u_cov_inv = _u.dot(_cov_inv)<EOL>_rets_cov_inv = exp_rets.dot(_cov_inv)<EOL>_m = np.empty((<NUM_LIT:2>, <NUM_LIT:2>))<EOL>_m[<NUM_LIT:0>, <NUM_LIT:0>] = _rets_cov_inv.dot(exp_rets)<EOL>_m[<NUM_LIT:0>, <NUM_LIT:1>] = _u_cov_inv.dot(exp_rets)<EOL>_m[<NUM_LIT:1>, <NUM_LIT:0>] = _rets_cov_inv.dot(_u)<EOL>_m[<NUM_LIT:1>, <NUM_LIT:1>] = _u_cov_inv.dot(_u)<EOL>_m_inv = np.linalg.inv(_m)<EOL>a = _m_inv[<NUM_LIT:0>, <NUM_LIT:0>] * _rets_cov_inv + _m_inv[<NUM_LIT:1>, <NUM_LIT:0>] * _u_cov_inv<EOL>b = _m_inv[<NUM_LIT:0>, <NUM_LIT:1>] * _rets_cov_inv + _m_inv[<NUM_LIT:1>, <NUM_LIT:1>] * _u_cov_inv<EOL>least_risk_ret = _m[<NUM_LIT:0>, <NUM_LIT:1>] / _m[<NUM_LIT:1>, <NUM_LIT:1>]<EOL>return a, b, least_risk_ret<EOL>
Return parameters for portfolio optimization.

Parameters
----------
exp_rets : ndarray
    Vector of expected returns for each investment..
covs : ndarray
    Covariance matrix for the given investments.

Returns
---------
a : ndarray
    The first vector (to be combined with target return as scalar)
    in the linear equation for optimal weights.
b : ndarray
    The second (constant) vector in the linear equation for
    optimal weights.
least_risk_ret : int
    The return achieved on the portfolio that combines the given
    equities so as to achieve the lowest possible risk.

Notes
---------
*   The length of `exp_rets` must match the number of rows
    and columns in the `covs` matrix.
*   The weights for an optimal portfolio with expected return
    `ret` is given by the formula `w = ret * a + b` where `a`
    and `b` are the vectors returned here. The weights `w` for
    the portfolio with lowest risk are given by `w = least_risk_ret * a + b`.
*   An exception will be raised if the covariance matrix
    is singular or if each prospective investment has the
    same expected return.