ENH: Add flag fill_delay kwarg to TradingAlgorithm.

This commit is contained in:
Thomas Wiecki
2013-07-09 11:38:09 -04:00
committed by Eddie Hebert
parent 8e39af906f
commit 5a58ade0fc
2 changed files with 12 additions and 2 deletions
+7 -2
View File
@@ -40,7 +40,7 @@ from zipline.finance.slippage import (
)
from zipline.finance.commission import PerShare, PerTrade
from zipline.finance.blotter import Blotter
from zipline.finance.constants import ANNUALIZER
from zipline.finance.constants import ANNUALIZER, FILL_DELAYS
import zipline.finance.trading as trading
import zipline.protocol
from zipline.protocol import Event
@@ -87,6 +87,8 @@ class TradingAlgorithm(object):
annualizer : int <optional>
Which constant to use for annualizing risk metrics.
If not provided, will extract from data_frequency.
fill_delay : datetime.timedelta
Delay between placing an order and filling an order.
capital_base : float <default: 1.0e5>
How much capital to start with.
"""
@@ -115,6 +117,8 @@ class TradingAlgorithm(object):
# Override annualizer if set
if 'annualizer' in kwargs:
self.annualizer = kwargs['annualizer']
if 'fill_delay' in kwargs:
self.fill_delay = kwargs['fill_delay']
# set the capital base
self.capital_base = kwargs.pop('capital_base', DEFAULT_CAPITAL_BASE)
@@ -125,7 +129,7 @@ class TradingAlgorithm(object):
self.blotter = kwargs.pop('blotter', None)
if not self.blotter:
self.blotter = Blotter()
self.blotter = Blotter(fill_delay=self.fill_delay)
# an algorithm subclass needs to set initialized to True when
# it is fully initialized.
@@ -431,3 +435,4 @@ class TradingAlgorithm(object):
assert data_frequency in ('daily', 'minute')
self.data_frequency = data_frequency
self.annualizer = ANNUALIZER[self.data_frequency]
self.fill_delay = FILL_DELAYS[self.data_frequency]
+5
View File
@@ -13,6 +13,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from datetime import timedelta
TRADING_DAYS_IN_YEAR = 250
TRADING_HOURS_IN_DAY = 6
MINUTES_IN_HOUR = 60
@@ -21,3 +23,6 @@ ANNUALIZER = {'daily': TRADING_DAYS_IN_YEAR,
'hourly': TRADING_DAYS_IN_YEAR * TRADING_HOURS_IN_DAY,
'minute': TRADING_DAYS_IN_YEAR * TRADING_HOURS_IN_DAY *
MINUTES_IN_HOUR}
FILL_DELAYS = {'daily': timedelta(days=1),
'minute': timedelta(minutes=1)}