コード例 #1
0
ファイル: feature_generation.py プロジェクト: jaiveerk/FML
def macd_signal(eq, slow_period, fast_period):
    macd_sig = np.array(
        Indicators.ema(
            np.array(Indicators.macd(eq.closes, slow_period, fast_period)), 9))
    macd_sig = macd_sig.T

    return [Indicator(macd_sig)]
コード例 #2
0
ファイル: equity.py プロジェクト: jaiveerk/FML
    def accumulative_swing_index(self, verbose=False):
        """[ASI is a way of looking at the prices of the equity
        in order to get information regarding momentum and market
        conditions]
        
        Returns:
            [float[]] -- [ASI values in a vector]
        """
        asi = np.zeros((len(self.closes), ))
        for i in range(len(self.closes)):
            if i + 1 >= len(self.closes):
                break
            curr_close = self.closes[i]
            prev_close = self.closes[i + 1]
            curr_open = self.opens[i]
            prev_open = self.opens[i + 1]
            curr_high = self.highs[i]
            prev_high = self.highs[i + 1]
            curr_low = self.lows[i]
            prev_low = self.lows[i + 1]
            k = np.max([(prev_high - curr_close), (prev_low - curr_close)])
            t = curr_high - curr_low
            kt = k / t

            num = (prev_close - curr_close + (0.5 * (prev_close - prev_open)) +
                   (0.25 * (curr_close - curr_open)))

            r = Indicators.get_r(curr_high, curr_low, prev_close, prev_open)

            body = num / r

            asi[i] = 50 * body * kt
        return asi[:-1]
コード例 #3
0
ファイル: equity.py プロジェクト: jaiveerk/FML
    def pivot_points(self, verbose=False):
        """[Pivot poits are the centers of recent price movement]
        
        Returns:
            [float[],float[],float[],float[],float[]] -- [The pivot
            points, restiance one band, resistance 2 band, support 1
            band and support 2 band respectively as vectors.]
        """
        closes = self.closes
        highs = self.highs
        lows = self.lows

        pivots = np.zeros((len(closes), ))
        r1s = np.zeros((len(closes), ))
        r2s = np.zeros((len(closes), ))
        s1s = np.zeros((len(closes), ))
        s2s = np.zeros((len(closes), ))

        for i in range(len(closes)):
            pivot, r1, r2, s1, s2 = Indicators.calc_pivot_points(
                highs[i], lows[i], closes[i])
            pivots[i] = pivot
            r1s[i] = r1
            r2s[i] = r2
            s1s[i] = s1
            s2s[i] = s2

        return pivots, r1s, r2s, s1s, s2s
コード例 #4
0
ファイル: feature_generation.py プロジェクト: jaiveerk/FML
def macd_raw_feature(eq, slow_period, fast_period):
    """
    Generates a feature vector of macd_raw for the last num_days
    """
    macd_raw_vec = np.array(
        Indicators.macd(eq.closes, slow_period, fast_period))
    macd_raw_vec = macd_raw_vec.T

    return [Indicator(macd_raw_vec)]
コード例 #5
0
ファイル: equity.py プロジェクト: jaiveerk/FML
    def bollinger_bands(self, period=20, stds=2, verbose=False):
        """[The Bolinger Bands is essentially a confidence interval of 
        stds Deviations where the price should be based on the last 
        period periods of prices]
        
        Keyword Arguments:
            period {int} -- [The period over which to look over the 
            prices] (default: {20})
            stds {int} -- [The number of standard deviations the bands 
            should take up] (default: {2})
        
        Returns:
            [float[], float[]] -- [Upper Bolinger Band, Lower Bolinger Band vectors respectively]
        """
        tp = self.typical_prices()
        ma = Indicators.sma(prices=tp, period=period)
        std = Indicators.calc_std(prices=tp, period=period)

        bolu = np.array([ma[i] + stds * std[i] for i in range(len(ma))])
        bold = np.array([ma[i] + stds * std[i] for i in range(len(ma))])

        return bolu, bold
コード例 #6
0
    def test_macd(self):
        prices = np.arange(100)

        print(Indicators.macd(prices, 18, 9))
コード例 #7
0
 def test_sma(self):
     prices = np.arange(10)
     expected = np.array([0, 0, 0, 0, 0, 2, 3, 4, 5, 6])
     assert (Indicators.sma(period=5, prices=prices) == expected).all()
コード例 #8
0
ファイル: feature_generation.py プロジェクト: jaiveerk/FML
def rainbow_feature(eq, smas):

    ohlc_vec = olhc_feature(eq)[0].values
    rainbow_vecs = Indicators.rainbow_ma(ohlc_vec, smas)

    return rainbow_vecs
コード例 #9
0
    def test_sma(self, period):
        prices = np.arange(10)

        print(Indicators.sma(prices, period))
コード例 #10
0
ファイル: feature_generation.py プロジェクト: jaiveerk/FML
def rsi_feature(eq, period=20, type='sma'):
    rsi_vec = np.array(Indicators.rsi(eq.closes, period, type))
    rsi_vec = rsi_vec.T
    return [Indicator(rsi_vec)]
コード例 #11
0
ファイル: feature_generation.py プロジェクト: jaiveerk/FML
def prings_feature(eq):
    prings_vec = np.array(Indicators.prings_know_sure_thing(eq.closes))
    prings_vec = prings_vec.T
    return [Indicator(prings_vec)]
コード例 #12
0
ファイル: feature_generation.py プロジェクト: jaiveerk/FML
def kst_trix_vec_feature(eq):
    kst_trix_vec = np.array(Indicators.kst_trix_indicator(eq.closes))
    kst_trix_vec = kst_trix_vec.T

    return [Indicator(kst_trix_vec)]
コード例 #13
0
ファイル: feature_generation.py プロジェクト: jaiveerk/FML
def trix_vec_feature(eq):
    trix_vec = np.array(Indicators.trix_indicator(eq.closes))
    trix_vec = trix_vec.T
    return [Indicator(trix_vec)]
コード例 #14
0
ファイル: feature_builder.py プロジェクト: jaiveerk/FML
def build_features(eq, type=''):
    
    # feature_type = parse_type(type)

    macd_ind = Indicators.macd_indicator(eq.closes, 6, 18)
コード例 #15
0
ファイル: feature_generation.py プロジェクト: jaiveerk/FML
def atr_feature(eq, period):
    atr_vec = np.array(Indicators.average_true_range(eq, period))
    atr_vec = atr_vec.T

    return [Indicator(atr_vec)]
コード例 #16
0
ファイル: feature_generation.py プロジェクト: jaiveerk/FML
def wilder_feature(eq, period):
    wilder_vec = np.array(Indicators.ema(eq.closes, period, 'wilder'))
    wilder_vec = wilder_vec.T

    return [Indicator(wilder_vec)]
コード例 #17
0
ファイル: feature_generation.py プロジェクト: jaiveerk/FML
def sma_feature(eq, period):
    sma_vec = np.array(Indicators.sma(eq.closes, period))
    sma_vec = sma_vec.T

    return [Indicator(sma_vec)]
コード例 #18
0
ファイル: feature_generation.py プロジェクト: jaiveerk/FML
def ema_feature(eq, period):

    ema_vec = np.array(Indicators.ema(eq.closes, period))
    ema_vec = ema_vec.T

    return [Indicator(ema_vec)]