Ejemplo n.º 1
0
def regression_series(sx: pd.Series, sy: pd.Series, window: int):
    new = [sx, sy]
    
    df = pd.concat(new, axis=1, join='outer',)
    values = df.values
    index = df.index.values
    x = values[:, 0]
    y = values[:, 1]
    x1 = array_windows(x, window=window)
    y1 = array_windows(y, window=window)
    m, b, r = regression(x1, y1)
    
    m = append_nan(m, window)
    b = append_nan(b, window)
    r = append_nan(r, window)
    return m, b, r, index
Ejemplo n.º 2
0
def test_intervals():
    def _time_days_int_intervals(times, window_size):
        """Test WITHOUT NUMBA. Construct time intervals for windowing."""
        tnum = len(times) - window_size
        intervals = []
        for ii in range(tnum):
            interval = times[ii:ii + window_size]
            intervals.append(interval)
        return intervals

    times = np.linspace(1, 100, 10000)
    window_size = 20
    _ = array_windows(times, window_size)

    def test1():
        return array_windows(times, window_size)

    def test2():
        return _time_days_int_intervals(times, window_size)

    def test3():
        return _array_windows(times, window_size)

    time1 = timeit.timeit(test1, number=400)
    time2 = timeit.timeit(test2, number=400)
    time3 = timeit.timeit(test3, number=400)

    print('Numba interval speed = ', time1)
    print('Python interval speed = ', time2)
    print('Numba 2  interval speed = ', time3)
    assert time1 < time2
Ejemplo n.º 3
0
    def __init__(self, sx: pd.Series, sy: pd.Series, window: int):
        
        new = [sx, sy]
        df = pd.concat(new, axis=1, join='outer',)
        values = df.values
        index = df.index.values
        x = values[:, 0]
        y = values[:, 1]

        
        x1 = array_windows(x, window=window)
        y1 = array_windows(y, window=window)
        m, b, r = regression(x1, y1)
        
        m = append_nan(m, window)
        b = append_nan(b, window)
        r = append_nan(r, window)      
        
        self.index = index
        self.x = x
        self.y = y
        self.m = m
        self.b = b
        self.r = r
Ejemplo n.º 4
0
 def test1():
     return array_windows(times, window_size)
Ejemplo n.º 5
0
# -*- coding: utf-8 -*-
from numba import njit
from backtester.exceptions import NotEnoughDataError
import numpy as np
from backtester.indicators import array_windows

if __name__ == '__main__':
    
    x = np.arange(5)
    
    try:
        y = array_windows(x, 40)
    except NotEnoughDataError:
        y = 'bob'