diff --git a/bt/backtest.py b/bt/backtest.py index 638280f..d3112d7 100644 --- a/bt/backtest.py +++ b/bt/backtest.py @@ -152,7 +152,7 @@ def __init__( ): if data.columns.duplicated().any(): cols = data.columns[data.columns.duplicated().tolist()].tolist() - raise Exception("data provided has some duplicate column names: \n%s \n" "Please remove duplicates!" % cols) + raise Exception("data provided has some duplicate column names: \n%s \nPlease remove duplicates!" % cols) # we want to reuse strategy logic - copy it! # basically strategy is a template @@ -549,7 +549,7 @@ def plot_histogram(self, statistic="monthly_sharpe", figsize=(15, 5), title=None """ if statistic not in self.r_stats.index: - raise ValueError("Invalid statistic. Valid statistics" "are the statistics in self.stats") + raise ValueError("Invalid statistic. Valid statisticsare the statistics in self.stats") if title is None: title = "%s histogram" % statistic @@ -588,7 +588,7 @@ class RenormalizedFixedIncomeResult(Result): def __init__(self, normalizing_value, *backtests): for backtest in backtests: if not backtest.strategy.fixed_income: - raise ValueError("Cannot apply RenormalizedFixedIncomeResult " "because backtest %s is not on a fixed income " "strategy" % backtest.name) + raise ValueError("Cannot apply RenormalizedFixedIncomeResult because backtest %s is not on a fixed income strategy" % backtest.name) if not isinstance(normalizing_value, dict): normalizing_value = {x.name: normalizing_value for x in backtests} tmp = [pd.DataFrame({x.name: self._price(x.strategy, normalizing_value[x.name])}) for x in backtests] diff --git a/bt/core.py b/bt/core.py index a15cc69..7651f21 100644 --- a/bt/core.py +++ b/bt/core.py @@ -475,7 +475,7 @@ def bidoffer_paid(self): self.root.update(self.now, None) return self._bidoffer_paid else: - raise Exception("Bid/offer accounting not turned on: " '"bidoffer" argument not provided during setup') + raise Exception('Bid/offer accounting not turned on: "bidoffer" argument not provided during setup') @property def bidoffers_paid(self): @@ -487,7 +487,7 @@ def bidoffers_paid(self): self.root.update(self.now, None) return self._bidoffers_paid.loc[: self.now] else: - raise Exception("Bid/offer accounting not turned on: " '"bidoffer" argument not provided during setup') + raise Exception('Bid/offer accounting not turned on: "bidoffer" argument not provided during setup') @property def universe(self): @@ -560,7 +560,7 @@ def setup(self, universe, **kwargs): # strategies as the "price" is just a reference # value and should not be used for capital allocation if self.fixed_income and not self.parent.fixed_income: - raise ValueError("Cannot have fixed income " "strategy child (%s) of non-" "fixed income strategy (%s)" % (self.name, self.parent.name)) + raise ValueError("Cannot have fixed income strategy child (%s) of non-fixed income strategy (%s)" % (self.name, self.parent.name)) # determine if needs paper trading # and setup if so @@ -1286,7 +1286,7 @@ def bidoffers(self): self.update(self.root.now) return self._bidoffers.loc[: self.now] else: - raise Exception("Bid/offer accounting not turned on: " '"bidoffer" argument not provided during setup') + raise Exception('Bid/offer accounting not turned on: "bidoffer" argument not provided during setup') @property def bidoffer_paid(self): @@ -1311,7 +1311,7 @@ def bidoffers_paid(self): self.root.update(self.root.now, None) return self._bidoffers_paid.loc[: self.now] else: - raise Exception("Bid/offer accounting not turned on: " '"bidoffer" argument not provided during setup') + raise Exception('Bid/offer accounting not turned on: "bidoffer" argument not provided during setup') def setup(self, universe, **kwargs): """ @@ -1424,7 +1424,7 @@ def update(self, date, data=None, inow=None): if is_zero(self._position): self._value = 0 else: - raise Exception("Position is open (non-zero: %s) and latest price is NaN " "for security %s on %s. Cannot update node value." % (self._position, self.name, date)) + raise Exception("Position is open (non-zero: %s) and latest price is NaN for security %s on %s. Cannot update node value." % (self._position, self.name, date)) else: self._value = self._position * self._price * self.multiplier @@ -1482,7 +1482,7 @@ def allocate(self, amount, update=True): raise Exception("Cannot allocate capital to a parentless security") if is_zero(self._price) or np.isnan(self._price): - raise Exception("Cannot allocate capital to " "%s because price is %s as of %s" % (self.name, self._price, self.parent.now)) + raise Exception("Cannot allocate capital to %s because price is %s as of %s" % (self.name, self._price, self.parent.now)) # buy/sell # determine quantity - must also factor in commission @@ -1623,7 +1623,7 @@ def transact(self, q, update=True, update_self=True, price=None): return if price is not None and not self._bidoffer_set: - raise ValueError('Cannot transact at custom prices when "bidoffer" has ' "not been passed during setup to enable bid-offer tracking.") + raise ValueError('Cannot transact at custom prices when "bidoffer" has not been passed during setup to enable bid-offer tracking.') # this security will need an update, even if pos is 0 (for example if # we close the positions, value and pos is 0, but still need to do that @@ -1843,7 +1843,7 @@ def update(self, date, data=None, inow=None): if is_zero(self._position): self._coupon = 0.0 else: - raise Exception("Position is open (non-zero) and latest coupon is NaN " "for security %s on %s. Cannot update node value." % (self.name, date)) + raise Exception("Position is open (non-zero) and latest coupon is NaN for security %s on %s. Cannot update node value." % (self.name, date)) else: self._coupon = self._position * coupon diff --git a/setup.py b/setup.py index e903db4..86c75b5 100644 --- a/setup.py +++ b/setup.py @@ -43,7 +43,7 @@ def local_file(filename): "pyprind>=2.11", "pytest", "pytest-cov", - "ruff>=0.5.0,<0.9", + "ruff>=0.5.0,<0.10", "setuptools", "twine", "wheel",