20170620 量化:BT回溯库

发现一个做回测的库挺方便的,记下来

http://pmorissette.github.io/bt/index.html#what-is-bt

其中比较难的地方是algos这个类,

class Algo(object):

"""
Algos are used to modularize strategy logic so that strategy logic becomes
modular, composable, more testable and less error prone. Basically, the
Algo should follow the unix philosophy - do one thing well.

In practice, algos are simply a function that receives one argument, the
Strategy (refered to as target) and are expected to return a bool.

When some state preservation is necessary between calls, the Algo
object can be used (this object). The __call___ method should be
implemented and logic defined therein to mimic a function call. A
simple function may also be used if no state preservation is neceesary.

Args:
    * name (str): Algo name

"""

def __init__(self, name=None):
    self._name = name

@property
def name(self):
    """
    Algo name.
    """
    if self._name is None:
        self._name = self.__class__.__name__
    return self._name

def __call__(self, target):
    raise NotImplementedError("%s not implemented!" % self.name)

你可能感兴趣的:(20170620 量化:BT回溯库)