mirror of
https://github.com/wassname/catalyst.git
synced 2026-09-12 12:12:04 +08:00
Locks down the ability to easily override the algo's portfolio.
Starting down the path of making the portfolio completely read-only with respect to the handle_data in algo. The portfolio should only be changed during the course of running the algorithm by the simulator. This doesn't do a 100% protection, i.e. an algo could use _portfolio, or the set_attr property, but hoping this helps guides algo writing to treat the portfolio as read-only.
This commit is contained in:
@@ -19,6 +19,7 @@ import zipline.utils.simfactory as simfactory
|
||||
from zipline.test_algorithms import (
|
||||
ExceptionAlgorithm,
|
||||
DivByZeroAlgorithm,
|
||||
SetPortfolioAlgorithm,
|
||||
)
|
||||
from zipline.finance.slippage import FixedSlippage
|
||||
from zipline.transforms.utils import StatefulTransform
|
||||
@@ -113,3 +114,25 @@ class ExceptionTestCase(TestCase):
|
||||
|
||||
self.assertEqual(ctx.exception.message,
|
||||
'integer division or modulo by zero')
|
||||
|
||||
def test_set_portfolio(self):
|
||||
"""
|
||||
Are we protected against overwriting an algo's portfolio?
|
||||
"""
|
||||
|
||||
# Simulation
|
||||
# ----------
|
||||
self.zipline_test_config['algorithm'] = \
|
||||
SetPortfolioAlgorithm(
|
||||
self.zipline_test_config['sid']
|
||||
)
|
||||
|
||||
zipline = simfactory.create_test_zipline(
|
||||
**self.zipline_test_config
|
||||
)
|
||||
|
||||
with self.assertRaises(AttributeError) as ctx:
|
||||
output, _ = drain_zipline(self, zipline)
|
||||
|
||||
self.assertEqual(ctx.exception.message,
|
||||
"can't set attribute")
|
||||
|
||||
Reference in New Issue
Block a user