BUG: Fixes handling of CLOSE_POSITION events for Futures

This commit is contained in:
jfkirk
2015-06-11 11:40:54 -04:00
parent 0d7e23857e
commit 3ee3a1226b
3 changed files with 10 additions and 2 deletions
+1
View File
@@ -1290,6 +1290,7 @@ class TestAccountControls(TestCase):
algo = SetMaxLeverageAlgorithm(1)
self.check_algo_succeeds(algo, handle_data)
class TestClosePosAlgo(TestCase):
def setUp(self):
+5
View File
@@ -337,6 +337,11 @@ class PerformanceTracker(object):
self.all_benchmark_returns[midnight] = event.returns
def process_close_position(self, event):
# CLOSE_POSITION events contain prices that must be handled as a final
# trade event
self.process_trade(event)
txn = self.position_tracker.create_close_position_transaction(event)
if txn:
self.process_transaction(txn)
+4 -2
View File
@@ -23,7 +23,7 @@ import pandas as pd
from zipline.sources.data_source import DataSource
from zipline.utils import tradingcalendar as calendar_nyse
from zipline.gens.utils import hash_args
from zipline.finance import trading
from zipline.finance.trading import TradingEnvironment
class RandomWalkSource(DataSource):
@@ -93,7 +93,9 @@ class RandomWalkSource(DataSource):
self.sd = sd
self.sids = self.start_prices.keys()
trading.environment.update_asset_finder(identifiers=self.sids)
TradingEnvironment.instance().update_asset_finder(
identifiers=self.sids
)
self.open_and_closes = \
calendar.open_and_closes[self.start:self.end]