Skip to content

Commit

Permalink
MAINT: Removes unnecessary capital_base arg to TradingAlgorithm (#1677)
Browse files Browse the repository at this point in the history
Capital base is included in the sim params, so we should define the
value there, or use the default.

This change also unifies the default capital base as 1e5, as was
previously defined in algorithm.py.
  • Loading branch information
Andrew Daniels authored Feb 17, 2017
1 parent 60689df commit ba484e5
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 11 deletions.
1 change: 0 additions & 1 deletion tests/test_algorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -4278,7 +4278,6 @@ def test_minutely_delisted_equities(self):
env=env,
sim_params=resources.sim_params,
data_frequency='minute',
capital_base=capital_base,
)

output = algo.run(resources.data_portal)
Expand Down
9 changes: 1 addition & 8 deletions zipline/algorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,6 @@
from zipline.sources.benchmark_source import BenchmarkSource
from zipline.zipline_warnings import ZiplineDeprecationWarning

DEFAULT_CAPITAL_BASE = 1e5


log = logbook.Logger("ZiplineLog")

Expand Down Expand Up @@ -181,8 +179,6 @@ class TradingAlgorithm(object):
tracebacks. default: '<string>'.
data_frequency : {'daily', 'minute'}, optional
The duration of the bars.
capital_base : float, optional
How much capital to start with. default: 1.0e5
instant_fill : bool, optional
Whether to fill orders immediately or on next bar. default: False
equities_metadata : dict or DataFrame or file-like object, optional
Expand Down Expand Up @@ -303,12 +299,9 @@ def __init__(self, *args, **kwargs):
get_calendar("NYSE")
)

# set the capital base
self.capital_base = kwargs.pop('capital_base', DEFAULT_CAPITAL_BASE)
self.sim_params = kwargs.pop('sim_params', None)
if self.sim_params is None:
self.sim_params = create_simulation_parameters(
capital_base=self.capital_base,
start=kwargs.pop('start', None),
end=kwargs.pop('end', None),
trading_calendar=self.trading_calendar,
Expand Down Expand Up @@ -505,7 +498,7 @@ def __repr__(self):
blotter={blotter},
recorded_vars={recorded_vars})
""".strip().format(class_name=self.__class__.__name__,
capital_base=self.capital_base,
capital_base=self.sim_params.capital_base,
sim_params=repr(self.sim_params),
initialized=self.initialized,
slippage=repr(self.blotter.slippage_func),
Expand Down
5 changes: 4 additions & 1 deletion zipline/finance/trading.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
log = logbook.Logger('Trading')


DEFAULT_CAPITAL_BASE = 1e5


class TradingEnvironment(object):
"""
The financial simulations in zipline depend on information
Expand Down Expand Up @@ -128,7 +131,7 @@ def write_data(self, **kwargs):
class SimulationParameters(object):
def __init__(self, start_session, end_session,
trading_calendar,
capital_base=10e3,
capital_base=DEFAULT_CAPITAL_BASE,
emission_rate='daily',
data_frequency='daily',
arena='backtest'):
Expand Down
1 change: 0 additions & 1 deletion zipline/utils/run_algo.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,6 @@ def choose_loader(column):

perf = TradingAlgorithm(
namespace=namespace,
capital_base=capital_base,
env=env,
get_pipeline_loader=choose_loader,
sim_params=create_simulation_parameters(
Expand Down

0 comments on commit ba484e5

Please sign in to comment.