Example #1
0
def Math_Transform(dataframe):
	#Math Transform Functions
	#ACOS - Vector Trigonometric ACos
	df[f'{ratio}_ACOS'] = talib.ACOS(Close)
	#ASIN - Vector Trigonometric ASin
	df[f'{ratio}_ASIN'] = talib.ASIN(Close)
	#ATAN - Vector Trigonometric ATan
	df[f'{ratio}_ATAN'] = talib.ATAN(Close)
	#CEIL - Vector Ceil
	df[f'{ratio}_CEIL'] = talib.CEIL(Close)
	#COS - Vector Trigonometric Cos
	df[f'{ratio}_COS'] = talib.COS(Close)
	#COSH - Vector Trigonometric Cosh
	df[f'{ratio}_COSH'] = talib.COSH(Close)
	#EXP - Vector Arithmetic Exp
	df[f'{ratio}_EXP'] = talib.EXP(Close)
	#FLOOR - Vector Floor
	df[f'{ratio}_FLOOR'] = talib.FLOOR(Close)
	#LN - Vector Log Natural
	df[f'{ratio}_LN'] = talib.LN(Close)
	#LOG10 - Vector Log10
	df[f'{ratio}_LOG10'] = talib.LOG10(Close)
	#SIN - Vector Trigonometric Sin
	df[f'{ratio}_SIN'] = talib.SIN(Close)
	#SINH - Vector Trigonometric Sinh
	df[f'{ratio}_SINH'] = talib.SINH(Close)
	#SQRT - Vector Square Root
	df[f'{ratio}_SQRT'] = talib.SQRT(Close)
	#TAN - Vector Trigonometric Tan
	df[f'{ratio}_TAN'] = talib.TAN(Close)
	#TANH - Vector Trigonometric Tanh
	df[f'{ratio}_TANH'] = talib.TANH(Close)

	return
def math_transform_process(event):
    print(event.widget.get())
    math_transform = event.widget.get()

    upperband, middleband, lowerband = ta.BBANDS(close, timeperiod=5, nbdevup=2, nbdevdn=2, matype=0)
    fig, axes = plt.subplots(2, 1, sharex=True)
    ax1, ax2 = axes[0], axes[1]
    axes[0].plot(close, 'rd-', markersize=3)
    axes[0].plot(upperband, 'y-')
    axes[0].plot(middleband, 'b-')
    axes[0].plot(lowerband, 'y-')
    axes[0].set_title(math_transform, fontproperties="SimHei")

    if math_transform == '反余弦':
        real = ta.ACOS(close)
        axes[1].plot(real, 'r-')
    elif math_transform == '反正弦':
        real = ta.ASIN(close)
        axes[1].plot(real, 'r-')
    elif math_transform == '反正切':
        real = ta.ATAN(close)
        axes[1].plot(real, 'r-')
    elif math_transform == '向上取整':
        real = ta.CEIL(close)
        axes[1].plot(real, 'r-')
    elif math_transform == '余弦':
        real = ta.COS(close)
        axes[1].plot(real, 'r-')
    elif math_transform == '双曲余弦':
        real = ta.COSH(close)
        axes[1].plot(real, 'r-')
    elif math_transform == '指数':
        real = ta.EXP(close)
        axes[1].plot(real, 'r-')
    elif math_transform == '向下取整':
        real = ta.FLOOR(close)
        axes[1].plot(real, 'r-')
    elif math_transform == '自然对数':
        real = ta.LN(close)
        axes[1].plot(real, 'r-')
    elif math_transform == '常用对数':
        real = ta.LOG10(close)
        axes[1].plot(real, 'r-')
    elif math_transform == '正弦':
        real = ta.SIN(close)
        axes[1].plot(real, 'r-')
    elif math_transform == '双曲正弦':
        real = ta.SINH(close)
        axes[1].plot(real, 'r-')
    elif math_transform == '平方根':
        real = ta.SQRT(close)
        axes[1].plot(real, 'r-')
    elif math_transform == '正切':
        real = ta.TAN(close)
        axes[1].plot(real, 'r-')
    elif math_transform == '双曲正切':
        real = ta.TANH(close)
        axes[1].plot(real, 'r-')

    plt.show()
Example #3
0
def genTA(data, y, t): #t is timeperiod
    indicators  = {}
    y_ind = copy.deepcopy(y)
   
    for ticker in data:
    ## Overlap
        indicators[ticker] = ta.SMA(data[ticker].iloc[:,3], timeperiod=t).to_frame()        
        indicators[ticker]['EMA'] = ta.EMA(data[ticker].iloc[:,3], timeperiod=t)       
        indicators[ticker]['BBAND_Upper'], indicators[ticker]['BBAND_Middle' ], indicators[ticker]['BBAND_Lower' ] = ta.BBANDS(data[ticker].iloc[:,3], timeperiod=t, nbdevup=2, nbdevdn=2, matype=0)         
        indicators[ticker]['HT_TRENDLINE'] = ta.HT_TRENDLINE(data[ticker].iloc[:,3])
        indicators[ticker]['SAR'] = ta.SAR(data[ticker].iloc[:,1], data[ticker].iloc[:,2], acceleration=0, maximum=0)
        #rename SMA column
        indicators[ticker].rename(columns={indicators[ticker].columns[0]: "SMA"}, inplace=True)
    ## Momentum
        indicators[ticker]['RSI'] = ta.RSI(data[ticker].iloc[:,3], timeperiod=(t-1))
        indicators[ticker]['MOM'] = ta.MOM(data[ticker].iloc[:,3], timeperiod=(t-1))
        indicators[ticker]['ROC'] = ta.ROC(data[ticker].iloc[:,3], timeperiod=(t-1))
        indicators[ticker]['ROCP']= ta.ROCP(data[ticker].iloc[:,3],timeperiod=(t-1))
        indicators[ticker]['STOCH_SLOWK'], indicators[ticker]['STOCH_SLOWD'] = ta.STOCH(data[ticker].iloc[:,1], data[ticker].iloc[:,2], data[ticker].iloc[:,3], fastk_period=t, slowk_period=int(.6*t), slowk_matype=0, slowd_period=int(.6*t), slowd_matype=0)
        indicators[ticker]['MACD'], indicators[ticker]['MACDSIGNAL'], indicators[ticker]['MACDHIST'] = ta.MACD(data[ticker].iloc[:,3], fastperiod=t,slowperiod=2*t,signalperiod=int(.7*t))
        
    ## Volume
        indicators[ticker]['OBV'] = ta.OBV(data[ticker].iloc[:,3], data[ticker].iloc[:,4])
        indicators[ticker]['AD'] = ta.AD(data[ticker].iloc[:,1], data[ticker].iloc[:,2], data[ticker].iloc[:,3], data[ticker].iloc[:,4])
        indicators[ticker]['ADOSC'] = ta.ADOSC(data[ticker].iloc[:,1], data[ticker].iloc[:,2], data[ticker].iloc[:,3], data[ticker].iloc[:,4], fastperiod=int(.3*t), slowperiod=t)
        
    ## Cycle
        indicators[ticker]['HT_DCPERIOD'] = ta.HT_DCPERIOD(data[ticker].iloc[:,3])
        indicators[ticker]['HT_TRENDMODE']= ta.HT_TRENDMODE(data[ticker].iloc[:,3])
    
    ## Price
        indicators[ticker]['AVGPRICE'] = ta.AVGPRICE(data[ticker].iloc[:,0], data[ticker].iloc[:,1], data[ticker].iloc[:,2], data[ticker].iloc[:,3])
        indicators[ticker]['TYPPRICE'] = ta.TYPPRICE(data[ticker].iloc[:,1], data[ticker].iloc[:,2], data[ticker].iloc[:,3])
    
    ## Volatility
        indicators[ticker]['ATR'] = ta.ATR(data[ticker].iloc[:,1], data[ticker].iloc[:,2], data[ticker].iloc[:,3],  timeperiod=(t-1))
    
    ## Statistics
        indicators[ticker]['BETA'] = ta.BETA(data[ticker].iloc[:,1], data[ticker].iloc[:,2], timeperiod=(t-1))
        indicators[ticker]['LINEARREG'] = ta.LINEARREG(data[ticker].iloc[:,3], timeperiod=t)
        indicators[ticker]['VAR'] = ta.VAR(data[ticker].iloc[:,3], timeperiod=t, nbdev=1)
    
    ## Math Transform
        indicators[ticker]['EXP'] = ta.EXP(data[ticker].iloc[:,3])
        indicators[ticker]['LN'] = ta.LN(data[ticker].iloc[:,3])
    
    ## Patterns (returns integers - but norming might not really do anything but wondering if they should be normed)
        indicators[ticker]['CDLENGULFING'] = ta.CDLENGULFING(data[ticker].iloc[:,0], data[ticker].iloc[:,1], data[ticker].iloc[:,2], data[ticker].iloc[:,3])
        indicators[ticker]['CDLDOJI']      = ta.CDLDOJI(data[ticker].iloc[:,0], data[ticker].iloc[:,1], data[ticker].iloc[:,2], data[ticker].iloc[:,3])
        indicators[ticker]['CDLHAMMER']    = ta.CDLHAMMER(data[ticker].iloc[:,0], data[ticker].iloc[:,1], data[ticker].iloc[:,2], data[ticker].iloc[:,3])
        indicators[ticker]['CDLHANGINGMAN']= ta.CDLHANGINGMAN(data[ticker].iloc[:,0], data[ticker].iloc[:,1], data[ticker].iloc[:,2], data[ticker].iloc[:,3])
        
    #drop 'nan' values
        indicators[ticker].drop(indicators[ticker].index[np.arange(0,63)], inplace=True)
        y_ind[ticker].drop(y_ind[ticker].index[np.arange(0,63)], inplace=True)
        
    #Normalize Features
    indicators_norm = normData(indicators)
        
    return indicators_norm, indicators, y_ind
Example #4
0
 def vol(self, n, array=False):
     """波动率指标"""
     logrtn = talib.LN(self.high / self.low)
     stdrtn = talib.STDDEV(logrtn, n)
     vol = talib.EXP(stdrtn) - 1
     if array:
         return vol
     return vol[-1]
Example #5
0
def EXP(close):
    ''' Vector Arithmetic Exp 指数曲线,三角函数

    分组: Math Transform 数学变换

    简介:

    real = EXP(close)
    '''
    return talib.EXP(close)
Example #6
0
def exp(client, symbol, timeframe="6m", col="close"):
    """This will return a dataframe of
    Vector Arithmetic Exp
    for the given symbol across the given timeframe

    Args:
        client (pyEX.Client); Client
        symbol (string); Ticker
        timeframe (string); timeframe to use, for pyEX.chart
        col (string); column to use to calculate

    Returns:
        DataFrame: result
    """
    df = client.chartDF(symbol, timeframe)
    x = t.EXP(df[col].values)
    return pd.DataFrame({col: df[col].values, "exp": x})
Example #7
0
def EXP(data, **kwargs):
    _check_talib_presence()
    prices = _extract_series(data)
    return talib.EXP(prices, **kwargs)
Example #8
0
def main():
    # read csv file and transform it to datafeed (df):
    df = pd.read_csv(current_dir + "/" + base_dir + "/" + in_dir + "/" +
                     in_dir + '_' + stock_symbol + '.csv')

    # set numpy datafeed from df:
    df_numpy = {
        'Date': np.array(df['date']),
        'Open': np.array(df['open'], dtype='float'),
        'High': np.array(df['high'], dtype='float'),
        'Low': np.array(df['low'], dtype='float'),
        'Close': np.array(df['close'], dtype='float'),
        'Volume': np.array(df['volume'], dtype='float')
    }

    date = df_numpy['Date']
    openp = df_numpy['Open']
    high = df_numpy['High']
    low = df_numpy['Low']
    close = df_numpy['Close']
    volume = df_numpy['Volume']

    #########################################
    #####  Math Transform Functions ######
    #########################################

    #ACOS - Vector Trigonometric ACos
    acos = ta.ACOS(close)

    #ASIN - Vector Trigonometric ASin
    asin = ta.ASIN(close)

    #ATAN - Vector Trigonometric ATan
    atan = ta.ATAN(close)

    #CEIL - Vector Ceil
    ceil = ta.CEIL(close)

    #COS - Vector Trigonometric Cos
    cos = ta.COS(close)

    #COSH - Vector Trigonometric Cosh
    cosh = ta.COSH(close)

    #EXP - Vector Arithmetic Exp
    exp = ta.EXP(close)

    #FLOOR - Vector Floor
    floor = ta.FLOOR(close)

    #LN - Vector Log Natural
    ln = ta.LN(close)

    #LOG10 - Vector Log10
    log10 = ta.LOG10(close)

    #SIN - Vector Trigonometric Sin
    sin = ta.SIN(close)

    #SINH - Vector Trigonometric Sinh
    sinh = ta.SINH(close)

    #SQRT - Vector Square Root
    sqrt = ta.SQRT(close)

    #TAN - Vector Trigonometric Tan
    tan = ta.TAN(close)

    #TANH - Vector Trigonometric Tanh
    tanh = ta.TANH(close)

    df_save = pd.DataFrame(
        data={
            'date': np.array(df['date']),
            'acos': acos,
            'asin': asin,
            'atan': atan,
            'ceil': ceil,
            'cos': cos,
            'cosh': cosh,
            'exp': exp,
            'floor': floor,
            'ln': ln,
            'log10': log10,
            'sin': sin,
            'sinh': sinh,
            'sqrt': sqrt,
            'tan': tan,
            'tanh': tanh
        })

    df_save.to_csv(current_dir + "/" + base_dir + "/" + out_dir + '/' +
                   stock_symbol + "/" + out_dir + '_ta_math_transform_' +
                   stock_symbol + '.csv',
                   index=False)
Example #9
0
 def EXP(Close):
     return Close.apply(lambda col: ta.EXP(col), axis=0)
Example #10
0
 def EXP(self, name, **parameters):
     data = self.__data[name]
     return talib.EXP(data, **parameters)