mirror of
https://github.com/wassname/catalyst.git
synced 2026-06-30 23:44:45 +08:00
BUG: Fixes handling of CLOSE_POSITION events for Futures
This commit is contained in:
@@ -1290,6 +1290,7 @@ class TestAccountControls(TestCase):
|
||||
algo = SetMaxLeverageAlgorithm(1)
|
||||
self.check_algo_succeeds(algo, handle_data)
|
||||
|
||||
|
||||
class TestClosePosAlgo(TestCase):
|
||||
|
||||
def setUp(self):
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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]
|
||||
|
||||
Reference in New Issue
Block a user