mirror of
https://github.com/wassname/catalyst.git
synced 2026-08-09 11:50:09 +08:00
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:
+10
-1
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user