Example #1
0
            return power * self.scale

        return numpy.array ([vola (arr) for arr in arrays])

    def __repr__ (self):

        return '⟨|@{0}|^p⟩^(1/p)'

###############################################################################
###############################################################################

if __name__ == "__main__":
    vola = VolatilityCallable (scale=1.0)

    parser = do.get_args_parser ({
        'stack-size': 2, 'function': vola, 'result': 'vola'
    })

    ##
    ## `volatility.exponent`
    ## ---------------------
    ## A large exponent `p` gives more weight to the tails of the distribution.
    ## If `p` is too large, the realized volatility may have an asymptotically
    ## infinite expectation (if returns have a heavy-tailed density function.
    ##

    parser.add_argument ("-e", "--exponent",
        default=2.0, type=float,
        help="p-exponent (default: %(default)s)")

    ##
Example #2
0
        return self._ema_callable

    ema_callable = property(fget=get_ema_callable)


###############################################################################
###############################################################################

if __name__ == "__main__":
    ema_iterated = EmaIteratedCallable(tau=600, n=1)  ## 10mins, no iteration

    parser = do.get_args_parser({
        'stack-size': 2,
        'function': ema_iterated,
        'parameters': [['timestamp']],
        'default': [],
        'result': 'ema-{n}'
    })

    parser.description = \
        """
        Calculates the *n-th* EMA directly from an inhomogeneous time series:
        It requires two parameters where the first is fixed as `timestamp` and
        the second can be chosen freely.
        """

    parser.epilog =\
        """
        Delivers results for the *first* to *n-th* EMA operators: This is a
        necessity since each EMA-i operator needs to access the results of the
Example #3
0
        self.n = n

    def __call__ (self, *arrays: [numpy.array], last=None) -> numpy.array:
        return numpy.array ([arr[0] - arr[self.n - 1] for arr in arrays])

    def __repr__ (self):
        return '@{0} - @{n-1}'

###############################################################################
###############################################################################

if __name__ == "__main__":
    diff = DiffCallable (n=2)

    parser = do.get_args_parser ({
        'stack-size': diff.n, 'function': diff, 'result': 'diff'
    })

    parser.description = \
        """
        Calculates the difference between two consecutive ticks by default, but
        it can also be used to calculate *overlapping* differences by
        increasing the *stack-size*.
        """

    parser.epilog = \
        """
        The difference is in general used to calculate a *return* at time
        t@{i}, r (t@{i}), and is defined as r (t@{i}) := r (Δt; t@{i}) =
        x (t@{i}) - x (t@{i}-Δt) where x (t@{i}) is a *homogeneous* sequence of
        logarithmic prices, and Δt is a time interval of fixed size.
Example #4
0
    def __repr__(self) -> str:
        return 'μ·EMA (t@{n-1}) + (1-μ)·z@{n-1} | ' \
               'μ := exp ((t@{n-1} - t@{n})/τ)'


###############################################################################
###############################################################################

if __name__ == "__main__":
    ema = EmaCallable(tau=600)  ## 10mins

    parser = do.get_args_parser({
        'stack-size': 2,
        'function': ema,
        'parameters': [['timestamp']],
        'default': [None],  ## dummy
        'result': 'ema'
    })

    parser.description = \
        """
        Calculates the *exponential moving average* EMA directly from an
        inhomogeneous time series: It requires at least two parameters where
        the first is fixed as *timestamp* and the rest can be chosen freely.
        """

    parser.epilog =\
        """
        The basic EMA is a simple linear operator. It is an averaging operator
        with an exponentially decaying kernel: ema (t) = exp (-t/τ) / τ. The
Example #5
0
            self._ema_callable = emalib.EmaCallable (tau=self.tau)

        return self._ema_callable

    ema_callable = property (fget=get_ema_callable)

###############################################################################
###############################################################################

if __name__ == "__main__":
    ema_iterated = EmaIteratedCallable (tau=600, n=1) ## 10mins, no iteration

    parser = do.get_args_parser ({
        'stack-size': 2,
        'function': ema_iterated,
        'parameters': [['timestamp']],
        'default': [],
        'result': 'ema-{n}'
    })

    parser.description = \
        """
        Calculates the *n-th* EMA directly from an inhomogeneous time series:
        It requires two parameters where the first is fixed as `timestamp` and
        the second can be chosen freely.
        """

    parser.epilog =\
        """
        Delivers results for the *first* to *n-th* EMA operators: This is a
        necessity since each EMA-i operator needs to access the results of the
Example #6
0
        ])

    def __repr__ (self) -> str:
        return 'μ·EMA (t@{n-1}) + (1-μ)·z@{n-1} | ' \
               'μ := exp ((t@{n-1} - t@{n})/τ)'

###############################################################################
###############################################################################

if __name__ == "__main__":
    ema = EmaCallable (tau=600) ## 10mins

    parser = do.get_args_parser ({
        'stack-size': 2,
        'function': ema,
        'parameters': [['timestamp']],
        'default': [None], ## dummy
        'result': 'ema'
    })

    parser.description = \
        """
        Calculates the *exponential moving average* EMA directly from an
        inhomogeneous time series: It requires at least two parameters where
        the first is fixed as *timestamp* and the rest can be chosen freely.
        """

    parser.epilog =\
        """
        The basic EMA is a simple linear operator. It is an averaging operator
        with an exponentially decaying kernel: ema (t) = exp (-t/τ) / τ. The