def GetStockData(tickers):
    start = datetime.now() - timedelta(days=2)
    end = datetime.now()
    df1 = pd.DataFrame()
    test = pd.DataFrame()
    for stock in stocks:
        df = yf.download(stock, start=start, end=end, interval="15m")
        df['Stock'] = stock
        print(stock)
        ######################### RSI ################################
        df['RSI'] = talib.RSI(df.Close, timeperiod=14)
        df['RSI_EMA'] = talib.EMA(df.RSI, timeperiod=9)

        cross = ta.cross(series_a=df.RSI, series_b=df.RSI_EMA, above=True)
        cross_down = ta.cross(series_a=df.RSI, series_b=df.RSI_EMA, above=False)
        cross_down.replace(1, -1, inplace=True)

        for each in range(len(cross)):
            if cross_down.iloc[each] == -1:
                cross.iloc[each] = -1
        df['RSI_X'] = cross
        ################## shortlist for trade ########################
        test = test.append(df)
        if df.RSI_X.iloc[-1] in [1, -1]:
            if (df.RSI.iloc[-1] > 70) or (df.RSI.iloc[-1] < 30):
                df1 = df1.append(df.tail(1))
                appended_stock = df['Stock'].iloc[-1]
                print(f'record appended {appended_stock}')
    return df1
예제 #2
0
def movingAverage(df, fast_p, slow_p):
    smas = df.ta.sma(length=fast_p)
    smal = df.ta.sma(length=slow_p)
    ma_buy = ta.cross(smas, smal, above=True)
    ma_sell = ta.cross(smas, smal, above=False)
    ma_upw = ta.above(smas, smal)
    ma_buy.iloc[:fast_p] = np.nan
    ma_sell.iloc[:fast_p] = np.nan
    ma_upw.iloc[:fast_p] = np.nan
    return ma_buy, ma_sell, ma_upw
예제 #3
0
def adx(df, adx_len, adx_ul):
    df_adx = df.ta.adx(length=adx_len)
    adx, dmp, dmm = df_adx.iloc[:, 0], df_adx.iloc[:, 1], df_adx.iloc[:, 2]
    adx_force = ta.above_value(adx, adx_ul)
    adx_buy = ta.cross(dmp, dmm, above=True)
    adx_sell = ta.cross(dmp, dmm, above=False)
    adx_upw = ta.above(dmp, dmm)
    adx_force.iloc[:adx_len] = np.nan
    adx_buy.iloc[:adx_len] = np.nan
    adx_sell.iloc[:adx_len] = np.nan
    adx_upw.iloc[:adx_len] = np.nan
    return adx_force, adx_buy, adx_sell, adx_upw
예제 #4
0
def macd(df, macd_fast_p, macd_slow_p, macd_sign_p):
    df_macd = df.ta.macd(fast=macd_fast_p,
                         slow=macd_slow_p,
                         signal=macd_sign_p)
    macd_macd = df_macd.iloc[:, 0]
    macd_sign = df_macd.iloc[:, 2]
    macd_buy = ta.cross(macd_sign, macd_macd, above=True)
    macd_sell = ta.cross(macd_sign, macd_macd, above=False)
    macd_upw = ta.above(macd_sign, macd_macd)
    macd_buy.iloc[:macd_slow_p] = np.nan
    macd_sell.iloc[:macd_slow_p] = np.nan
    macd_upw.iloc[:macd_slow_p] = np.nan
    return macd_buy, macd_sell, macd_upw