Skip to content

Commit

Permalink
pylint fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
enzbus committed Nov 7, 2023
1 parent 6612a74 commit 952fdf1
Show file tree
Hide file tree
Showing 2 changed files with 211 additions and 54 deletions.
26 changes: 26 additions & 0 deletions cvxportfolio/costs.py
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,18 @@ def __init__(self, a=None, pershare_cost=None, b=0., window_sigma_est=None,
self.window_volume_est = window_volume_est
self.exponent = exponent

# these are overwritten by parameters defined below
self.first_term_multiplier = None
self.second_term_multiplier = None

def initialize_estimator(self, universe, trading_calendar):
"""Initialize cvxpy parameters.
:param universe: Trading universe, including cash.
:type universe: pandas.Index
:param trading_calendar: Future (including current) trading calendar.
:type trading_calendar: pandas.DatetimeIndex
"""
if self.a is not None or self.pershare_cost is not None:
self.first_term_multiplier = cp.Parameter(
len(universe)-1, nonneg=True)
Expand Down Expand Up @@ -663,6 +674,9 @@ def simulate(self, t, u, past_returns, current_returns, current_volumes,
current_prices, **kwargs):
"""Simulate transaction cost in cash units.
:raises SyntaxError: If the market returns are not available in the
market data.
:param t: Current timestamp.
:type t: pandas.Timestamp
:param u: Trades vector.
Expand Down Expand Up @@ -726,7 +740,19 @@ def simulate(self, t, u, past_returns, current_returns, current_volumes,
return result

def compile_to_cvxpy(self, w_plus, z, w_plus_minus_w_bm):
"""Compile cost to cvxpy expression.
:param w_plus: Post-trade weights.
:type w_plus: cvxpy.Variable
:param z: Trade weights.
:type z: cvxpy.Variable
:param w_plus_minus_w_bm: Post-trade weights minus benchmark
weights.
:type w_plus_minus_w_bm: cvxpy.Variable
:returns: Cvxpy expression.
:rtype: cvxpy.expression
"""
expression = 0
if self.a is not None or self.pershare_cost is not None:
expression += cp.abs(z[:-1]).T @ self.first_term_multiplier
Expand Down
Loading

0 comments on commit 952fdf1

Please sign in to comment.