mirror of
https://github.com/microsoft/qlib.git
synced 2026-06-06 05:51:17 +08:00
Change Power to a NpPairOperator (#1052)
* Change Power to a NpPairOperator * Change Power to pair operator and use black to format
This commit is contained in:
@@ -112,6 +112,11 @@ class Expression(abc.ABC):
|
||||
|
||||
return Power(self, other)
|
||||
|
||||
def __rpow__(self, other):
|
||||
from .ops import Power # pylint: disable=C0415
|
||||
|
||||
return Power(other, self)
|
||||
|
||||
def __and__(self, other):
|
||||
from .ops import And # pylint: disable=C0415
|
||||
|
||||
|
||||
@@ -150,32 +150,6 @@ class Log(NpElemOperator):
|
||||
super(Log, self).__init__(feature, "log")
|
||||
|
||||
|
||||
class Power(NpElemOperator):
|
||||
"""Feature Power
|
||||
|
||||
Parameters
|
||||
----------
|
||||
feature : Expression
|
||||
feature instance
|
||||
|
||||
Returns
|
||||
----------
|
||||
Expression
|
||||
a feature instance with power
|
||||
"""
|
||||
|
||||
def __init__(self, feature, exponent):
|
||||
super(Power, self).__init__(feature, "power")
|
||||
self.exponent = exponent
|
||||
|
||||
def __str__(self):
|
||||
return "{}({},{})".format(type(self).__name__, self.feature, self.exponent)
|
||||
|
||||
def _load_internal(self, instrument, start_index, end_index, *args):
|
||||
series = self.feature.load(instrument, start_index, end_index, *args)
|
||||
return getattr(np, self.func)(series, self.exponent)
|
||||
|
||||
|
||||
class Mask(NpElemOperator):
|
||||
"""Feature Mask
|
||||
|
||||
@@ -333,6 +307,26 @@ class NpPairOperator(PairOperator):
|
||||
return res
|
||||
|
||||
|
||||
class Power(NpPairOperator):
|
||||
"""Power Operator
|
||||
|
||||
Parameters
|
||||
----------
|
||||
feature_left : Expression
|
||||
feature instance
|
||||
feature_right : Expression
|
||||
feature instance
|
||||
|
||||
Returns
|
||||
----------
|
||||
Feature:
|
||||
The bases in feature_left raised to the exponents in feature_right
|
||||
"""
|
||||
|
||||
def __init__(self, feature_left, feature_right):
|
||||
super(Power, self).__init__(feature_left, feature_right, "power")
|
||||
|
||||
|
||||
class Add(NpPairOperator):
|
||||
"""Add Operator
|
||||
|
||||
|
||||
Reference in New Issue
Block a user