示例#1
0
def MultiAsset(traders=None,
               strategy=None,
               name=None,
               PnL=None,
               timeseries=None):
    from marketsim import rtti
    from marketsim.gen._out._itimeserie import ITimeSerie
    from marketsim.gen._out._isingleassettrader import ISingleAssetTrader
    from marketsim import listOf
    from marketsim.gen._out._imultiassetstrategy import IMultiAssetStrategy
    if traders is None or rtti.can_be_casted(traders,
                                             listOf(ISingleAssetTrader)):
        if strategy is None or rtti.can_be_casted(strategy,
                                                  IMultiAssetStrategy):
            if name is None or rtti.can_be_casted(name, str):
                if PnL is None or rtti.can_be_casted(PnL, float):
                    if timeseries is None or rtti.can_be_casted(
                            timeseries, listOf(ITimeSerie)):
                        return MultiAsset_ListISingleAssetTraderIMultiAssetStrategyStringFloatListITimeSerie(
                            traders, strategy, name, PnL, timeseries)
    raise Exception('Cannot find suitable overload for MultiAsset(' +
                    str(traders) + ':' + str(type(traders)) + ',' +
                    str(strategy) + ':' + str(type(strategy)) + ',' +
                    str(name) + ':' + str(type(name)) + ',' + str(PnL) + ':' +
                    str(type(PnL)) + ',' + str(timeseries) + ':' +
                    str(type(timeseries)) + ')')
示例#2
0
 def typecheck(self):
     from marketsim import listOf
     from marketsim.gen._out._imultiassetstrategy import IMultiAssetStrategy
     from marketsim.gen._out._itimeserie import ITimeSerie
     from marketsim import rtti
     from marketsim.gen._out._isingleassettrader import ISingleAssetTrader
     rtti.typecheck(listOf(ISingleAssetTrader), self.traders)
     rtti.typecheck(IMultiAssetStrategy, self.strategy)
     rtti.typecheck(str, self.name)
     rtti.typecheck(float, self.PnL)
     rtti.typecheck(listOf(ITimeSerie), self.timeseries)
示例#3
0
    def typecheck(self):
        from marketsim import listOf
        from marketsim.gen._out._imultiassetstrategy import IMultiAssetStrategy
        from marketsim.gen._out._itimeserie import ITimeSerie
        from marketsim import rtti
        from marketsim.gen._out._isingleassettrader import ISingleAssetTrader

        rtti.typecheck(listOf(ISingleAssetTrader), self.traders)
        rtti.typecheck(IMultiAssetStrategy, self.strategy)
        rtti.typecheck(str, self.name)
        rtti.typecheck(float, self.PnL)
        rtti.typecheck(listOf(ITimeSerie), self.timeseries)
示例#4
0
def MultiAsset(traders = None,strategy = None,name = None,PnL = None,timeseries = None): 
    from marketsim.gen._out._itimeserie import ITimeSerie
    from marketsim import rtti
    from marketsim.gen._out._imultiassetstrategy import IMultiAssetStrategy
    from marketsim.gen._out._isingleassettrader import ISingleAssetTrader
    from marketsim import listOf
    if traders is None or rtti.can_be_casted(traders, listOf(ISingleAssetTrader)):
        if strategy is None or rtti.can_be_casted(strategy, IMultiAssetStrategy):
            if name is None or rtti.can_be_casted(name, str):
                if PnL is None or rtti.can_be_casted(PnL, float):
                    if timeseries is None or rtti.can_be_casted(timeseries, listOf(ITimeSerie)):
                        return MultiAsset_ListISingleAssetTraderIMultiAssetStrategyStringFloatListITimeSerie(traders,strategy,name,PnL,timeseries)
    raise Exception('Cannot find suitable overload for MultiAsset('+str(traders) +':'+ str(type(traders))+','+str(strategy) +':'+ str(type(strategy))+','+str(name) +':'+ str(type(name))+','+str(PnL) +':'+ str(type(PnL))+','+str(timeseries) +':'+ str(type(timeseries))+')')
示例#5
0
def ChooseTheBest(array=None):
    from marketsim import listOf
    from marketsim import rtti
    if array is None or rtti.can_be_casted(array, listOf(float)):
        return ChooseTheBest_ListFloat(array)
    raise Exception('Cannot find suitable overload for ChooseTheBest(' +
                    str(array) + ':' + str(type(array)) + ')')
示例#6
0
class Remote_IOrderBookITwoWayLinkListITimeSerie(IOrderBook, _Remote_Impl):
    """  to the market by means of a *link* that introduces some latency in information propagation
    """
    def __init__(self, orderbook=None, link=None, timeseries=None):
        from marketsim.gen._out.orderbook._local import Local_StringFloatIntListITimeSerie as _orderbook_Local_StringFloatIntListITimeSerie
        from marketsim.gen._out.orderbook._twowaylink import TwoWayLink_ILinkILink as _orderbook_TwoWayLink_ILinkILink
        from marketsim import rtti
        self.orderbook = orderbook if orderbook is not None else _orderbook_Local_StringFloatIntListITimeSerie(
        )
        self.link = link if link is not None else _orderbook_TwoWayLink_ILinkILink(
        )
        self.timeseries = timeseries if timeseries is not None else []
        rtti.check_fields(self)
        _Remote_Impl.__init__(self)

    @property
    def label(self):
        return repr(self)

    _properties = {
        'orderbook': IOrderBook,
        'link': ITwoWayLink,
        'timeseries': listOf(ITimeSerie)
    }

    def __repr__(self):
        return "%(orderbook)s.name^remote" % self.__dict__
示例#7
0
def SingleAsset(orderBook=None,
                strategy=None,
                name=None,
                amount=None,
                PnL=None,
                timeseries=None):
    from marketsim import rtti
    from marketsim.gen._out._itimeserie import ITimeSerie
    from marketsim.gen._out._iorderbook import IOrderBook
    from marketsim.gen._out._isingleassetstrategy import ISingleAssetStrategy
    from marketsim import listOf
    if orderBook is None or rtti.can_be_casted(orderBook, IOrderBook):
        if strategy is None or rtti.can_be_casted(strategy,
                                                  ISingleAssetStrategy):
            if name is None or rtti.can_be_casted(name, str):
                if amount is None or rtti.can_be_casted(amount, float):
                    if PnL is None or rtti.can_be_casted(PnL, float):
                        if timeseries is None or rtti.can_be_casted(
                                timeseries, listOf(ITimeSerie)):
                            return SingleAsset_IOrderBookISingleAssetStrategyStringFloatFloatListITimeSerie(
                                orderBook, strategy, name, amount, PnL,
                                timeseries)
    raise Exception('Cannot find suitable overload for SingleAsset(' +
                    str(orderBook) + ':' + str(type(orderBook)) + ',' +
                    str(strategy) + ':' + str(type(strategy)) + ',' +
                    str(name) + ':' + str(type(name)) + ',' + str(amount) +
                    ':' + str(type(amount)) + ',' + str(PnL) + ':' +
                    str(type(PnL)) + ',' + str(timeseries) + ':' +
                    str(type(timeseries)) + ')')
示例#8
0
def Array(strategies = None): 
    from marketsim.gen._out._isingleassetstrategy import ISingleAssetStrategy
    from marketsim import listOf
    from marketsim import rtti
    if strategies is None or rtti.can_be_casted(strategies, listOf(ISingleAssetStrategy)):
        return Array_ListISingleAssetStrategy(strategies)
    raise Exception('Cannot find suitable overload for Array('+str(strategies) +':'+ str(type(strategies))+')')
class ChooseTheBest_ListISingleAssetStrategyISingleAssetStrategyIAccountIAccountFloat(
        ISingleAssetStrategy, _ChooseTheBest_Impl):
    """  In some moments of time the most effective strategy
     is chosen and made running; other strategies are suspended.
     It can be considered as a particular case for MultiArmedBandit strategy with
     *corrector* parameter set to *chooseTheBest*
    """
    def __init__(self, strategies=None, account=None, performance=None):
        from marketsim.gen._out.strategy._noise import Noise_IEventSideIObservableIOrder as _strategy_Noise_IEventSideIObservableIOrder
        from marketsim.gen._out.strategy.account.inner._inner_virtualmarket import inner_VirtualMarket_ as _strategy_account_inner_inner_VirtualMarket_
        from marketsim.gen._out.strategy.weight.trader._trader_traderefficiencytrend import trader_TraderEfficiencyTrend_Float as _strategy_weight_trader_trader_TraderEfficiencyTrend_Float
        from marketsim import rtti
        self.strategies = strategies if strategies is not None else [
            _strategy_Noise_IEventSideIObservableIOrder()
        ]
        self.account = account if account is not None else _strategy_account_inner_inner_VirtualMarket_(
        )
        self.performance = performance if performance is not None else _strategy_weight_trader_trader_TraderEfficiencyTrend_Float(
        )
        rtti.check_fields(self)
        _ChooseTheBest_Impl.__init__(self)

    @property
    def label(self):
        return repr(self)

    _properties = {
        'strategies': listOf(ISingleAssetStrategy),
        'account': IFunctionIAccountISingleAssetStrategy,
        'performance': IFunctionIFunctionfloatIAccount
    }

    def __repr__(self):
        return "ChooseTheBest(%(strategies)s, %(account)s, %(performance)s)" % self.__dict__
class MultiArmedBandit_ListISingleAssetStrategyISingleAssetStrategyIAccountIAccountFloatFloatFloatListFloatListFloat(ISingleAssetStrategy,_MultiarmedBandit2_Impl):
    """  In some moments of time the efficiency of the strategies is evaluated
     These efficiencies are mapped into weights using *weight* and *normilizer*
     functions per every strategy and *corrector* for the whole collection of weights
     These weights are used to choose randomly a strategy to run for the next quant of time.
     All other strategies are suspended
    """ 
    def __init__(self, strategies = None, account = None, weight = None, normalizer = None, corrector = None):
        from marketsim import rtti
        from marketsim.gen._out.strategy.weight.trader._trader_traderefficiencytrend import trader_TraderEfficiencyTrend_Float as _strategy_weight_trader_trader_TraderEfficiencyTrend_Float
        from marketsim.gen._out.strategy._noise import Noise_IEventSideIObservableIOrder as _strategy_Noise_IEventSideIObservableIOrder
        from marketsim.gen._out.strategy.account.inner._inner_virtualmarket import inner_VirtualMarket_ as _strategy_account_inner_inner_VirtualMarket_
        from marketsim.gen._out.strategy.weight.f._f_atanpow import f_AtanPow_Float as _strategy_weight_f_f_AtanPow_Float
        from marketsim.gen._out.strategy.weight.array._array_identityl import array_IdentityL_ as _strategy_weight_array_array_IdentityL_
        self.strategies = strategies if strategies is not None else [_strategy_Noise_IEventSideIObservableIOrder()]
        self.account = account if account is not None else _strategy_account_inner_inner_VirtualMarket_()
        self.weight = weight if weight is not None else _strategy_weight_trader_trader_TraderEfficiencyTrend_Float()
        self.normalizer = normalizer if normalizer is not None else _strategy_weight_f_f_AtanPow_Float()
        self.corrector = corrector if corrector is not None else _strategy_weight_array_array_IdentityL_()
        rtti.check_fields(self)
        _MultiarmedBandit2_Impl.__init__(self)
    
    @property
    def label(self):
        return repr(self)
    
    _properties = {
        'strategies' : listOf(ISingleAssetStrategy),
        'account' : IFunctionIAccountISingleAssetStrategy,
        'weight' : IFunctionIFunctionfloatIAccount,
        'normalizer' : IFunctionIFunctionfloatIFunctionfloat,
        'corrector' : IFunctionIFunctionlistOffloatlistOffloat
    }
    def __repr__(self):
        return "MultiArmedBandit(%(strategies)s, %(account)s, %(weight)s, %(normalizer)s, %(corrector)s)" % self.__dict__
示例#11
0
class volumeLevels_IVolumeLevelsIGraphIntIntListFloatInt(ITimeSerie,_VolumeLevels_Impl):
    """  Level of volume V is a price at which cumulative volume of better orders is V
    """ 
    def __init__(self, source , graph = None, _digitsToShow = None, _smooth = None, _volumes = None, _isBuy = None):
        from marketsim.gen._out.veusz._graph import Graph_String as _veusz_Graph_String
        from marketsim import rtti
        self.source = source
        self.graph = graph if graph is not None else _veusz_Graph_String()
        self._digitsToShow = _digitsToShow if _digitsToShow is not None else 4
        self._smooth = _smooth if _smooth is not None else 1
        self._volumes = _volumes if _volumes is not None else [30.0]
        self._isBuy = _isBuy if _isBuy is not None else 1
        rtti.check_fields(self)
        _VolumeLevels_Impl.__init__(self)
    
    @property
    def label(self):
        return repr(self)
    
    _properties = {
        'source' : IFunctionIVolumeLevels,
        'graph' : IGraph,
        '_digitsToShow' : int,
        '_smooth' : int,
        '_volumes' : listOf(float),
        '_isBuy' : int
    }
    def __repr__(self):
        return "%(source)s" % self.__dict__
示例#12
0
def volumeLevels(source=None,
                 graph=None,
                 _digitsToShow=None,
                 _smooth=None,
                 _volumes=None,
                 _isBuy=None):
    from marketsim.gen._out._ifunction._ifunctionivolumelevels import IFunctionIVolumeLevels
    from marketsim.gen._out._igraph import IGraph
    from marketsim import listOf
    from marketsim import rtti
    if source is None or rtti.can_be_casted(source, IFunctionIVolumeLevels):
        if graph is None or rtti.can_be_casted(graph, IGraph):
            if _digitsToShow is None or rtti.can_be_casted(_digitsToShow, int):
                if _smooth is None or rtti.can_be_casted(_smooth, int):
                    if _volumes is None or rtti.can_be_casted(
                            _volumes, listOf(float)):
                        if _isBuy is None or rtti.can_be_casted(_isBuy, int):
                            return volumeLevels_IVolumeLevelsIGraphIntIntListFloatInt(
                                source, graph, _digitsToShow, _smooth,
                                _volumes, _isBuy)
    raise Exception('Cannot find suitable overload for volumeLevels(' +
                    str(source) + ':' + str(type(source)) + ',' + str(graph) +
                    ':' + str(type(graph)) + ',' + str(_digitsToShow) + ':' +
                    str(type(_digitsToShow)) + ',' + str(_smooth) + ':' +
                    str(type(_smooth)) + ',' + str(_volumes) + ':' +
                    str(type(_volumes)) + ',' + str(_isBuy) + ':' +
                    str(type(_isBuy)) + ')')
示例#13
0
class Local_StringFloatIntListITimeSerie(IOrderBook, _Local_Impl):
    """  Maintains two order queues for orders of different sides
    """
    def __init__(self,
                 name=None,
                 tickSize=None,
                 _digitsToShow=None,
                 timeseries=None):
        from marketsim import rtti
        self.name = name if name is not None else "-orderbook-"
        self.tickSize = tickSize if tickSize is not None else 0.01
        self._digitsToShow = _digitsToShow if _digitsToShow is not None else 2
        self.timeseries = timeseries if timeseries is not None else []
        rtti.check_fields(self)
        _Local_Impl.__init__(self)

    @property
    def label(self):
        return repr(self)

    _properties = {
        'name': str,
        'tickSize': float,
        '_digitsToShow': int,
        'timeseries': listOf(ITimeSerie)
    }

    def __repr__(self):
        return "%(name)s" % self.__dict__
示例#14
0
 def typecheck(self):
     from marketsim import rtti
     from marketsim.gen._out._itimeserie import ITimeSerie
     from marketsim import listOf
     rtti.typecheck(str, self.name)
     rtti.typecheck(float, self.tickSize)
     rtti.typecheck(int, self._digitsToShow)
     rtti.typecheck(listOf(ITimeSerie), self.timeseries)
示例#15
0
 def typecheck(self):
     from marketsim import rtti
     from marketsim.gen._out._itimeserie import ITimeSerie
     from marketsim import listOf
     rtti.typecheck(str, self.name)
     rtti.typecheck(float, self.tickSize)
     rtti.typecheck(int, self._digitsToShow)
     rtti.typecheck(listOf(ITimeSerie), self.timeseries)
示例#16
0
 def typecheck(self):
     from marketsim.gen._out._itwowaylink import ITwoWayLink
     from marketsim import listOf
     from marketsim.gen._out._itimeserie import ITimeSerie
     from marketsim import rtti
     from marketsim.gen._out._iorderbook import IOrderBook
     rtti.typecheck(IOrderBook, self.orderbook)
     rtti.typecheck(ITwoWayLink, self.link)
     rtti.typecheck(listOf(ITimeSerie), self.timeseries)
示例#17
0
 def typecheck(self):
     from marketsim.gen._out._itwowaylink import ITwoWayLink
     from marketsim import listOf
     from marketsim.gen._out._itimeserie import ITimeSerie
     from marketsim import rtti
     from marketsim.gen._out._iorderbook import IOrderBook
     rtti.typecheck(IOrderBook, self.orderbook)
     rtti.typecheck(ITwoWayLink, self.link)
     rtti.typecheck(listOf(ITimeSerie), self.timeseries)
 def typecheck(self):
     from marketsim.gen._out._isingleassetstrategy import ISingleAssetStrategy
     from marketsim.gen._out._ifunction._ifunctioniaccount_from_isingleassetstrategy import IFunctionIAccount_from_ISingleAssetStrategy
     from marketsim import listOf
     from marketsim.gen._out._ifunction._ifunctionifunctionfloat_from_iaccount import IFunctionIFunctionfloat_from_IAccount
     from marketsim import rtti
     rtti.typecheck(listOf(ISingleAssetStrategy), self.strategies)
     rtti.typecheck(IFunctionIAccount_from_ISingleAssetStrategy, self.account)
     rtti.typecheck(IFunctionIFunctionfloat_from_IAccount, self.performance)
示例#19
0
 def typecheck(self):
     from marketsim.gen._out._isingleassetstrategy import ISingleAssetStrategy
     from marketsim.gen._out._ifunction._ifunctioniaccount_from_isingleassetstrategy import IFunctionIAccount_from_ISingleAssetStrategy
     from marketsim import listOf
     from marketsim.gen._out._ifunction._ifunctionifunctionfloat_from_iaccount import IFunctionIFunctionfloat_from_IAccount
     from marketsim import rtti
     rtti.typecheck(listOf(ISingleAssetStrategy), self.strategies)
     rtti.typecheck(IFunctionIAccount_from_ISingleAssetStrategy,
                    self.account)
     rtti.typecheck(IFunctionIFunctionfloat_from_IAccount, self.performance)
示例#20
0
def Local(name = None,tickSize = None,_digitsToShow = None,timeseries = None): 
    from marketsim.gen._out._itimeserie import ITimeSerie
    from marketsim import listOf
    from marketsim import rtti
    if name is None or rtti.can_be_casted(name, str):
        if tickSize is None or rtti.can_be_casted(tickSize, float):
            if _digitsToShow is None or rtti.can_be_casted(_digitsToShow, int):
                if timeseries is None or rtti.can_be_casted(timeseries, listOf(ITimeSerie)):
                    return Local_StringFloatIntListITimeSerie(name,tickSize,_digitsToShow,timeseries)
    raise Exception('Cannot find suitable overload for Local('+str(name) +':'+ str(type(name))+','+str(tickSize) +':'+ str(type(tickSize))+','+str(_digitsToShow) +':'+ str(type(_digitsToShow))+','+str(timeseries) +':'+ str(type(timeseries))+')')
示例#21
0
 def typecheck(self):
     from marketsim import rtti
     from marketsim.gen._out._ifunction._ifunctionivolumelevels import IFunctionIVolumeLevels
     from marketsim.gen._out._igraph import IGraph
     from marketsim import listOf
     rtti.typecheck(IFunctionIVolumeLevels, self.source)
     rtti.typecheck(IGraph, self.graph)
     rtti.typecheck(int, self._digitsToShow)
     rtti.typecheck(int, self._smooth)
     rtti.typecheck(listOf(float), self._volumes)
     rtti.typecheck(int, self._isBuy)
 def typecheck(self):
     from marketsim import rtti
     from marketsim.gen._out._ifunction._ifunctionivolumelevels import IFunctionIVolumeLevels
     from marketsim.gen._out._igraph import IGraph
     from marketsim import listOf
     rtti.typecheck(IFunctionIVolumeLevels, self.source)
     rtti.typecheck(IGraph, self.graph)
     rtti.typecheck(int, self._digitsToShow)
     rtti.typecheck(int, self._smooth)
     rtti.typecheck(listOf(float), self._volumes)
     rtti.typecheck(int, self._isBuy)
示例#23
0
def ChooseTheBest(strategies = None,account = None,performance = None): 
    from marketsim.gen._out._ifunction import IFunctionIFunctionfloatIAccount
    from marketsim import rtti
    from marketsim.gen._out._ifunction import IFunctionIAccountISingleAssetStrategy
    from marketsim.gen._out._isingleassetstrategy import ISingleAssetStrategy
    from marketsim import listOf
    if strategies is None or rtti.can_be_casted(strategies, listOf(ISingleAssetStrategy)):
        if account is None or rtti.can_be_casted(account, IFunctionIAccountISingleAssetStrategy):
            if performance is None or rtti.can_be_casted(performance, IFunctionIFunctionfloatIAccount):
                return ChooseTheBest_ListISingleAssetStrategyISingleAssetStrategyIAccountIAccountFloat(strategies,account,performance)
    raise Exception('Cannot find suitable overload for ChooseTheBest('+str(strategies) +':'+ str(type(strategies))+','+str(account) +':'+ str(type(account))+','+str(performance) +':'+ str(type(performance))+')')
示例#24
0
def Remote(orderbook = None,link = None,timeseries = None): 
    from marketsim.gen._out._itimeserie import ITimeSerie
    from marketsim import rtti
    from marketsim.gen._out._itwowaylink import ITwoWayLink
    from marketsim import listOf
    from marketsim.gen._out._iorderbook import IOrderBook
    if orderbook is None or rtti.can_be_casted(orderbook, IOrderBook):
        if link is None or rtti.can_be_casted(link, ITwoWayLink):
            if timeseries is None or rtti.can_be_casted(timeseries, listOf(ITimeSerie)):
                return Remote_IOrderBookITwoWayLinkListITimeSerie(orderbook,link,timeseries)
    raise Exception('Cannot find suitable overload for Remote('+str(orderbook) +':'+ str(type(orderbook))+','+str(link) +':'+ str(type(link))+','+str(timeseries) +':'+ str(type(timeseries))+')')
 def typecheck(self):
     from marketsim.gen._out._isingleassetstrategy import ISingleAssetStrategy
     from marketsim import listOf
     from marketsim.gen._out._itimeserie import ITimeSerie
     from marketsim import rtti
     from marketsim.gen._out._iorderbook import IOrderBook
     rtti.typecheck(IOrderBook, self.orderBook)
     rtti.typecheck(ISingleAssetStrategy, self.strategy)
     rtti.typecheck(str, self.name)
     rtti.typecheck(float, self.amount)
     rtti.typecheck(float, self.PnL)
     rtti.typecheck(listOf(ITimeSerie), self.timeseries)
示例#26
0
 def typecheck(self):
     from marketsim.gen._out._isingleassetstrategy import ISingleAssetStrategy
     from marketsim import listOf
     from marketsim.gen._out._itimeserie import ITimeSerie
     from marketsim import rtti
     from marketsim.gen._out._iorderbook import IOrderBook
     rtti.typecheck(IOrderBook, self.orderBook)
     rtti.typecheck(ISingleAssetStrategy, self.strategy)
     rtti.typecheck(str, self.name)
     rtti.typecheck(float, self.amount)
     rtti.typecheck(float, self.PnL)
     rtti.typecheck(listOf(ITimeSerie), self.timeseries)
示例#27
0
def volumeLevels(source = None,graph = None,_digitsToShow = None,_smooth = None,_volumes = None,_isBuy = None): 
    from marketsim.gen._out._ifunction import IFunctionIVolumeLevels
    from marketsim.gen._out._igraph import IGraph
    from marketsim import listOf
    from marketsim import rtti
    if source is None or rtti.can_be_casted(source, IFunctionIVolumeLevels):
        if graph is None or rtti.can_be_casted(graph, IGraph):
            if _digitsToShow is None or rtti.can_be_casted(_digitsToShow, int):
                if _smooth is None or rtti.can_be_casted(_smooth, int):
                    if _volumes is None or rtti.can_be_casted(_volumes, listOf(float)):
                        if _isBuy is None or rtti.can_be_casted(_isBuy, int):
                            return volumeLevels_IVolumeLevelsIGraphIntIntListFloatInt(source,graph,_digitsToShow,_smooth,_volumes,_isBuy)
    raise Exception('Cannot find suitable overload for volumeLevels('+str(source) +':'+ str(type(source))+','+str(graph) +':'+ str(type(graph))+','+str(_digitsToShow) +':'+ str(type(_digitsToShow))+','+str(_smooth) +':'+ str(type(_smooth))+','+str(_volumes) +':'+ str(type(_volumes))+','+str(_isBuy) +':'+ str(type(_isBuy))+')')
示例#28
0
 def typecheck(self):
     from marketsim.gen._out._isingleassetstrategy import ISingleAssetStrategy
     from marketsim.gen._out._ifunction._ifunctioniaccount_from_isingleassetstrategy import IFunctionIAccount_from_ISingleAssetStrategy
     from marketsim import listOf
     from marketsim.gen._out._ifunction._ifunctionifunctionfloat_from_iaccount import IFunctionIFunctionfloat_from_IAccount
     from marketsim import rtti
     from marketsim.gen._out._ifunction._ifunctionifunctionlistoffloat_from_listoffloat import IFunctionIFunctionlistOffloat_from_listOffloat
     from marketsim.gen._out._ifunction._ifunctionifunctionfloat_from_ifunctionfloat import IFunctionIFunctionfloat_from_IFunctionfloat
     rtti.typecheck(listOf(ISingleAssetStrategy), self.strategies)
     rtti.typecheck(IFunctionIAccount_from_ISingleAssetStrategy, self.account)
     rtti.typecheck(IFunctionIFunctionfloat_from_IAccount, self.weight)
     rtti.typecheck(IFunctionIFunctionfloat_from_IFunctionfloat, self.normalizer)
     rtti.typecheck(IFunctionIFunctionlistOffloat_from_listOffloat, self.corrector)
def SingleAsset(orderBook = None,strategy = None,name = None,amount = None,PnL = None,timeseries = None): 
    from marketsim import rtti
    from marketsim.gen._out._itimeserie import ITimeSerie
    from marketsim.gen._out._iorderbook import IOrderBook
    from marketsim.gen._out._isingleassetstrategy import ISingleAssetStrategy
    from marketsim import listOf
    if orderBook is None or rtti.can_be_casted(orderBook, IOrderBook):
        if strategy is None or rtti.can_be_casted(strategy, ISingleAssetStrategy):
            if name is None or rtti.can_be_casted(name, str):
                if amount is None or rtti.can_be_casted(amount, float):
                    if PnL is None or rtti.can_be_casted(PnL, float):
                        if timeseries is None or rtti.can_be_casted(timeseries, listOf(ITimeSerie)):
                            return SingleAsset_IOrderBookISingleAssetStrategyStringFloatFloatListITimeSerie(orderBook,strategy,name,amount,PnL,timeseries)
    raise Exception('Cannot find suitable overload for SingleAsset('+str(orderBook) +':'+ str(type(orderBook))+','+str(strategy) +':'+ str(type(strategy))+','+str(name) +':'+ str(type(name))+','+str(amount) +':'+ str(type(amount))+','+str(PnL) +':'+ str(type(PnL))+','+str(timeseries) +':'+ str(type(timeseries))+')')
def MultiArmedBandit(strategies=None, account=None, weight=None, normalizer=None, corrector=None):
    from marketsim.gen._out._ifunction._ifunctionifunctionlistoffloat_from_listoffloat import (
        IFunctionIFunctionlistOffloat_from_listOffloat,
    )
    from marketsim import rtti
    from marketsim.gen._out._ifunction._ifunctioniaccount_from_isingleassetstrategy import (
        IFunctionIAccount_from_ISingleAssetStrategy,
    )
    from marketsim.gen._out._ifunction._ifunctionifunctionfloat_from_ifunctionfloat import (
        IFunctionIFunctionfloat_from_IFunctionfloat,
    )
    from marketsim.gen._out._isingleassetstrategy import ISingleAssetStrategy
    from marketsim import listOf
    from marketsim.gen._out._ifunction._ifunctionifunctionfloat_from_iaccount import (
        IFunctionIFunctionfloat_from_IAccount,
    )

    if strategies is None or rtti.can_be_casted(strategies, listOf(ISingleAssetStrategy)):
        if account is None or rtti.can_be_casted(account, IFunctionIAccount_from_ISingleAssetStrategy):
            if weight is None or rtti.can_be_casted(weight, IFunctionIFunctionfloat_from_IAccount):
                if normalizer is None or rtti.can_be_casted(normalizer, IFunctionIFunctionfloat_from_IFunctionfloat):
                    if corrector is None or rtti.can_be_casted(
                        corrector, IFunctionIFunctionlistOffloat_from_listOffloat
                    ):
                        return MultiArmedBandit_ListISingleAssetStrategyISingleAssetStrategyIAccountIAccountFloatFloatFloatListFloatListFloat(
                            strategies, account, weight, normalizer, corrector
                        )
    raise Exception(
        "Cannot find suitable overload for MultiArmedBandit("
        + str(strategies)
        + ":"
        + str(type(strategies))
        + ","
        + str(account)
        + ":"
        + str(type(account))
        + ","
        + str(weight)
        + ":"
        + str(type(weight))
        + ","
        + str(normalizer)
        + ":"
        + str(type(normalizer))
        + ","
        + str(corrector)
        + ":"
        + str(type(corrector))
        + ")"
    )
示例#31
0
def MultiArmedBandit(strategies = None,account = None,weight = None,normalizer = None,corrector = None): 
    from marketsim.gen._out._ifunction._ifunctionifunctionlistoffloat_from_listoffloat import IFunctionIFunctionlistOffloat_from_listOffloat
    from marketsim import rtti
    from marketsim.gen._out._ifunction._ifunctioniaccount_from_isingleassetstrategy import IFunctionIAccount_from_ISingleAssetStrategy
    from marketsim.gen._out._ifunction._ifunctionifunctionfloat_from_ifunctionfloat import IFunctionIFunctionfloat_from_IFunctionfloat
    from marketsim.gen._out._isingleassetstrategy import ISingleAssetStrategy
    from marketsim import listOf
    from marketsim.gen._out._ifunction._ifunctionifunctionfloat_from_iaccount import IFunctionIFunctionfloat_from_IAccount
    if strategies is None or rtti.can_be_casted(strategies, listOf(ISingleAssetStrategy)):
        if account is None or rtti.can_be_casted(account, IFunctionIAccount_from_ISingleAssetStrategy):
            if weight is None or rtti.can_be_casted(weight, IFunctionIFunctionfloat_from_IAccount):
                if normalizer is None or rtti.can_be_casted(normalizer, IFunctionIFunctionfloat_from_IFunctionfloat):
                    if corrector is None or rtti.can_be_casted(corrector, IFunctionIFunctionlistOffloat_from_listOffloat):
                        return MultiArmedBandit_ListISingleAssetStrategyISingleAssetStrategyIAccountIAccountFloatFloatFloatListFloatListFloat(strategies,account,weight,normalizer,corrector)
    raise Exception('Cannot find suitable overload for MultiArmedBandit('+str(strategies) +':'+ str(type(strategies))+','+str(account) +':'+ str(type(account))+','+str(weight) +':'+ str(type(weight))+','+str(normalizer) +':'+ str(type(normalizer))+','+str(corrector) +':'+ str(type(corrector))+')')
示例#32
0
def Local(name=None, tickSize=None, _digitsToShow=None, timeseries=None):
    from marketsim.gen._out._itimeserie import ITimeSerie
    from marketsim import listOf
    from marketsim import rtti
    if name is None or rtti.can_be_casted(name, str):
        if tickSize is None or rtti.can_be_casted(tickSize, float):
            if _digitsToShow is None or rtti.can_be_casted(_digitsToShow, int):
                if timeseries is None or rtti.can_be_casted(
                        timeseries, listOf(ITimeSerie)):
                    return Local_StringFloatIntListITimeSerie(
                        name, tickSize, _digitsToShow, timeseries)
    raise Exception('Cannot find suitable overload for Local(' + str(name) +
                    ':' + str(type(name)) + ',' + str(tickSize) + ':' +
                    str(type(tickSize)) + ',' + str(_digitsToShow) + ':' +
                    str(type(_digitsToShow)) + ',' + str(timeseries) + ':' +
                    str(type(timeseries)) + ')')
示例#33
0
def Remote(orderbook=None, link=None, timeseries=None):
    from marketsim import rtti
    from marketsim.gen._out._itimeserie import ITimeSerie
    from marketsim.gen._out._iorderbook import IOrderBook
    from marketsim.gen._out._itwowaylink import ITwoWayLink
    from marketsim import listOf
    if orderbook is None or rtti.can_be_casted(orderbook, IOrderBook):
        if link is None or rtti.can_be_casted(link, ITwoWayLink):
            if timeseries is None or rtti.can_be_casted(
                    timeseries, listOf(ITimeSerie)):
                return Remote_IOrderBookITwoWayLinkListITimeSerie(
                    orderbook, link, timeseries)
    raise Exception('Cannot find suitable overload for Remote(' +
                    str(orderbook) + ':' + str(type(orderbook)) + ',' +
                    str(link) + ':' + str(type(link)) + ',' + str(timeseries) +
                    ':' + str(type(timeseries)) + ')')
示例#34
0
class ChooseTheBest_ListFloat(IFunctionlistOffloat, _ChooseTheBest_Impl):
    """   having 1 at the index of the maximal element and 0 are at the rest
    """
    def __init__(self, array=None):
        from marketsim import rtti
        self.array = array if array is not None else []
        rtti.check_fields(self)
        _ChooseTheBest_Impl.__init__(self)

    @property
    def label(self):
        return repr(self)

    _properties = {'array': listOf(float)}

    def __repr__(self):
        return "ChooseTheBest(%(array)s)" % self.__dict__
示例#35
0
class IdentityL_ListFloat(IFunctionlistOffloat, _Identity_Impl):
    """ 
    """
    def __init__(self, array=None):
        from marketsim import rtti
        self.array = array if array is not None else []
        rtti.check_fields(self)
        _Identity_Impl.__init__(self)

    @property
    def label(self):
        return repr(self)

    _properties = {'array': listOf(float)}

    def __repr__(self):
        return "IdentityL(%(array)s)" % self.__dict__
示例#36
0
def ChooseTheBest(strategies=None, account=None, performance=None):
    from marketsim.gen._out._ifunction import IFunctionIFunctionfloatIAccount
    from marketsim import rtti
    from marketsim.gen._out._ifunction import IFunctionIAccountISingleAssetStrategy
    from marketsim.gen._out._isingleassetstrategy import ISingleAssetStrategy
    from marketsim import listOf
    if strategies is None or rtti.can_be_casted(strategies,
                                                listOf(ISingleAssetStrategy)):
        if account is None or rtti.can_be_casted(
                account, IFunctionIAccountISingleAssetStrategy):
            if performance is None or rtti.can_be_casted(
                    performance, IFunctionIFunctionfloatIAccount):
                return ChooseTheBest_ListISingleAssetStrategyISingleAssetStrategyIAccountIAccountFloat(
                    strategies, account, performance)
    raise Exception('Cannot find suitable overload for ChooseTheBest(' +
                    str(strategies) + ':' + str(type(strategies)) + ',' +
                    str(account) + ':' + str(type(account)) + ',' +
                    str(performance) + ':' + str(type(performance)) + ')')
示例#37
0
class Array_ListISingleAssetStrategy(ISingleAssetStrategy, _Array_Impl):
    """ 
    """
    def __init__(self, strategies=None):
        from marketsim.gen._out.strategy._noise import Noise_IEventSideIObservableIOrder as _strategy_Noise_IEventSideIObservableIOrder
        from marketsim import rtti
        self.strategies = strategies if strategies is not None else [
            _strategy_Noise_IEventSideIObservableIOrder()
        ]
        rtti.check_fields(self)
        _Array_Impl.__init__(self)

    @property
    def label(self):
        return repr(self)

    _properties = {'strategies': listOf(ISingleAssetStrategy)}

    def __repr__(self):
        return "Array(%(strategies)s)" % self.__dict__
    def typecheck(self):
        from marketsim.gen._out._isingleassetstrategy import ISingleAssetStrategy
        from marketsim.gen._out._ifunction._ifunctioniaccount_from_isingleassetstrategy import (
            IFunctionIAccount_from_ISingleAssetStrategy,
        )
        from marketsim import listOf
        from marketsim.gen._out._ifunction._ifunctionifunctionfloat_from_iaccount import (
            IFunctionIFunctionfloat_from_IAccount,
        )
        from marketsim import rtti
        from marketsim.gen._out._ifunction._ifunctionifunctionlistoffloat_from_listoffloat import (
            IFunctionIFunctionlistOffloat_from_listOffloat,
        )
        from marketsim.gen._out._ifunction._ifunctionifunctionfloat_from_ifunctionfloat import (
            IFunctionIFunctionfloat_from_IFunctionfloat,
        )

        rtti.typecheck(listOf(ISingleAssetStrategy), self.strategies)
        rtti.typecheck(IFunctionIAccount_from_ISingleAssetStrategy, self.account)
        rtti.typecheck(IFunctionIFunctionfloat_from_IAccount, self.weight)
        rtti.typecheck(IFunctionIFunctionfloat_from_IFunctionfloat, self.normalizer)
        rtti.typecheck(IFunctionIFunctionlistOffloat_from_listOffloat, self.corrector)
示例#39
0
class SingleAsset_IOrderBookISingleAssetStrategyStringFloatFloatListITimeSerie(
        ISingleAssetTrader, _SingleAsset_Impl):
    """ 
    """
    def __init__(self,
                 orderBook,
                 strategy=None,
                 name=None,
                 amount=None,
                 PnL=None,
                 timeseries=None):
        from marketsim.gen._out.strategy._noise import Noise_IEventSideIObservableIOrder as _strategy_Noise_IEventSideIObservableIOrder
        from marketsim import rtti
        self.orderBook = orderBook
        self.strategy = strategy if strategy is not None else _strategy_Noise_IEventSideIObservableIOrder(
        )
        self.name = name if name is not None else "-trader-"
        self.amount = amount if amount is not None else 0.0
        self.PnL = PnL if PnL is not None else 0.0
        self.timeseries = timeseries if timeseries is not None else []
        rtti.check_fields(self)
        _SingleAsset_Impl.__init__(self)

    @property
    def label(self):
        return repr(self)

    _properties = {
        'orderBook': IOrderBook,
        'strategy': ISingleAssetStrategy,
        'name': str,
        'amount': float,
        'PnL': float,
        'timeseries': listOf(ITimeSerie)
    }

    def __repr__(self):
        return "%(name)s" % self.__dict__
示例#40
0
def ChooseTheBest(array = None): 
    from marketsim import listOf
    from marketsim import rtti
    if array is None or rtti.can_be_casted(array, listOf(float)):
        return ChooseTheBest_ListFloat(array)
    raise Exception('Cannot find suitable overload for ChooseTheBest('+str(array) +':'+ str(type(array))+')')
示例#41
0
class volumeLevels_IVolumeLevelsIGraphIntIntListFloatInt(
        ITimeSerie, VolumeLevels_Impl):
    """ **Time serie holding volume levels of an asset**
    
     Level of volume V is a price at which cumulative volume of better orders is V
    
    Parameters are:
    
    **source**
    
    **graph**
    
    **_digitsToShow**
    
    **_smooth**
    
    **_volumes**
    
    **_isBuy**
    """
    def __init__(self,
                 source,
                 graph=None,
                 _digitsToShow=None,
                 _smooth=None,
                 _volumes=None,
                 _isBuy=None):
        from marketsim.gen._out.veusz._graph import Graph_String as _veusz_Graph_String
        from marketsim import deref_opt
        self.source = source
        self.graph = graph if graph is not None else deref_opt(
            _veusz_Graph_String())
        self._digitsToShow = _digitsToShow if _digitsToShow is not None else 4
        self._smooth = _smooth if _smooth is not None else 1
        self._volumes = _volumes if _volumes is not None else [30.0]
        self._isBuy = _isBuy if _isBuy is not None else 1
        VolumeLevels_Impl.__init__(self)

    @property
    def label(self):
        return repr(self)

    _properties = {
        'source': IFunctionIVolumeLevels,
        'graph': IGraph,
        '_digitsToShow': int,
        '_smooth': int,
        '_volumes': listOf(float),
        '_isBuy': int
    }

    def __repr__(self):
        return "%(source)s" % dict([(name, getattr(self, name))
                                    for name in self._properties.iterkeys()])

    def bind_ex(self, ctx):
        if self.__dict__.get('_bound_ex', False): return
        self.__dict__['_bound_ex'] = True
        if self.__dict__.get('_processing_ex', False):
            raise Exception('cycle detected')
        self.__dict__['_processing_ex'] = True
        self.__dict__['_ctx_ex'] = ctx.updatedFrom(self)
        if hasattr(self, '_internals'):
            for t in self._internals:
                v = getattr(self, t)
                if type(v) in [list, set]:
                    for w in v:
                        w.bind_ex(self.__dict__['_ctx_ex'])
                else:
                    v.bind_ex(self.__dict__['_ctx_ex'])
        self.source.bind_ex(self._ctx_ex)
        self.graph.bind_ex(self._ctx_ex)

        self.bind_impl(self.__dict__['_ctx_ex'])
        if hasattr(self, '_subscriptions'):
            for s in self._subscriptions:
                s.bind_ex(self.__dict__['_ctx_ex'])
        self.__dict__['_processing_ex'] = False

    def reset_ex(self, generation):
        if self.__dict__.get('_reset_generation_ex', -1) == generation: return
        self.__dict__['_reset_generation_ex'] = generation
        if self.__dict__.get('_processing_ex', False):
            raise Exception('cycle detected')
        self.__dict__['_processing_ex'] = True
        if hasattr(self, '_internals'):
            for t in self._internals:
                v = getattr(self, t)
                if type(v) in [list, set]:
                    for w in v:
                        w.reset_ex(generation)
                else:
                    v.reset_ex(generation)
        self.source.reset_ex(generation)
        self.graph.reset_ex(generation)

        self.reset()
        if hasattr(self, '_subscriptions'):
            for s in self._subscriptions:
                s.reset_ex(generation)
        self.__dict__['_processing_ex'] = False

    def typecheck(self):
        from marketsim import rtti
        from marketsim.gen._out._ifunction._ifunctionivolumelevels import IFunctionIVolumeLevels
        from marketsim.gen._out._igraph import IGraph
        from marketsim import listOf
        rtti.typecheck(IFunctionIVolumeLevels, self.source)
        rtti.typecheck(IGraph, self.graph)
        rtti.typecheck(int, self._digitsToShow)
        rtti.typecheck(int, self._smooth)
        rtti.typecheck(listOf(float), self._volumes)
        rtti.typecheck(int, self._isBuy)

    def registerIn(self, registry):
        if self.__dict__.get('_id', False): return
        self.__dict__['_id'] = True
        if self.__dict__.get('_processing_ex', False):
            raise Exception('cycle detected')
        self.__dict__['_processing_ex'] = True
        registry.insert(self)
        self.source.registerIn(registry)
        self.graph.registerIn(registry)

        if hasattr(self, '_subscriptions'):
            for s in self._subscriptions:
                s.registerIn(registry)
        if hasattr(self, '_internals'):
            for t in self._internals:
                v = getattr(self, t)
                if type(v) in [list, set]:
                    for w in v:
                        w.registerIn(registry)
                else:
                    v.registerIn(registry)
        self.__dict__['_processing_ex'] = False

    def bind_impl(self, ctx):
        VolumeLevels_Impl.bind_impl(self, ctx)

    def reset(self):
        VolumeLevels_Impl.reset(self)
 def typecheck(self):
     from marketsim import rtti
     from marketsim import listOf
     rtti.typecheck(listOf(float), self.array)
示例#43
0
class Local_StringFloatIntListITimeSerie(IOrderBook, Local_Impl):
    """ **Order book for a single asset in a market.**
    
     Maintains two order queues for orders of different sides
    
    Parameters are:
    
    **name**
    
    **tickSize**
    
    **_digitsToShow**
    
    **timeseries**
    """
    def __init__(self,
                 name=None,
                 tickSize=None,
                 _digitsToShow=None,
                 timeseries=None):
        self.name = name if name is not None else "-orderbook-"
        self.tickSize = tickSize if tickSize is not None else 0.01
        self._digitsToShow = _digitsToShow if _digitsToShow is not None else 2
        self.timeseries = timeseries if timeseries is not None else []
        Local_Impl.__init__(self)

    @property
    def label(self):
        return repr(self)

    _properties = {
        'name': str,
        'tickSize': float,
        '_digitsToShow': int,
        'timeseries': listOf(ITimeSerie)
    }

    def __repr__(self):
        return "%(name)s" % dict([(name, getattr(self, name))
                                  for name in self._properties.iterkeys()])

    def bind_ex(self, ctx):
        if self.__dict__.get('_bound_ex', False): return
        self.__dict__['_bound_ex'] = True
        if self.__dict__.get('_processing_ex', False):
            raise Exception('cycle detected')
        self.__dict__['_processing_ex'] = True
        self.__dict__['_ctx_ex'] = ctx.updatedFrom(self)
        if hasattr(self, '_internals'):
            for t in self._internals:
                v = getattr(self, t)
                if type(v) in [list, set]:
                    for w in v:
                        w.bind_ex(self.__dict__['_ctx_ex'])
                else:
                    v.bind_ex(self.__dict__['_ctx_ex'])
        for x in self.timeseries:
            x.bind_ex(self._ctx_ex)
        self.bind_impl(self.__dict__['_ctx_ex'])
        if hasattr(self, '_subscriptions'):
            for s in self._subscriptions:
                s.bind_ex(self.__dict__['_ctx_ex'])
        self.__dict__['_processing_ex'] = False

    def reset_ex(self, generation):
        if self.__dict__.get('_reset_generation_ex', -1) == generation: return
        self.__dict__['_reset_generation_ex'] = generation
        if self.__dict__.get('_processing_ex', False):
            raise Exception('cycle detected')
        self.__dict__['_processing_ex'] = True
        if hasattr(self, '_internals'):
            for t in self._internals:
                v = getattr(self, t)
                if type(v) in [list, set]:
                    for w in v:
                        w.reset_ex(generation)
                else:
                    v.reset_ex(generation)
        for x in self.timeseries:
            x.reset_ex(generation)
        self.reset()
        if hasattr(self, '_subscriptions'):
            for s in self._subscriptions:
                s.reset_ex(generation)
        self.__dict__['_processing_ex'] = False

    def typecheck(self):
        from marketsim import rtti
        from marketsim.gen._out._itimeserie import ITimeSerie
        from marketsim import listOf
        rtti.typecheck(str, self.name)
        rtti.typecheck(float, self.tickSize)
        rtti.typecheck(int, self._digitsToShow)
        rtti.typecheck(listOf(ITimeSerie), self.timeseries)

    def registerIn(self, registry):
        if self.__dict__.get('_id', False): return
        self.__dict__['_id'] = True
        if self.__dict__.get('_processing_ex', False):
            raise Exception('cycle detected')
        self.__dict__['_processing_ex'] = True
        registry.insert(self)
        for x in self.timeseries:
            x.registerIn(registry)
        if hasattr(self, '_subscriptions'):
            for s in self._subscriptions:
                s.registerIn(registry)
        if hasattr(self, '_internals'):
            for t in self._internals:
                v = getattr(self, t)
                if type(v) in [list, set]:
                    for w in v:
                        w.registerIn(registry)
                else:
                    v.registerIn(registry)
        self.__dict__['_processing_ex'] = False

    def bind_impl(self, ctx):
        Local_Impl.bind_impl(self, ctx)

    def reset(self):
        Local_Impl.reset(self)
示例#44
0
 def typecheck(self):
     from marketsim import rtti
     from marketsim.gen._out._isingleassetstrategy import ISingleAssetStrategy
     from marketsim import listOf
     rtti.typecheck(listOf(ISingleAssetStrategy), self.strategies)
class IFunctionIFunctionlistOffloat_from_listOffloat(object):
    _types = [meta.function((listOf(float), ), IFunctionlistOffloat)]
    _types.append(IFunctionobject_from_listOffloat)
    _types.append(IFunctionIFunctionobject_from_listOffloat)
    _types.append(IFunctionIFunctionlistOfobject_from_listOffloat)
    pass
示例#46
0
class Remote_IOrderBookITwoWayLinkListITimeSerie(IOrderBook, Remote_Impl):
    """ **Represent an *orderbook* from point of view of a remote trader connected**
    
     to the market by means of a *link* that introduces some latency in information propagation
    
    Parameters are:
    
    **orderbook**
    
    **link**
    
    **timeseries**
    """
    def __init__(self, orderbook=None, link=None, timeseries=None):
        from marketsim.gen._out.orderbook._local import Local_StringFloatIntListITimeSerie as _orderbook_Local_StringFloatIntListITimeSerie
        from marketsim import deref_opt
        from marketsim.gen._out.orderbook._twowaylink import TwoWayLink_ILinkILink as _orderbook_TwoWayLink_ILinkILink
        self.orderbook = orderbook if orderbook is not None else deref_opt(
            _orderbook_Local_StringFloatIntListITimeSerie())
        self.link = link if link is not None else deref_opt(
            _orderbook_TwoWayLink_ILinkILink())
        self.timeseries = timeseries if timeseries is not None else []
        Remote_Impl.__init__(self)

    @property
    def label(self):
        return repr(self)

    _properties = {
        'orderbook': IOrderBook,
        'link': ITwoWayLink,
        'timeseries': listOf(ITimeSerie)
    }

    def __repr__(self):
        return "%(orderbook)s.name^remote" % dict([(name, getattr(
            self, name)) for name in self._properties.iterkeys()])

    def bind_ex(self, ctx):
        if self.__dict__.get('_bound_ex', False): return
        self.__dict__['_bound_ex'] = True
        if self.__dict__.get('_processing_ex', False):
            raise Exception('cycle detected')
        self.__dict__['_processing_ex'] = True
        self.__dict__['_ctx_ex'] = ctx.updatedFrom(self)
        if hasattr(self, '_internals'):
            for t in self._internals:
                v = getattr(self, t)
                if type(v) in [list, set]:
                    for w in v:
                        w.bind_ex(self.__dict__['_ctx_ex'])
                else:
                    v.bind_ex(self.__dict__['_ctx_ex'])
        self.orderbook.bind_ex(self._ctx_ex)
        self.link.bind_ex(self._ctx_ex)
        for x in self.timeseries:
            x.bind_ex(self._ctx_ex)
        self.bind_impl(self.__dict__['_ctx_ex'])
        if hasattr(self, '_subscriptions'):
            for s in self._subscriptions:
                s.bind_ex(self.__dict__['_ctx_ex'])
        self.__dict__['_processing_ex'] = False

    def reset_ex(self, generation):
        if self.__dict__.get('_reset_generation_ex', -1) == generation: return
        self.__dict__['_reset_generation_ex'] = generation
        if self.__dict__.get('_processing_ex', False):
            raise Exception('cycle detected')
        self.__dict__['_processing_ex'] = True
        if hasattr(self, '_internals'):
            for t in self._internals:
                v = getattr(self, t)
                if type(v) in [list, set]:
                    for w in v:
                        w.reset_ex(generation)
                else:
                    v.reset_ex(generation)
        self.orderbook.reset_ex(generation)
        self.link.reset_ex(generation)
        for x in self.timeseries:
            x.reset_ex(generation)
        self.reset()
        if hasattr(self, '_subscriptions'):
            for s in self._subscriptions:
                s.reset_ex(generation)
        self.__dict__['_processing_ex'] = False

    def typecheck(self):
        from marketsim.gen._out._itwowaylink import ITwoWayLink
        from marketsim import listOf
        from marketsim.gen._out._itimeserie import ITimeSerie
        from marketsim import rtti
        from marketsim.gen._out._iorderbook import IOrderBook
        rtti.typecheck(IOrderBook, self.orderbook)
        rtti.typecheck(ITwoWayLink, self.link)
        rtti.typecheck(listOf(ITimeSerie), self.timeseries)

    def registerIn(self, registry):
        if self.__dict__.get('_id', False): return
        self.__dict__['_id'] = True
        if self.__dict__.get('_processing_ex', False):
            raise Exception('cycle detected')
        self.__dict__['_processing_ex'] = True
        registry.insert(self)
        self.orderbook.registerIn(registry)
        self.link.registerIn(registry)
        for x in self.timeseries:
            x.registerIn(registry)
        if hasattr(self, '_subscriptions'):
            for s in self._subscriptions:
                s.registerIn(registry)
        if hasattr(self, '_internals'):
            for t in self._internals:
                v = getattr(self, t)
                if type(v) in [list, set]:
                    for w in v:
                        w.registerIn(registry)
                else:
                    v.registerIn(registry)
        self.__dict__['_processing_ex'] = False

    def bind_impl(self, ctx):
        Remote_Impl.bind_impl(self, ctx)

    def reset(self):
        Remote_Impl.reset(self)
示例#47
0
class SingleAsset_IOrderBookISingleAssetStrategyStringFloatFloatListITimeSerie(
        ISingleAssetTrader, SingleAsset_Impl):
    """ **A trader that trades a single asset on a single market**
    
    
    Parameters are:
    
    **orderBook**
    	 order book for the asset being traded 
    
    **strategy**
    	 strategy run by the trader 
    
    **name**
    
    **amount**
    	 current position of the trader (number of assets that it owns) 
    
    **PnL**
    	 current trader balance (number of money units that it owns) 
    
    **timeseries**
    	 defines what data should be gathered for the trader 
    """
    def __init__(self,
                 orderBook,
                 strategy=None,
                 name=None,
                 amount=None,
                 PnL=None,
                 timeseries=None):
        from marketsim.gen._out.strategy._empty import Empty_ as _strategy_Empty_
        from marketsim import deref_opt
        self.orderBook = orderBook
        self.strategy = strategy if strategy is not None else deref_opt(
            _strategy_Empty_())
        self.name = name if name is not None else "-trader-"
        self.amount = amount if amount is not None else 0.0
        self.PnL = PnL if PnL is not None else 0.0
        self.timeseries = timeseries if timeseries is not None else []
        SingleAsset_Impl.__init__(self)

    @property
    def label(self):
        return repr(self)

    _properties = {
        'orderBook': IOrderBook,
        'strategy': ISingleAssetStrategy,
        'name': str,
        'amount': float,
        'PnL': float,
        'timeseries': listOf(ITimeSerie)
    }

    def __repr__(self):
        return "%(name)s" % dict([(name, getattr(self, name))
                                  for name in self._properties.iterkeys()])

    def bind_ex(self, ctx):
        if self.__dict__.get('_bound_ex', False): return
        self.__dict__['_bound_ex'] = True
        if self.__dict__.get('_processing_ex', False):
            raise Exception('cycle detected')
        self.__dict__['_processing_ex'] = True
        self.__dict__['_ctx_ex'] = ctx.updatedFrom(self)
        if hasattr(self, '_internals'):
            for t in self._internals:
                v = getattr(self, t)
                if type(v) in [list, set]:
                    for w in v:
                        w.bind_ex(self.__dict__['_ctx_ex'])
                else:
                    v.bind_ex(self.__dict__['_ctx_ex'])
        self.orderBook.bind_ex(self._ctx_ex)
        self.strategy.bind_ex(self._ctx_ex)
        for x in self.timeseries:
            x.bind_ex(self._ctx_ex)
        self.bind_impl(self.__dict__['_ctx_ex'])
        if hasattr(self, '_subscriptions'):
            for s in self._subscriptions:
                s.bind_ex(self.__dict__['_ctx_ex'])
        self.__dict__['_processing_ex'] = False

    def reset_ex(self, generation):
        if self.__dict__.get('_reset_generation_ex', -1) == generation: return
        self.__dict__['_reset_generation_ex'] = generation
        if self.__dict__.get('_processing_ex', False):
            raise Exception('cycle detected')
        self.__dict__['_processing_ex'] = True
        if hasattr(self, '_internals'):
            for t in self._internals:
                v = getattr(self, t)
                if type(v) in [list, set]:
                    for w in v:
                        w.reset_ex(generation)
                else:
                    v.reset_ex(generation)
        self.orderBook.reset_ex(generation)
        self.strategy.reset_ex(generation)
        for x in self.timeseries:
            x.reset_ex(generation)
        self.reset()
        if hasattr(self, '_subscriptions'):
            for s in self._subscriptions:
                s.reset_ex(generation)
        self.__dict__['_processing_ex'] = False

    def typecheck(self):
        from marketsim.gen._out._isingleassetstrategy import ISingleAssetStrategy
        from marketsim import listOf
        from marketsim.gen._out._itimeserie import ITimeSerie
        from marketsim import rtti
        from marketsim.gen._out._iorderbook import IOrderBook
        rtti.typecheck(IOrderBook, self.orderBook)
        rtti.typecheck(ISingleAssetStrategy, self.strategy)
        rtti.typecheck(str, self.name)
        rtti.typecheck(float, self.amount)
        rtti.typecheck(float, self.PnL)
        rtti.typecheck(listOf(ITimeSerie), self.timeseries)

    def registerIn(self, registry):
        if self.__dict__.get('_id', False): return
        self.__dict__['_id'] = True
        if self.__dict__.get('_processing_ex', False):
            raise Exception('cycle detected')
        self.__dict__['_processing_ex'] = True
        registry.insert(self)
        self.orderBook.registerIn(registry)
        self.strategy.registerIn(registry)
        for x in self.timeseries:
            x.registerIn(registry)
        if hasattr(self, '_subscriptions'):
            for s in self._subscriptions:
                s.registerIn(registry)
        if hasattr(self, '_internals'):
            for t in self._internals:
                v = getattr(self, t)
                if type(v) in [list, set]:
                    for w in v:
                        w.registerIn(registry)
                else:
                    v.registerIn(registry)
        self.__dict__['_processing_ex'] = False

    def bind_impl(self, ctx):
        SingleAsset_Impl.bind_impl(self, ctx)

    def reset(self):
        SingleAsset_Impl.reset(self)