Allows the capital base of an algorithm to be more easily modified.

By having run() use a capital_base member of the algorithm to
create the trading environment, the capital base should now be
configurable in the instantiation of the algorithm.

e.g.:

```
algo = LowCapitalBaseAlgorithm(capital_base=1000.0):
```
This commit is contained in:
Eddie Hebert
2012-12-04 08:07:40 -05:00
parent 3f94fad97e
commit 3ff3a6964e
2 changed files with 13 additions and 3 deletions
+10 -1
View File
@@ -41,6 +41,8 @@ from zipline.gens.composites import (
from zipline.gens.tradesimulation import TradeSimulationClient as tsc
from zipline import MESSAGES
DEFAULT_CAPITAL_BASE = float("1.0e5")
class TradingAlgorithm(object):
"""Base class for trading algorithms. Inherit and overload
@@ -82,6 +84,9 @@ class TradingAlgorithm(object):
self.slippage = VolumeShareSlippage()
self.commission = PerShare()
# set the capital base
self.capital_base = kwargs.get('capital_base', DEFAULT_CAPITAL_BASE)
# an algorithm subclass needs to set initialized to True
# when it is fully initialized.
self.initialized = False
@@ -175,7 +180,11 @@ class TradingAlgorithm(object):
self.transforms.append(sf)
environment = create_trading_environment(start=start, end=end)
environment = create_trading_environment(
start=start,
end=end,
capital_base=self.capital_base
)
# create transforms and zipline
self.gen = self._create_generator(environment)
+3 -2
View File
@@ -92,7 +92,8 @@ Fetching data from data.treasury.gov
return bm_returns, tr_curves
def create_trading_environment(year=2006, start=None, end=None):
def create_trading_environment(year=2006, start=None, end=None,
capital_base=float("1.0e5")):
"""Construct a complete environment with reasonable defaults"""
benchmark_returns, treasury_curves = load_market_data()
@@ -106,7 +107,7 @@ def create_trading_environment(year=2006, start=None, end=None):
treasury_curves,
period_start=start,
period_end=end,
capital_base=100000.0
capital_base=capital_base
)
return trading_environment