Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update ruff usage, enforce format, update workflows #445

Merged
merged 2 commits into from
Jun 24, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Reformat files
  • Loading branch information
timkpaine committed Jun 24, 2024
commit 8d57f199df688795b9ae7bc17653827266942470
49 changes: 1 addition & 48 deletions bt/algos.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
A collection of Algos used to create Strategy logic.
"""

from __future__ import division

import abc
@@ -26,7 +27,6 @@ def run_always(f):


class PrintDate(Algo):

"""
This Algo simply print's the current date.

@@ -39,7 +39,6 @@ def __call__(self, target):


class PrintTempData(Algo):

"""
This Algo prints the temp data.

@@ -64,7 +63,6 @@ def __call__(self, target):


class PrintInfo(Algo):

"""
Prints out info associated with the target strategy. Useful for debugging
purposes.
@@ -93,7 +91,6 @@ def __call__(self, target):


class Debug(Algo):

"""
Utility Algo that calls pdb.set_trace when triggered.

@@ -109,7 +106,6 @@ def __call__(self, target):


class RunOnce(Algo):

"""
Returns True on first run then returns False.

@@ -192,7 +188,6 @@ def compare_dates(self, now, date_to_compare):


class RunDaily(RunPeriod):

"""
Returns True on day change.

@@ -215,7 +210,6 @@ def compare_dates(self, now, date_to_compare):


class RunWeekly(RunPeriod):

"""
Returns True on week change.

@@ -238,7 +232,6 @@ def compare_dates(self, now, date_to_compare):


class RunMonthly(RunPeriod):

"""
Returns True on month change.

@@ -261,7 +254,6 @@ def compare_dates(self, now, date_to_compare):


class RunQuarterly(RunPeriod):

"""
Returns True on quarter change.

@@ -284,7 +276,6 @@ def compare_dates(self, now, date_to_compare):


class RunYearly(RunPeriod):

"""
Returns True on year change.

@@ -307,7 +298,6 @@ def compare_dates(self, now, date_to_compare):


class RunOnDate(Algo):

"""
Returns True on a specific set of dates.

@@ -332,7 +322,6 @@ def __call__(self, target):


class RunAfterDate(Algo):

"""
Returns True after a date has passed

@@ -359,7 +348,6 @@ def __call__(self, target):


class RunAfterDays(Algo):

"""
Returns True after a specific number of 'warmup' trading days have passed

@@ -388,7 +376,6 @@ def __call__(self, target):


class RunIfOutOfBounds(Algo):

"""
This algo returns true if any of the target weights deviate by an amount greater
than tolerance. For example, it will be run if the tolerance is set to 0.5 and
@@ -433,7 +420,6 @@ def __call__(self, target):


class RunEveryNPeriods(Algo):

"""
This algo runs every n periods.

@@ -473,7 +459,6 @@ def __call__(self, target):


class SelectAll(Algo):

"""
Sets temp['selected'] with all securities (based on universe).

@@ -508,7 +493,6 @@ def __call__(self, target):


class SelectThese(Algo):

"""
Sets temp['selected'] with a set list of tickers.

@@ -542,7 +526,6 @@ def __call__(self, target):


class SelectHasData(Algo):

"""
Sets temp['selected'] based on all items in universe that meet
data requirements.
@@ -611,7 +594,6 @@ def __call__(self, target):


class SelectN(Algo):

"""
Sets temp['selected'] based on ranking temp['stat'].

@@ -668,7 +650,6 @@ def __call__(self, target):


class SelectMomentum(AlgoStack):

"""
Sets temp['selected'] based on a simple momentum filter.

@@ -711,7 +692,6 @@ def __init__(


class SelectWhere(Algo):

"""
Selects securities based on an indicator DataFrame.

@@ -771,7 +751,6 @@ def __call__(self, target):


class SelectRandomly(AlgoStack):

"""
Sets temp['selected'] based on a random subset of
the items currently in temp['selected'].
@@ -831,7 +810,6 @@ def __call__(self, target):


class SelectRegex(Algo):

"""
Sets temp['selected'] based on a regex on their names.
Useful when working with a large universe of different kinds of securities
@@ -858,7 +836,6 @@ def __call__(self, target):


class ResolveOnTheRun(Algo):

"""
Looks at securities set in temp['selected'] and searches for names that
match the names of "aliases" for on-the-run securities in the provided
@@ -905,7 +882,6 @@ def __call__(self, target):


class SetStat(Algo):

"""
Sets temp['stat'] for use by downstream algos (such as SelectN).

@@ -935,7 +911,6 @@ def __call__(self, target):


class StatTotalReturn(Algo):

"""
Sets temp['stat'] with total returns over a given period.

@@ -972,7 +947,6 @@ def __call__(self, target):


class WeighEqually(Algo):

"""
Sets temp['weights'] by calculating equal weights for all items in
selected.
@@ -1004,7 +978,6 @@ def __call__(self, target):


class WeighSpecified(Algo):

"""
Sets temp['weights'] based on a provided dict of ticker:weights.

@@ -1029,7 +1002,6 @@ def __call__(self, target):


class ScaleWeights(Algo):

"""
Sets temp['weights'] based on a scaled version of itself.
Useful for going short, or scaling up/down when using
@@ -1056,7 +1028,6 @@ def __call__(self, target):


class WeighTarget(Algo):

"""
Sets target weights based on a target weight DataFrame.

@@ -1110,7 +1081,6 @@ def __call__(self, target):


class WeighInvVol(Algo):

"""
Sets temp['weights'] based on the inverse volatility Algo.

@@ -1154,7 +1124,6 @@ def __call__(self, target):


class WeighERC(Algo):

"""
Sets temp['weights'] based on equal risk contribution algorithm.

@@ -1241,7 +1210,6 @@ def __call__(self, target):


class WeighMeanVar(Algo):

"""
Sets temp['weights'] based on mean-variance optimization.

@@ -1307,7 +1275,6 @@ def __call__(self, target):


class WeighRandomly(Algo):

"""
Sets temp['weights'] based on a random weight vector.

@@ -1356,7 +1323,6 @@ def __call__(self, target):


class LimitDeltas(Algo):

"""
Modifies temp['weights'] based on weight delta limits.

@@ -1415,7 +1381,6 @@ def __call__(self, target):


class LimitWeights(Algo):

"""
Modifies temp['weights'] based on weight limits.

@@ -1619,7 +1584,6 @@ def __call__(self, target):


class CapitalFlow(Algo):

"""
Used to model capital flows. Flows can either be inflows or outflows.

@@ -1652,7 +1616,6 @@ def __call__(self, target):


class CloseDead(Algo):

"""
Closes all positions for which prices are equal to zero (we assume
that these stocks are dead) and removes them from temp['weights'] if
@@ -1689,7 +1652,6 @@ def __call__(self, target):


class SetNotional(Algo):

"""
Sets the notional_value to use as the base for rebalancing for
:class:`FixedIncomeStrategy <bt.core.FixedIncomeStrategy>` targets
@@ -1718,7 +1680,6 @@ def __call__(self, target):


class Rebalance(Algo):

"""
Rebalances capital based on temp['weights']

@@ -1792,7 +1753,6 @@ def __call__(self, target):


class RebalanceOverTime(Algo):

"""
Similar to Rebalance but rebalances to target
weight over n periods.
@@ -1862,7 +1822,6 @@ def __call__(self, target):


class Require(Algo):

"""
Flow control Algo.

@@ -1984,7 +1943,6 @@ def __call__(self, target):


class ClosePositionsAfterDates(Algo):

"""
Close positions on securities after a given date.
This can be used to make sure positions on matured/redeemed securities are
@@ -2037,7 +1995,6 @@ def __call__(self, target):


class RollPositionsAfterDates(Algo):

"""
Roll securities based on the provided map.
This can be used for any securities which have "On-The-Run" and "Off-The-Run"
@@ -2095,7 +2052,6 @@ def __call__(self, target):


class SelectActive(Algo):

"""
Sets temp['selected'] based on filtering temp['selected'] to exclude
those securities that have been closed or rolled after a certain date
@@ -2121,7 +2077,6 @@ def __call__(self, target):


class ReplayTransactions(Algo):

"""
Replay a list of transactions that were executed.
This is useful for taking a blotter of actual trades that occurred,
@@ -2227,7 +2182,6 @@ def _get_unit_risk(security, data, index=None):


class UpdateRisk(Algo):

"""
Tracks a risk measure on all nodes of the strategy. To use this node, the
``additional_data`` argument on :class:`Backtest <bt.backtest.Backtest>` must
@@ -2298,7 +2252,6 @@ def __call__(self, target):


class PrintRisk(Algo):

"""
This Algo prints the risk data.

Loading