コード例 #1
0
ファイル: pairwise.py プロジェクト: alexcwyu/python-trading
    def __init__(self, input_lhs, input_rhs, func, name, length=1, input_key='close', desc="Pairwise"):
        super(Pairwise, self).__init__(name, [input_lhs, input_rhs], input_key, length=length, desc=desc)
        self.lhs_name = PipeLine.get_input_name(input_lhs)
        self.rhs_name = PipeLine.get_input_name(input_rhs)
        self.func = func
        self.is_input_pipeline = False

        if isinstance(input_lhs, PipeLine) and not isinstance(input_rhs, PipeLine):
            raise TypeError("input_lhs has to be the same type as input_rhs as Pipeline")

        if isinstance(input_lhs, Indicator) and not isinstance(input_rhs, Indicator):
            raise TypeError("input_lhs has to be the same type as input_rhs as Indicator")

        if isinstance(input_lhs, DataSeries) and not isinstance(input_rhs, DataSeries):
            raise TypeError("input_lhs has to be the same type as input_rhs as DataSeries")

        if isinstance(input_lhs, PipeLine):
            self.is_input_pipeline = True
            try:
                np.testing.assert_almost_equal(input_lhs.shape(), input_rhs.shape(), 10)
                self.__shape = input_lhs.shape()
            except AssertionError as e:
                raise ValueError("input_lhs shape should be the same as input_rhs in Pairwise Pipeline operation!")
        else:
            self.__shape = np.array([1, 1])

        super(Pairwise, self).update_all()
コード例 #2
0
ファイル: pairwise.py プロジェクト: jjchan121/python-trading
    def __init__(self, input_lhs, input_rhs, func, name, length=1, input_key='close', desc="Pairwise"):
        super(Pairwise, self).__init__(name, [input_lhs, input_rhs], input_key, length=length, desc=desc)
        self.lhs_name = PipeLine.get_input_name(input_lhs)
        self.rhs_name = PipeLine.get_input_name(input_rhs)
        self.func = func
        self.is_input_pipeline = False

        if isinstance(input_lhs, PipeLine) and not isinstance(input_rhs, PipeLine):
            raise TypeError("input_lhs has to be the same type as input_rhs as Pipeline")

        if isinstance(input_lhs, Indicator) and not isinstance(input_rhs, Indicator):
            raise TypeError("input_lhs has to be the same type as input_rhs as Indicator")

        if isinstance(input_lhs, DataSeries) and not isinstance(input_rhs, DataSeries):
            raise TypeError("input_lhs has to be the same type as input_rhs as DataSeries")

        if isinstance(input_lhs, PipeLine):
            self.is_input_pipeline = True
            try:
                np.testing.assert_almost_equal(input_lhs.shape(), input_rhs.shape(), 10)
                self.__shape = input_lhs.shape()
            except AssertionError as e:
                raise ValueError("input_lhs shape should be the same as input_rhs in Pairwise Pipeline operation!")
        else:
            self.__shape = [1, 1]

        super(Pairwise, self).update_all()
コード例 #3
0
 def __init__(self, inputs, lb, ub, newval, input_key="close", desc="Cross Sessional Tail"):
     super(Tail, self).__init__(
         inputs=inputs,
         np_func=lambda x: np_assign_on_mask(x, lb, ub, newval),
         name=PipeLine.get_name(Tail.__name__, inputs, input_key),
         input_key=input_key,
         length=1,
         desc=desc,
     )
コード例 #4
0
 def __init__(self, inputs, input_key="close", desc="Cross Sessional Average"):
     super(Average, self).__init__(
         inputs=inputs,
         np_func=np.average,
         name=PipeLine.get_name(Average.__name__, inputs, input_key),
         input_key=input_key,
         length=1,
         desc=desc,
     )
コード例 #5
0
 def __init__(self, inputs, input_key="close", desc="Cross Sessional Sum"):
     super(Sum, self).__init__(
         inputs=inputs,
         np_func=np.sum,
         name=PipeLine.get_name(Sum.__name__, inputs, input_key),
         input_key=input_key,
         length=1,
         desc=desc,
     )
コード例 #6
0
 def __init__(self, inputs, input_key='close', desc="Cross Sessional Log"):
     super(Log,
           self).__init__(inputs=inputs,
                          np_func=lambda x: np.log(x),
                          name=PipeLine.get_name(Log.__name__, inputs,
                                                 input_key),
                          input_key=input_key,
                          length=1,
                          desc=desc)
コード例 #7
0
 def __init__(self, inputs, input_key='close', desc="Cross Sessional Sign"):
     super(Sign,
           self).__init__(inputs=inputs,
                          np_func=lambda x: np_sign_to_value(x),
                          name=PipeLine.get_name(Sign.__name__, inputs,
                                                 input_key),
                          input_key=input_key,
                          length=1,
                          desc=desc)
コード例 #8
0
 def __init__(self, inputs, length, input_key="close", desc="Cross Sessional Delta"):
     super(Delta, self).__init__(
         inputs=inputs,
         np_func=lambda x: x[-1, :] - x[0, :],
         name=PipeLine.get_name(Delta.__name__, inputs, input_key),
         input_key=input_key,
         length=length,
         desc=desc,
     )
コード例 #9
0
 def __init__(self, inputs, length, input_key="close", desc="Cross Sessional Product"):
     super(Product, self).__init__(
         inputs=inputs,
         np_func=lambda x: np.prod(x, axis=0),
         name=PipeLine.get_name(Product.__name__, inputs, input_key),
         input_key=input_key,
         length=length,
         desc=desc,
     )
コード例 #10
0
 def __init__(self, inputs, input_key="close", desc="Cross Sessional Log"):
     super(Log, self).__init__(
         inputs=inputs,
         np_func=lambda x: np.log(x),
         name=PipeLine.get_name(Log.__name__, inputs, input_key),
         input_key=input_key,
         length=1,
         desc=desc,
     )
コード例 #11
0
 def __init__(self, inputs, input_key="close", desc="Cross Sessional Scale"):
     super(Scale, self).__init__(
         inputs=inputs,
         np_func=lambda x: x / np.sum(np.abs(x)),
         name=PipeLine.get_name(Scale.__name__, inputs, input_key),
         input_key=input_key,
         length=1,
         desc=desc,
     )
コード例 #12
0
 def __init__(self, inputs, input_key='close', desc="Cross Sessional Abs"):
     super(Abs,
           self).__init__(inputs=inputs,
                          np_func=np.abs,
                          name=PipeLine.get_name(Abs.__name__, inputs,
                                                 input_key),
                          input_key=input_key,
                          length=1,
                          desc=desc)
コード例 #13
0
 def __init__(self, inputs, length=20, input_key="close", desc="Cross Sessional DecayLinear"):
     super(DecayLinear, self).__init__(
         inputs=inputs,
         np_func=lambda x: np.dot(np.arange(length, 0, -1), x) / np.sum(np.arange(length, 0, -1)),
         name=PipeLine.get_name(DecayLinear.__name__, inputs, input_key),
         input_key=input_key,
         length=length,
         desc=desc,
     )
コード例 #14
0
 def __init__(self, inputs, f=0.9, length=20, input_key="close", desc="Cross Sessional DecayExp"):
     super(DecayExp, self).__init__(
         inputs=inputs,
         np_func=lambda x: np.dot(np.power(f, np.arange(length)), x) / np.sum(np.power(f, np.arange(length))),
         name=PipeLine.get_name(DecayExp.__name__, inputs, input_key),
         input_key=input_key,
         length=length,
         desc=desc,
     )
コード例 #15
0
 def __init__(self, inputs, ascending=True, length=20, input_key="close", desc="Cross Sessional Timeseries Rank"):
     super(TsRank, self).__init__(
         inputs=inputs,
         np_func=lambda x: timeseries_rank_helper(x, ascending=ascending),
         name=PipeLine.get_name(TsRank.__name__, inputs, input_key),
         input_key=input_key,
         length=length,
         desc=desc,
     )
コード例 #16
0
 def __init__(self, inputs, input_key="close", desc="Cross Sessional SignPower"):
     super(SignPower, self).__init__(
         inputs=inputs,
         np_func=lambda x: np_sign_to_value(x) * np.power(x, e),
         name=PipeLine.get_name(SignPower.__name__, inputs, input_key),
         input_key=input_key,
         length=1,
         desc=desc,
     )
コード例 #17
0
 def __init__(self,
              inputs,
              input_key='close',
              desc="Cross Sessional Scale"):
     super(Scale,
           self).__init__(inputs=inputs,
                          np_func=lambda x: x / np.sum(np.abs(x)),
                          name=PipeLine.get_name(Scale.__name__, inputs,
                                                 input_key),
                          input_key=input_key,
                          length=1,
                          desc=desc)
コード例 #18
0
 def __init__(self,
              inputs=None,
              ascending=True,
              input_key='close',
              desc="Rank"):
     self.ascending = ascending
     super(Rank, self).__init__(PipeLine.get_name(Rank.__name__, inputs,
                                                  input_key),
                                inputs,
                                input_key,
                                length=1,
                                desc=desc)
コード例 #19
0
 def __init__(self,
              inputs,
              input_key='close',
              desc="Bundle and Sync DataSeries to Vector"):
     super(MakeVector,
           self).__init__(PipeLine.get_name(MakeVector.__name__, inputs,
                                            input_key),
                          inputs,
                          input_key,
                          length=1,
                          desc=desc)
     super(MakeVector, self).update_all()
コード例 #20
0
 def __init__(self,
              inputs,
              ascending=True,
              length=20,
              input_key='close',
              desc="Cross Sessional Timeseries Rank"):
     super(TsRank, self).__init__(
         inputs=inputs,
         np_func=lambda x: timeseries_rank_helper(x, ascending=ascending),
         name=PipeLine.get_name(TsRank.__name__, inputs, input_key),
         input_key=input_key,
         length=length,
         desc=desc)
コード例 #21
0
 def __init__(self,
              input_lhs,
              input_rhs,
              input_key='close',
              desc="Pairwise Max"):
     super(Max, self).__init__(
         input_lhs,
         input_rhs,
         func=lambda x, y: np.max(np.vstack([x, y]), axis=0),
         name=PipeLine.get_name(Max.__name__, [input_lhs, input_rhs],
                                input_key),
         input_key=input_key,
         desc=desc)
コード例 #22
0
 def __init__(self,
              inputs,
              length=20,
              input_key='close',
              desc="Cross Sessional DecayLinear"):
     super(DecayLinear, self).__init__(
         inputs=inputs,
         np_func=lambda x: np.dot(np.arange(length, 0, -1), x) / np.sum(
             np.arange(length, 0, -1)),
         name=PipeLine.get_name(DecayLinear.__name__, inputs, input_key),
         input_key=input_key,
         length=length,
         desc=desc)
コード例 #23
0
 def __init__(self,
              inputs,
              length,
              input_key='close',
              desc="Cross Sessional Product"):
     super(Product,
           self).__init__(inputs=inputs,
                          np_func=lambda x: np.prod(x, axis=0),
                          name=PipeLine.get_name(Product.__name__, inputs,
                                                 input_key),
                          input_key=input_key,
                          length=length,
                          desc=desc)
コード例 #24
0
 def __init__(self,
              inputs,
              length,
              input_key='close',
              desc="Cross Sessional Delta"):
     super(Delta,
           self).__init__(inputs=inputs,
                          np_func=lambda x: x[-1, :] - x[0, :],
                          name=PipeLine.get_name(Delta.__name__, inputs,
                                                 input_key),
                          input_key=input_key,
                          length=length,
                          desc=desc)
コード例 #25
0
 def __init__(self,
              inputs,
              f=0.9,
              length=20,
              input_key='close',
              desc="Cross Sessional DecayExp"):
     super(DecayExp, self).__init__(
         inputs=inputs,
         np_func=lambda x: np.dot(np.power(f, np.arange(
             length)), x) / np.sum(np.power(f, np.arange(length))),
         name=PipeLine.get_name(DecayExp.__name__, inputs, input_key),
         input_key=input_key,
         length=length,
         desc=desc)
コード例 #26
0
 def __init__(self,
              input_lhs,
              input_rhs,
              input_key='close',
              desc="Pairwise Divdes"):
     super(Divides,
           self).__init__(input_lhs,
                          input_rhs,
                          func=lambda x, y: x / y,
                          name=PipeLine.get_name(Divides.__name__,
                                                 [input_lhs, input_rhs],
                                                 input_key),
                          input_key=input_key,
                          desc=desc)
コード例 #27
0
 def __init__(self,
              input_lhs,
              input_rhs,
              input_key='close',
              desc="Pairwise Greater"):
     super(Greater,
           self).__init__(input_lhs,
                          input_rhs,
                          func=lambda x, y: x > y,
                          name=PipeLine.get_name(Greater.__name__,
                                                 [input_lhs, input_rhs],
                                                 input_key),
                          input_key=input_key,
                          desc=desc)
コード例 #28
0
 def __init__(self,
              input_lhs,
              input_rhs,
              input_key='close',
              desc="Pairwise NotEquals"):
     super(NotEquals,
           self).__init__(input_lhs,
                          input_rhs,
                          func=lambda x, y: x != y,
                          name=PipeLine.get_name(NotEquals.__name__,
                                                 [input_lhs, input_rhs],
                                                 input_key),
                          input_key=input_key,
                          desc=desc)
コード例 #29
0
 def __init__(self,
              inputs,
              lb,
              ub,
              newval,
              input_key='close',
              desc="Cross Sessional Tail"):
     super(Tail, self).__init__(
         inputs=inputs,
         np_func=lambda x: np_assign_on_mask(x, lb, ub, newval),
         name=PipeLine.get_name(Tail.__name__, inputs, input_key),
         input_key=input_key,
         length=1,
         desc=desc)
コード例 #30
0
 def __init__(self,
              input_lhs,
              input_rhs,
              length,
              input_key='close',
              desc="Pairwise PairCorrelation"):
     super(PairCorrelation, self).__init__(
         input_lhs,
         input_rhs,
         length=length,
         func=lambda x, y: np.corrcoef(np.transpose(x), np.transpose(y)),
         name=PipeLine.get_name(PairCorrelation.__name__,
                                [input_lhs, input_rhs], input_key),
         input_key=input_key,
         desc=desc)
コード例 #31
0
ファイル: rank.py プロジェクト: alexcwyu/python-trading
 def __init__(self, inputs, ascending=True, input_key='close', desc="Rank"):
     self.ascending = ascending
     super(Rank, self).__init__(PipeLine.get_name(Rank.__name__, inputs, input_key),
                                inputs, input_key, length=1, desc=desc)
コード例 #32
0
ファイル: corr.py プロジェクト: jjchan121/python-trading
 def __init__(self, inputs, input_key='close', length=30, desc="Correlation"):
     super(Corr, self).__init__(PipeLine.get_name(Corr.__name__, input),
                                input,  input_key, length, desc)
     super(Corr, self).update_all()
コード例 #33
0
ファイル: pairwise.py プロジェクト: alexcwyu/python-trading
 def __init__(self, input_lhs, input_rhs, input_key='close', desc="Pairwise Max"):
     super(Max, self).__init__(input_lhs, input_rhs, func=lambda x, y: np.max(np.vstack([x, y]), axis=0),
                                   name=PipeLine.get_name(Max.__name__, [input_lhs, input_rhs], input_key),
                                   input_key=input_key, desc=desc)
コード例 #34
0
ファイル: pairwise.py プロジェクト: alexcwyu/python-trading
 def __init__(self, input_lhs, input_rhs, length, input_key='close', desc="Pairwise PairCorrelation"):
     super(PairCorrelation, self).__init__(input_lhs, input_rhs, length=length,
                                           func=lambda x, y: np.corrcoef(np.transpose(x), np.transpose(y)),
                                   name=PipeLine.get_name(PairCorrelation.__name__, [input_lhs, input_rhs], input_key),
                                   input_key=input_key, desc=desc)
コード例 #35
0
ファイル: pairwise.py プロジェクト: alexcwyu/python-trading
 def get_name(indicator_name, input_lhs, input_rhs, input_key, *args):
     return PipeLine.get_name(indicator_name,
                              inputs=[input_lhs, input_rhs],
                              input_key=input_key, *args)
コード例 #36
0
ファイル: pairwise.py プロジェクト: alexcwyu/python-trading
 def __init__(self, input_lhs, input_rhs, input_key='close', desc="Pairwise NotEquals"):
     super(NotEquals, self).__init__(input_lhs, input_rhs, func=lambda x, y: x != y,
                                   name=PipeLine.get_name(NotEquals.__name__, [input_lhs, input_rhs], input_key),
                                   input_key=input_key, desc=desc)
コード例 #37
0
ファイル: pairwise.py プロジェクト: alexcwyu/python-trading
 def __init__(self, input_lhs, input_rhs, input_key='close', desc="Pairwise Divdes"):
     super(Divides, self).__init__(input_lhs, input_rhs, func=lambda x, y: x/y,
                                name=PipeLine.get_name(Divides.__name__, [input_lhs, input_rhs], input_key),
                                input_key=input_key, desc=desc)
コード例 #38
0
ファイル: pairwise.py プロジェクト: alexcwyu/python-trading
 def __init__(self, input_lhs, input_rhs, input_key='close', desc="Pairwise Greater"):
     super(Greater, self).__init__(input_lhs, input_rhs, func=lambda x, y: x > y,
                                   name=PipeLine.get_name(Greater.__name__, [input_lhs, input_rhs], input_key),
                                   input_key=input_key, desc=desc)
コード例 #39
0
ファイル: corr.py プロジェクト: vjaeng/python-trading
 def __init__(self, inputs, input_key='close', length=30, desc="Correlation"):
     super(Corr, self).__init__(PipeLine.get_name(Corr.__name__, input),
                                input,  input_key, length, desc)
     super(Corr, self).update_all()
コード例 #40
0
 def get_name(indicator_name, input_lhs, input_rhs, input_key, *args):
     return PipeLine.get_name(indicator_name,
                              inputs=[input_lhs, input_rhs],
                              input_key=input_key,
                              *args)
コード例 #41
0
 def __init__(self, inputs, input_key='close', desc="Cross Sessional Sign"):
     super(Sign, self).__init__(inputs=inputs, np_func=lambda x: np_sign_to_value(x),
                                   name=PipeLine.get_name(Sign.__name__, inputs, input_key),
                                   input_key=input_key, length=1, desc=desc)
コード例 #42
0
 def __init__(self, inputs, input_key='close', desc="Cross Sessional Abs"):
     super(Abs, self).__init__(inputs=inputs, np_func=np.abs,
                                   name=PipeLine.get_name(Abs.__name__, inputs, input_key),
                                   input_key=input_key, length=1, desc=desc)
コード例 #43
0
 def __init__(self, inputs, input_key='close', desc="Bundle and Sync DataSeries to Vector"):
     super(MakeVector, self).__init__(PipeLine.get_name(MakeVector.__name__, inputs, input_key),
                                               inputs,  input_key, length=1, desc=desc)
     super(MakeVector, self).update_all()