def efficient_risk(self, target_risk, risk_free_rate=<NUM_LIT>, market_neutral=False):
if not isinstance(target_risk, float) or target_risk < <NUM_LIT:0>:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if not isinstance(risk_free_rate, (int, float)):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>args = (self.expected_returns, self.cov_matrix, self.gamma, risk_free_rate)<EOL>target_constraint = {<EOL>"<STR_LIT:type>": "<STR_LIT>",<EOL>"<STR_LIT>": lambda w: target_risk<EOL>- np.sqrt(objective_functions.volatility(w, self.cov_matrix)),<EOL>}<EOL>if market_neutral:<EOL><INDENT>if self.bounds[<NUM_LIT:0>][<NUM_LIT:0>] is not None and self.bounds[<NUM_LIT:0>][<NUM_LIT:0>] >= <NUM_LIT:0>:<EOL><INDENT>warnings.warn(<EOL>"<STR_LIT>",<EOL>RuntimeWarning,<EOL>)<EOL>self.bounds = self._make_valid_bounds((-<NUM_LIT:1>, <NUM_LIT:1>))<EOL><DEDENT>constraints = [<EOL>{"<STR_LIT:type>": "<STR_LIT>", "<STR_LIT>": lambda x: np.sum(x)},<EOL>target_constraint,<EOL>]<EOL><DEDENT>else:<EOL><INDENT>constraints = self.constraints + [target_constraint]<EOL><DEDENT>result = sco.minimize(<EOL>objective_functions.negative_sharpe,<EOL>x0=self.initial_guess,<EOL>args=args,<EOL>method="<STR_LIT>",<EOL>bounds=self.bounds,<EOL>constraints=constraints,<EOL>)<EOL>self.weights = result["<STR_LIT:x>"]<EOL>return dict(zip(self.tickers, self.weights))<EOL>
Calculate the Sharpe-maximising portfolio for a given volatility (i.e max return
for a target risk).

:param target_risk: the desired volatility of the resulting portfolio.
:type target_risk: float
:param risk_free_rate: risk-free rate of borrowing/lending, defaults to 0.02
:type risk_free_rate: float, optional
:param market_neutral: whether the portfolio should be market neutral (weights sum to zero),
                       defaults to False. Requires negative lower weight bound.
:param market_neutral: bool, optional
:raises ValueError: if ``target_risk`` is not a positive float
:raises ValueError: if ``risk_free_rate`` is non-numeric
:return: asset weights for the efficient risk portfolio
:rtype: dict