Skip to content

Commit

Permalink
Merge 0b238ca into 42ea84d
Browse files Browse the repository at this point in the history
  • Loading branch information
dmichalowicz committed Jul 20, 2017
2 parents 42ea84d + 0b238ca commit 65fd7b5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
20 changes: 19 additions & 1 deletion tests/test_algorithm.py
Expand Up @@ -23,7 +23,7 @@
import logbook
import toolz
from logbook import TestHandler, WARNING
from mock import MagicMock
from mock import MagicMock, patch
from nose_parameterized import parameterized
from six import iteritems, itervalues, string_types
from six.moves import range
Expand Down Expand Up @@ -3526,6 +3526,24 @@ def handle_data(algo, data):
env=self.env)
self.check_algo_succeeds(algo, handle_data)

def test_end_of_day_leverage_enforced(self):
# Patch handle data so that it does not perform account validation.
def mocked_handle_data(self, data):
if self._handle_data:
self._handle_data(self, data)

with patch.object(TradingAlgorithm, 'handle_data', mocked_handle_data):
def handle_data(algo, data):
algo.order(algo.sid(self.sidint), 1)

algo = SetMaxLeverageAlgorithm(
max_leverage=0, sim_params=self.sim_params, env=self.env,
)

# The algo should still fail the account validation because we are
# checking it at the end of the day.
self.check_algo_fails(algo, handle_data)


# FIXME re-implement this testcase in q2
# class TestClosePosAlgo(TestCase):
Expand Down
1 change: 1 addition & 0 deletions zipline/gens/tradesimulation.py
Expand Up @@ -229,6 +229,7 @@ def calculate_minute_capital_changes(dt):
if emission_rate == 'daily':
handle_benchmark(normalize_date(dt))
execute_order_cancellation_policy()
algo.validate_account_controls()

yield self._get_daily_message(dt, algo, algo.perf_tracker)
elif action == BEFORE_TRADING_START_BAR:
Expand Down

0 comments on commit 65fd7b5

Please sign in to comment.