Files
catalyst/catalyst/finance/shared.py
T
Conner Fromknecht a38a35d664 Changed zipline -> catalyst import paths
* Updated cython build scripts
 * Updated setup.py to to install catalyst package
 * Updated momentum example to use catalyst package
 * catalyst executable now supports loading pipelines from multiple bundles
2017-06-19 14:43:10 -07:00

45 lines
1.5 KiB
Python

from abc import ABCMeta
from itertools import chain
class FinancialModelMeta(ABCMeta):
"""
This metaclass allows users to create custom slippage and commission models
that support both equities and futures by subclassing the appropriate
individualized classes.
Take for example the following custom model, which subclasses both
EquitySlippageModel and FutureSlippageModel together:
class MyCustomSlippage(EquitySlippageModel, FutureSlippageModel):
def process_order(self, data, order):
...
Ordinarily the first parent class in the MRO ('EquitySlippageModel' in this
example) would override the 'allowed_asset_types' class attribute to only
include equities. However, this is probably not the expected behavior for a
reasonable user, so the metaclass will handle this specific case by
manually allowing both equities and futures for the class being created.
"""
def __new__(mcls, name, bases, dict_):
if 'allowed_asset_types' not in dict_:
allowed_asset_types = tuple(
chain.from_iterable(
marker.allowed_asset_types
for marker in bases
if isinstance(marker, AllowedAssetMarker)
)
)
if allowed_asset_types:
dict_['allowed_asset_types'] = allowed_asset_types
return super(FinancialModelMeta, mcls).__new__(
mcls, name, bases, dict_,
)
class AllowedAssetMarker(FinancialModelMeta):
pass