├── 101 Formulaic Alphas.pdf ├── 101Alpha_code_1.py └── 101Alpha_code_2.py /101 Formulaic Alphas.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robertmartin8/WorldQuant_alpha101_code/3bb9918dd7b62039f41a585a9e37bfd67ce3719f/101 Formulaic Alphas.pdf -------------------------------------------------------------------------------- /101Alpha_code_1.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | import pandas as pd 3 | from numpy import abs 4 | from numpy import log 5 | from numpy import sign 6 | from scipy.stats import rankdata 7 | 8 | # region Auxiliary functions 9 | def ts_sum(df, window=10): 10 | """ 11 | Wrapper function to estimate rolling sum. 12 | :param df: a pandas DataFrame. 13 | :param window: the rolling window. 14 | :return: a pandas DataFrame with the time-series min over the past 'window' days. 15 | """ 16 | 17 | return df.rolling(window).sum() 18 | 19 | def sma(df, window=10): 20 | """ 21 | Wrapper function to estimate SMA. 22 | :param df: a pandas DataFrame. 23 | :param window: the rolling window. 24 | :return: a pandas DataFrame with the time-series min over the past 'window' days. 25 | """ 26 | return df.rolling(window).mean() 27 | 28 | def stddev(df, window=10): 29 | """ 30 | Wrapper function to estimate rolling standard deviation. 31 | :param df: a pandas DataFrame. 32 | :param window: the rolling window. 33 | :return: a pandas DataFrame with the time-series min over the past 'window' days. 34 | """ 35 | return df.rolling(window).std() 36 | 37 | def correlation(x, y, window=10): 38 | """ 39 | Wrapper function to estimate rolling corelations. 40 | :param df: a pandas DataFrame. 41 | :param window: the rolling window. 42 | :return: a pandas DataFrame with the time-series min over the past 'window' days. 43 | """ 44 | return x.rolling(window).corr(y) 45 | 46 | def covariance(x, y, window=10): 47 | """ 48 | Wrapper function to estimate rolling covariance. 49 | :param df: a pandas DataFrame. 50 | :param window: the rolling window. 51 | :return: a pandas DataFrame with the time-series min over the past 'window' days. 52 | """ 53 | return x.rolling(window).cov(y) 54 | 55 | def rolling_rank(na): 56 | """ 57 | Auxiliary function to be used in pd.rolling_apply 58 | :param na: numpy array. 59 | :return: The rank of the last value in the array. 60 | """ 61 | return rankdata(na)[-1] 62 | 63 | def ts_rank(df, window=10): 64 | """ 65 | Wrapper function to estimate rolling rank. 66 | :param df: a pandas DataFrame. 67 | :param window: the rolling window. 68 | :return: a pandas DataFrame with the time-series rank over the past window days. 69 | """ 70 | return df.rolling(window).apply(rolling_rank) 71 | 72 | def rolling_prod(na): 73 | """ 74 | Auxiliary function to be used in pd.rolling_apply 75 | :param na: numpy array. 76 | :return: The product of the values in the array. 77 | """ 78 | return np.prod(na) 79 | 80 | def product(df, window=10): 81 | """ 82 | Wrapper function to estimate rolling product. 83 | :param df: a pandas DataFrame. 84 | :param window: the rolling window. 85 | :return: a pandas DataFrame with the time-series product over the past 'window' days. 86 | """ 87 | return df.rolling(window).apply(rolling_prod) 88 | 89 | def ts_min(df, window=10): 90 | """ 91 | Wrapper function to estimate rolling min. 92 | :param df: a pandas DataFrame. 93 | :param window: the rolling window. 94 | :return: a pandas DataFrame with the time-series min over the past 'window' days. 95 | """ 96 | return df.rolling(window).min() 97 | 98 | def ts_max(df, window=10): 99 | """ 100 | Wrapper function to estimate rolling min. 101 | :param df: a pandas DataFrame. 102 | :param window: the rolling window. 103 | :return: a pandas DataFrame with the time-series max over the past 'window' days. 104 | """ 105 | return df.rolling(window).max() 106 | 107 | def delta(df, period=1): 108 | """ 109 | Wrapper function to estimate difference. 110 | :param df: a pandas DataFrame. 111 | :param period: the difference grade. 112 | :return: a pandas DataFrame with today’s value minus the value 'period' days ago. 113 | """ 114 | return df.diff(period) 115 | 116 | def delay(df, period=1): 117 | """ 118 | Wrapper function to estimate lag. 119 | :param df: a pandas DataFrame. 120 | :param period: the lag grade. 121 | :return: a pandas DataFrame with lagged time series 122 | """ 123 | return df.shift(period) 124 | 125 | def rank(df): 126 | """ 127 | Cross sectional rank 128 | :param df: a pandas DataFrame. 129 | :return: a pandas DataFrame with rank along columns. 130 | """ 131 | #return df.rank(axis=1, pct=True) 132 | return df.rank(pct=True) 133 | 134 | def scale(df, k=1): 135 | """ 136 | Scaling time serie. 137 | :param df: a pandas DataFrame. 138 | :param k: scaling factor. 139 | :return: a pandas DataFrame rescaled df such that sum(abs(df)) = k 140 | """ 141 | return df.mul(k).div(np.abs(df).sum()) 142 | 143 | def ts_argmax(df, window=10): 144 | """ 145 | Wrapper function to estimate which day ts_max(df, window) occurred on 146 | :param df: a pandas DataFrame. 147 | :param window: the rolling window. 148 | :return: well.. that :) 149 | """ 150 | return df.rolling(window).apply(np.argmax) + 1 151 | 152 | def ts_argmin(df, window=10): 153 | """ 154 | Wrapper function to estimate which day ts_min(df, window) occurred on 155 | :param df: a pandas DataFrame. 156 | :param window: the rolling window. 157 | :return: well.. that :) 158 | """ 159 | return df.rolling(window).apply(np.argmin) + 1 160 | 161 | def decay_linear(df, period=10): 162 | """ 163 | Linear weighted moving average implementation. 164 | :param df: a pandas DataFrame. 165 | :param period: the LWMA period 166 | :return: a pandas DataFrame with the LWMA. 167 | """ 168 | # Clean data 169 | if df.isnull().values.any(): 170 | df.fillna(method='ffill', inplace=True) 171 | df.fillna(method='bfill', inplace=True) 172 | df.fillna(value=0, inplace=True) 173 | na_lwma = np.zeros_like(df) 174 | na_lwma[:period, :] = df.iloc[:period, :] 175 | na_series = df.as_matrix() 176 | 177 | divisor = period * (period + 1) / 2 178 | y = (np.arange(period) + 1) * 1.0 / divisor 179 | # Estimate the actual lwma with the actual close. 180 | # The backtest engine should assure to be snooping bias free. 181 | for row in range(period - 1, df.shape[0]): 182 | x = na_series[row - period + 1: row + 1, :] 183 | na_lwma[row, :] = (np.dot(x.T, y)) 184 | return pd.DataFrame(na_lwma, index=df.index, columns=['CLOSE']) 185 | # endregion 186 | 187 | def get_alpha(df): 188 | stock=Alphas(df) 189 | df['alpha001']=stock.alpha001() 190 | df['alpha002']=stock.alpha002() 191 | df['alpha003']=stock.alpha003() 192 | df['alpha004']=stock.alpha004() 193 | df['alpha005']=stock.alpha005() 194 | df['alpha006']=stock.alpha006() 195 | df['alpha007']=stock.alpha007() 196 | df['alpha008']=stock.alpha008() 197 | df['alpha009']=stock.alpha009() 198 | df['alpha010']=stock.alpha010() 199 | df['alpha011']=stock.alpha011() 200 | df['alpha012']=stock.alpha012() 201 | df['alpha013']=stock.alpha013() 202 | df['alpha014']=stock.alpha014() 203 | df['alpha015']=stock.alpha015() 204 | df['alpha016']=stock.alpha016() 205 | df['alpha017']=stock.alpha017() 206 | df['alpha018']=stock.alpha018() 207 | df['alpha019']=stock.alpha019() 208 | df['alpha020']=stock.alpha020() 209 | df['alpha021']=stock.alpha021() 210 | df['alpha022']=stock.alpha022() 211 | df['alpha023']=stock.alpha023() 212 | df['alpha024']=stock.alpha024() 213 | df['alpha025']=stock.alpha025() 214 | df['alpha026']=stock.alpha026() 215 | df['alpha027']=stock.alpha027() 216 | df['alpha028']=stock.alpha028() 217 | df['alpha029']=stock.alpha029() 218 | df['alpha030']=stock.alpha030() 219 | df['alpha031']=stock.alpha031() 220 | df['alpha032']=stock.alpha032() 221 | df['alpha033']=stock.alpha033() 222 | df['alpha034']=stock.alpha034() 223 | df['alpha035']=stock.alpha035() 224 | df['alpha036']=stock.alpha036() 225 | df['alpha037']=stock.alpha037() 226 | df['alpha038']=stock.alpha038() 227 | df['alpha039']=stock.alpha039() 228 | df['alpha040']=stock.alpha040() 229 | df['alpha041']=stock.alpha041() 230 | df['alpha042']=stock.alpha042() 231 | df['alpha043']=stock.alpha043() 232 | df['alpha044']=stock.alpha044() 233 | df['alpha045']=stock.alpha045() 234 | df['alpha046']=stock.alpha046() 235 | df['alpha047']=stock.alpha047() 236 | df['alpha049']=stock.alpha049() 237 | df['alpha050']=stock.alpha050() 238 | df['alpha051']=stock.alpha051() 239 | df['alpha052']=stock.alpha052() 240 | df['alpha053']=stock.alpha053() 241 | df['alpha054']=stock.alpha054() 242 | df['alpha055']=stock.alpha055() 243 | df['alpha057']=stock.alpha057() 244 | df['alpha060']=stock.alpha060() 245 | df['alpha061']=stock.alpha061() 246 | df['alpha062']=stock.alpha062() 247 | df['alpha064']=stock.alpha064() 248 | df['alpha065']=stock.alpha065() 249 | df['alpha066']=stock.alpha066() 250 | df['alpha068']=stock.alpha068() 251 | df['alpha071']=stock.alpha071() 252 | df['alpha072']=stock.alpha072() 253 | df['alpha073']=stock.alpha073() 254 | df['alpha074']=stock.alpha074() 255 | df['alpha075']=stock.alpha075() 256 | df['alpha077']=stock.alpha077() 257 | df['alpha078']=stock.alpha078() 258 | df['alpha081']=stock.alpha081() 259 | df['alpha083']=stock.alpha083() 260 | df['alpha084']=stock.alpha084() 261 | df['alpha085']=stock.alpha085() 262 | df['alpha086']=stock.alpha086() 263 | df['alpha088']=stock.alpha088() 264 | df['alpha092']=stock.alpha092() 265 | df['alpha094']=stock.alpha094() 266 | df['alpha095']=stock.alpha095() 267 | df['alpha096']=stock.alpha096() 268 | df['alpha098']=stock.alpha098() 269 | df['alpha099']=stock.alpha099() 270 | df['alpha101']=stock.alpha101() 271 | return df 272 | 273 | class Alphas(object): 274 | def __init__(self, df_data): 275 | 276 | self.open = df_data['S_DQ_OPEN'] 277 | self.high = df_data['S_DQ_HIGH'] 278 | self.low = df_data['S_DQ_LOW'] 279 | self.close = df_data['S_DQ_CLOSE'] 280 | self.volume = df_data['S_DQ_VOLUME']*100 281 | self.returns = df_data['S_DQ_PCTCHANGE'] 282 | self.vwap = (df_data['S_DQ_AMOUNT']*1000)/(df_data['S_DQ_VOLUME']*100+1) 283 | 284 | # Alpha#1 (rank(Ts_ArgMax(SignedPower(((returns < 0) ? stddev(returns, 20) : close), 2.), 5)) -0.5) 285 | def alpha001(self): 286 | inner = self.close 287 | inner[self.returns < 0] = stddev(self.returns, 20) 288 | return rank(ts_argmax(inner ** 2, 5)) 289 | 290 | # Alpha#2 (-1 * correlation(rank(delta(log(volume), 2)), rank(((close - open) / open)), 6)) 291 | def alpha002(self): 292 | df = -1 * correlation(rank(delta(log(self.volume), 2)), rank((self.close - self.open) / self.open), 6) 293 | return df.replace([-np.inf, np.inf], 0).fillna(value=0) 294 | 295 | # Alpha#3 (-1 * correlation(rank(open), rank(volume), 10)) 296 | def alpha003(self): 297 | df = -1 * correlation(rank(self.open), rank(self.volume), 10) 298 | return df.replace([-np.inf, np.inf], 0).fillna(value=0) 299 | 300 | # Alpha#4 (-1 * Ts_Rank(rank(low), 9)) 301 | def alpha004(self): 302 | return -1 * ts_rank(rank(self.low), 9) 303 | 304 | # Alpha#5 (rank((open - (sum(vwap, 10) / 10))) * (-1 * abs(rank((close - vwap))))) 305 | def alpha005(self): 306 | return (rank((self.open - (sum(self.vwap, 10) / 10))) * (-1 * abs(rank((self.close - self.vwap))))) 307 | 308 | # Alpha#6 (-1 * correlation(open, volume, 10)) 309 | def alpha006(self): 310 | df = -1 * correlation(self.open, self.volume, 10) 311 | return df.replace([-np.inf, np.inf], 0).fillna(value=0) 312 | 313 | # Alpha#7 ((adv20 < volume) ? ((-1 * ts_rank(abs(delta(close, 7)), 60)) * sign(delta(close, 7))) : (-1* 1)) 314 | def alpha007(self): 315 | adv20 = sma(self.volume, 20) 316 | alpha = -1 * ts_rank(abs(delta(self.close, 7)), 60) * sign(delta(self.close, 7)) 317 | alpha[adv20 >= self.volume] = -1 318 | return alpha 319 | 320 | # Alpha#8 (-1 * rank(((sum(open, 5) * sum(returns, 5)) - delay((sum(open, 5) * sum(returns, 5)),10)))) 321 | def alpha008(self): 322 | return -1 * (rank(((ts_sum(self.open, 5) * ts_sum(self.returns, 5)) - 323 | delay((ts_sum(self.open, 5) * ts_sum(self.returns, 5)), 10)))) 324 | 325 | # Alpha#9 ((0 < ts_min(delta(close, 1), 5)) ? delta(close, 1) : ((ts_max(delta(close, 1), 5) < 0) ?delta(close, 1) : (-1 * delta(close, 1)))) 326 | def alpha009(self): 327 | delta_close = delta(self.close, 1) 328 | cond_1 = ts_min(delta_close, 5) > 0 329 | cond_2 = ts_max(delta_close, 5) < 0 330 | alpha = -1 * delta_close 331 | alpha[cond_1 | cond_2] = delta_close 332 | return alpha 333 | 334 | # Alpha#10 rank(((0 < ts_min(delta(close, 1), 4)) ? delta(close, 1) : ((ts_max(delta(close, 1), 4) < 0)? delta(close, 1) : (-1 * delta(close, 1))))) 335 | def alpha010(self): 336 | delta_close = delta(self.close, 1) 337 | cond_1 = ts_min(delta_close, 4) > 0 338 | cond_2 = ts_max(delta_close, 4) < 0 339 | alpha = -1 * delta_close 340 | alpha[cond_1 | cond_2] = delta_close 341 | return alpha 342 | 343 | # Alpha#11 ((rank(ts_max((vwap - close), 3)) + rank(ts_min((vwap - close), 3))) *rank(delta(volume, 3))) 344 | def alpha011(self): 345 | return ((rank(ts_max((self.vwap - self.close), 3)) + rank(ts_min((self.vwap - self.close), 3))) *rank(delta(self.volume, 3))) 346 | 347 | # Alpha#12 (sign(delta(volume, 1)) * (-1 * delta(close, 1))) 348 | def alpha012(self): 349 | return sign(delta(self.volume, 1)) * (-1 * delta(self.close, 1)) 350 | 351 | # Alpha#13 (-1 * rank(covariance(rank(close), rank(volume), 5))) 352 | def alpha013(self): 353 | return -1 * rank(covariance(rank(self.close), rank(self.volume), 5)) 354 | 355 | # Alpha#14 ((-1 * rank(delta(returns, 3))) * correlation(open, volume, 10)) 356 | def alpha014(self): 357 | df = correlation(self.open, self.volume, 10) 358 | df = df.replace([-np.inf, np.inf], 0).fillna(value=0) 359 | return -1 * rank(delta(self.returns, 3)) * df 360 | 361 | # Alpha#15 (-1 * sum(rank(correlation(rank(high), rank(volume), 3)), 3)) 362 | def alpha015(self): 363 | df = correlation(rank(self.high), rank(self.volume), 3) 364 | df = df.replace([-np.inf, np.inf], 0).fillna(value=0) 365 | return -1 * ts_sum(rank(df), 3) 366 | 367 | # Alpha#16 (-1 * rank(covariance(rank(high), rank(volume), 5))) 368 | def alpha016(self): 369 | return -1 * rank(covariance(rank(self.high), rank(self.volume), 5)) 370 | 371 | # Alpha#17 (((-1 * rank(ts_rank(close, 10))) * rank(delta(delta(close, 1), 1))) *rank(ts_rank((volume / adv20), 5))) 372 | def alpha017(self): 373 | adv20 = sma(self.volume, 20) 374 | return -1 * (rank(ts_rank(self.close, 10)) * 375 | rank(delta(delta(self.close, 1), 1)) * 376 | rank(ts_rank((self.volume / adv20), 5))) 377 | 378 | # Alpha#18 (-1 * rank(((stddev(abs((close - open)), 5) + (close - open)) + correlation(close, open,10)))) 379 | def alpha018(self): 380 | df = correlation(self.close, self.open, 10) 381 | df = df.replace([-np.inf, np.inf], 0).fillna(value=0) 382 | return -1 * (rank((stddev(abs((self.close - self.open)), 5) + (self.close - self.open)) + 383 | df)) 384 | 385 | # Alpha#19 ((-1 * sign(((close - delay(close, 7)) + delta(close, 7)))) * (1 + rank((1 + sum(returns,250))))) 386 | def alpha019(self): 387 | return ((-1 * sign((self.close - delay(self.close, 7)) + delta(self.close, 7))) * 388 | (1 + rank(1 + ts_sum(self.returns, 250)))) 389 | 390 | # Alpha#20 (((-1 * rank((open - delay(high, 1)))) * rank((open - delay(close, 1)))) * rank((open -delay(low, 1)))) 391 | def alpha020(self): 392 | return -1 * (rank(self.open - delay(self.high, 1)) * 393 | rank(self.open - delay(self.close, 1)) * 394 | rank(self.open - delay(self.low, 1))) 395 | 396 | # Alpha#21 ((((sum(close, 8) / 8) + stddev(close, 8)) < (sum(close, 2) / 2)) ? (-1 * 1) : (((sum(close,2) / 2) < ((sum(close, 8) / 8) - stddev(close, 8))) ? 1 : (((1 < (volume / adv20)) || ((volume /adv20) == 1)) ? 1 : (-1 * 1)))) 397 | def alpha021(self): 398 | cond_1 = sma(self.close, 8) + stddev(self.close, 8) < sma(self.close, 2) 399 | cond_2 = sma(self.volume, 20) / self.volume < 1 400 | alpha = pd.DataFrame(np.ones_like(self.close), index=self.close.index 401 | ) 402 | # alpha = pd.DataFrame(np.ones_like(self.close), index=self.close.index, 403 | # columns=self.close.columns) 404 | alpha[cond_1 | cond_2] = -1 405 | return alpha 406 | 407 | # Alpha#22 (-1 * (delta(correlation(high, volume, 5), 5) * rank(stddev(close, 20)))) 408 | def alpha022(self): 409 | df = correlation(self.high, self.volume, 5) 410 | df = df.replace([-np.inf, np.inf], 0).fillna(value=0) 411 | return -1 * delta(df, 5) * rank(stddev(self.close, 20)) 412 | 413 | # Alpha#23 (((sum(high, 20) / 20) < high) ? (-1 * delta(high, 2)) : 0) 414 | def alpha023(self): 415 | cond = sma(self.high, 20) < self.high 416 | alpha = pd.DataFrame(np.zeros_like(self.close),index=self.close.index,columns=['close']) 417 | alpha.at[cond,'close'] = -1 * delta(self.high, 2).fillna(value=0) 418 | return alpha 419 | 420 | # Alpha#24 ((((delta((sum(close, 100) / 100), 100) / delay(close, 100)) < 0.05) ||((delta((sum(close, 100) / 100), 100) / delay(close, 100)) == 0.05)) ? (-1 * (close - ts_min(close,100))) : (-1 * delta(close, 3))) 421 | def alpha024(self): 422 | cond = delta(sma(self.close, 100), 100) / delay(self.close, 100) <= 0.05 423 | alpha = -1 * delta(self.close, 3) 424 | alpha[cond] = -1 * (self.close - ts_min(self.close, 100)) 425 | return alpha 426 | 427 | # Alpha#25 rank(((((-1 * returns) * adv20) * vwap) * (high - close))) 428 | def alpha025(self): 429 | adv20 = sma(self.volume, 20) 430 | return rank(((((-1 * self.returns) * adv20) * self.vwap) * (self.high - self.close))) 431 | 432 | # Alpha#26 (-1 * ts_max(correlation(ts_rank(volume, 5), ts_rank(high, 5), 5), 3)) 433 | def alpha026(self): 434 | df = correlation(ts_rank(self.volume, 5), ts_rank(self.high, 5), 5) 435 | df = df.replace([-np.inf, np.inf], 0).fillna(value=0) 436 | return -1 * ts_max(df, 3) 437 | 438 | # Alpha#27 ((0.5 < rank((sum(correlation(rank(volume), rank(vwap), 6), 2) / 2.0))) ? (-1 * 1) : 1) 439 | ### 440 | ## Some Error, still fixing!! 441 | def alpha027(self): 442 | alpha = rank((sma(correlation(rank(self.volume), rank(self.vwap), 6), 2) / 2.0)) 443 | alpha[alpha > 0.5] = -1 444 | alpha[alpha <= 0.5]=1 445 | return alpha 446 | 447 | # Alpha#28 scale(((correlation(adv20, low, 5) + ((high + low) / 2)) - close)) 448 | def alpha028(self): 449 | adv20 = sma(self.volume, 20) 450 | df = correlation(adv20, self.low, 5) 451 | df = df.replace([-np.inf, np.inf], 0).fillna(value=0) 452 | return scale(((df + ((self.high + self.low) / 2)) - self.close)) 453 | 454 | # Alpha#29 (min(product(rank(rank(scale(log(sum(ts_min(rank(rank((-1 * rank(delta((close - 1),5))))), 2), 1))))), 1), 5) + ts_rank(delay((-1 * returns), 6), 5)) 455 | def alpha029(self): 456 | return (ts_min(rank(rank(scale(log(ts_sum(rank(rank(-1 * rank(delta((self.close - 1), 5)))), 2))))), 5) + 457 | ts_rank(delay((-1 * self.returns), 6), 5)) 458 | 459 | # Alpha#30 (((1.0 - rank(((sign((close - delay(close, 1))) + sign((delay(close, 1) - delay(close, 2)))) +sign((delay(close, 2) - delay(close, 3)))))) * sum(volume, 5)) / sum(volume, 20)) 460 | def alpha030(self): 461 | delta_close = delta(self.close, 1) 462 | inner = sign(delta_close) + sign(delay(delta_close, 1)) + sign(delay(delta_close, 2)) 463 | return ((1.0 - rank(inner)) * ts_sum(self.volume, 5)) / ts_sum(self.volume, 20) 464 | 465 | # Alpha#31 ((rank(rank(rank(decay_linear((-1 * rank(rank(delta(close, 10)))), 10)))) + rank((-1 *delta(close, 3)))) + sign(scale(correlation(adv20, low, 12)))) 466 | def alpha031(self): 467 | adv20 = sma(self.volume, 20) 468 | df = correlation(adv20, self.low, 12).replace([-np.inf, np.inf], 0).fillna(value=0) 469 | p1=rank(rank(rank(decay_linear((-1 * rank(rank(delta(self.close, 10)))).to_frame(), 10)))) 470 | p2=rank((-1 * delta(self.close, 3))) 471 | p3=sign(scale(df)) 472 | 473 | return p1.CLOSE+p2+p3 474 | 475 | # Alpha#32 (scale(((sum(close, 7) / 7) - close)) + (20 * scale(correlation(vwap, delay(close, 5),230)))) 476 | def alpha032(self): 477 | return scale(((sma(self.close, 7) / 7) - self.close)) + (20 * scale(correlation(self.vwap, delay(self.close, 5),230))) 478 | 479 | # Alpha#33 rank((-1 * ((1 - (open / close))^1))) 480 | def alpha033(self): 481 | return rank(-1 + (self.open / self.close)) 482 | 483 | # Alpha#34 rank(((1 - rank((stddev(returns, 2) / stddev(returns, 5)))) + (1 - rank(delta(close, 1))))) 484 | def alpha034(self): 485 | inner = stddev(self.returns, 2) / stddev(self.returns, 5) 486 | inner = inner.replace([-np.inf, np.inf], 1).fillna(value=1) 487 | return rank(2 - rank(inner) - rank(delta(self.close, 1))) 488 | 489 | # Alpha#35 ((Ts_Rank(volume, 32) * (1 - Ts_Rank(((close + high) - low), 16))) * (1 -Ts_Rank(returns, 32))) 490 | def alpha035(self): 491 | return ((ts_rank(self.volume, 32) * 492 | (1 - ts_rank(self.close + self.high - self.low, 16))) * 493 | (1 - ts_rank(self.returns, 32))) 494 | 495 | # Alpha#36 (((((2.21 * rank(correlation((close - open), delay(volume, 1), 15))) + (0.7 * rank((open- close)))) + (0.73 * rank(Ts_Rank(delay((-1 * returns), 6), 5)))) + rank(abs(correlation(vwap,adv20, 6)))) + (0.6 * rank((((sum(close, 200) / 200) - open) * (close - open))))) 496 | def alpha036(self): 497 | adv20 = sma(self.volume, 20) 498 | return (((((2.21 * rank(correlation((self.close - self.open), delay(self.volume, 1), 15))) + (0.7 * rank((self.open- self.close)))) + (0.73 * rank(ts_rank(delay((-1 * self.returns), 6), 5)))) + rank(abs(correlation(self.vwap,adv20, 6)))) + (0.6 * rank((((sma(self.close, 200) / 200) - self.open) * (self.close - self.open))))) 499 | 500 | # Alpha#37 (rank(correlation(delay((open - close), 1), close, 200)) + rank((open - close))) 501 | def alpha037(self): 502 | return rank(correlation(delay(self.open - self.close, 1), self.close, 200)) + rank(self.open - self.close) 503 | 504 | # Alpha#38 ((-1 * rank(Ts_Rank(close, 10))) * rank((close / open))) 505 | def alpha038(self): 506 | inner = self.close / self.open 507 | inner = inner.replace([-np.inf, np.inf], 1).fillna(value=1) 508 | return -1 * rank(ts_rank(self.open, 10)) * rank(inner) 509 | 510 | # Alpha#39 ((-1 * rank((delta(close, 7) * (1 - rank(decay_linear((volume / adv20), 9)))))) * (1 +rank(sum(returns, 250)))) 511 | def alpha039(self): 512 | adv20 = sma(self.volume, 20) 513 | return ((-1 * rank(delta(self.close, 7) * (1 - rank(decay_linear((self.volume / adv20).to_frame(), 9).CLOSE)))) * 514 | (1 + rank(sma(self.returns, 250)))) 515 | 516 | # Alpha#40 ((-1 * rank(stddev(high, 10))) * correlation(high, volume, 10)) 517 | def alpha040(self): 518 | return -1 * rank(stddev(self.high, 10)) * correlation(self.high, self.volume, 10) 519 | 520 | # Alpha#41 (((high * low)^0.5) - vwap) 521 | def alpha041(self): 522 | return pow((self.high * self.low),0.5) - self.vwap 523 | 524 | # Alpha#42 (rank((vwap - close)) / rank((vwap + close))) 525 | def alpha042(self): 526 | return rank((self.vwap - self.close)) / rank((self.vwap + self.close)) 527 | 528 | # Alpha#43 (ts_rank((volume / adv20), 20) * ts_rank((-1 * delta(close, 7)), 8)) 529 | def alpha043(self): 530 | adv20 = sma(self.volume, 20) 531 | return ts_rank(self.volume / adv20, 20) * ts_rank((-1 * delta(self.close, 7)), 8) 532 | 533 | # Alpha#44 (-1 * correlation(high, rank(volume), 5)) 534 | def alpha044(self): 535 | df = correlation(self.high, rank(self.volume), 5) 536 | df = df.replace([-np.inf, np.inf], 0).fillna(value=0) 537 | return -1 * df 538 | 539 | # Alpha#45 (-1 * ((rank((sum(delay(close, 5), 20) / 20)) * correlation(close, volume, 2)) *rank(correlation(sum(close, 5), sum(close, 20), 2)))) 540 | def alpha045(self): 541 | df = correlation(self.close, self.volume, 2) 542 | df = df.replace([-np.inf, np.inf], 0).fillna(value=0) 543 | return -1 * (rank(sma(delay(self.close, 5), 20)) * df * 544 | rank(correlation(ts_sum(self.close, 5), ts_sum(self.close, 20), 2))) 545 | 546 | # Alpha#46 ((0.25 < (((delay(close, 20) - delay(close, 10)) / 10) - ((delay(close, 10) - close) / 10))) ?(-1 * 1) : (((((delay(close, 20) - delay(close, 10)) / 10) - ((delay(close, 10) - close) / 10)) < 0) ? 1 :((-1 * 1) * (close - delay(close, 1))))) 547 | def alpha046(self): 548 | inner = ((delay(self.close, 20) - delay(self.close, 10)) / 10) - ((delay(self.close, 10) - self.close) / 10) 549 | alpha = (-1 * delta(self.close)) 550 | alpha[inner < 0] = 1 551 | alpha[inner > 0.25] = -1 552 | return alpha 553 | 554 | # Alpha#47 ((((rank((1 / close)) * volume) / adv20) * ((high * rank((high - close))) / (sum(high, 5) /5))) - rank((vwap - delay(vwap, 5)))) 555 | def alpha047(self): 556 | adv20 = sma(self.volume, 20) 557 | return ((((rank((1 / self.close)) * self.volume) / adv20) * ((self.high * rank((self.high - self.close))) / (sma(self.high, 5) /5))) - rank((self.vwap - delay(self.vwap, 5)))) 558 | 559 | # Alpha#48 (indneutralize(((correlation(delta(close, 1), delta(delay(close, 1), 1), 250) *delta(close, 1)) / close), IndClass.subindustry) / sum(((delta(close, 1) / delay(close, 1))^2), 250)) 560 | 561 | 562 | # Alpha#49 (((((delay(close, 20) - delay(close, 10)) / 10) - ((delay(close, 10) - close) / 10)) < (-1 *0.1)) ? 1 : ((-1 * 1) * (close - delay(close, 1)))) 563 | def alpha049(self): 564 | inner = (((delay(self.close, 20) - delay(self.close, 10)) / 10) - ((delay(self.close, 10) - self.close) / 10)) 565 | alpha = (-1 * delta(self.close)) 566 | alpha[inner < -0.1] = 1 567 | return alpha 568 | 569 | # Alpha#50 (-1 * ts_max(rank(correlation(rank(volume), rank(vwap), 5)), 5)) 570 | def alpha050(self): 571 | return (-1 * ts_max(rank(correlation(rank(self.volume), rank(self.vwap), 5)), 5)) 572 | 573 | # Alpha#51 (((((delay(close, 20) - delay(close, 10)) / 10) - ((delay(close, 10) - close) / 10)) < (-1 *0.05)) ? 1 : ((-1 * 1) * (close - delay(close, 1)))) 574 | def alpha051(self): 575 | inner = (((delay(self.close, 20) - delay(self.close, 10)) / 10) - ((delay(self.close, 10) - self.close) / 10)) 576 | alpha = (-1 * delta(self.close)) 577 | alpha[inner < -0.05] = 1 578 | return alpha 579 | 580 | # Alpha#52 ((((-1 * ts_min(low, 5)) + delay(ts_min(low, 5), 5)) * rank(((sum(returns, 240) -sum(returns, 20)) / 220))) * ts_rank(volume, 5)) 581 | def alpha052(self): 582 | return (((-1 * delta(ts_min(self.low, 5), 5)) * 583 | rank(((ts_sum(self.returns, 240) - ts_sum(self.returns, 20)) / 220))) * ts_rank(self.volume, 5)) 584 | 585 | # Alpha#53 (-1 * delta((((close - low) - (high - close)) / (close - low)), 9)) 586 | def alpha053(self): 587 | inner = (self.close - self.low).replace(0, 0.0001) 588 | return -1 * delta((((self.close - self.low) - (self.high - self.close)) / inner), 9) 589 | 590 | # Alpha#54 ((-1 * ((low - close) * (open^5))) / ((low - high) * (close^5))) 591 | def alpha054(self): 592 | inner = (self.low - self.high).replace(0, -0.0001) 593 | return -1 * (self.low - self.close) * (self.open ** 5) / (inner * (self.close ** 5)) 594 | 595 | # Alpha#55 (-1 * correlation(rank(((close - ts_min(low, 12)) / (ts_max(high, 12) - ts_min(low,12)))), rank(volume), 6)) 596 | def alpha055(self): 597 | divisor = (ts_max(self.high, 12) - ts_min(self.low, 12)).replace(0, 0.0001) 598 | inner = (self.close - ts_min(self.low, 12)) / (divisor) 599 | df = correlation(rank(inner), rank(self.volume), 6) 600 | return -1 * df.replace([-np.inf, np.inf], 0).fillna(value=0) 601 | 602 | # Alpha#56 (0 - (1 * (rank((sum(returns, 10) / sum(sum(returns, 2), 3))) * rank((returns * cap))))) 603 | # This Alpha uses the Cap, however I have not acquired the data yet 604 | # def alpha056(self): 605 | # return (0 - (1 * (rank((sma(self.returns, 10) / sma(sma(self.returns, 2), 3))) * rank((self.returns * self.cap))))) 606 | 607 | # Alpha#57 (0 - (1 * ((close - vwap) / decay_linear(rank(ts_argmax(close, 30)), 2)))) 608 | def alpha057(self): 609 | return (0 - (1 * ((self.close - self.vwap) / decay_linear(rank(ts_argmax(self.close, 30)).to_frame(), 2).CLOSE))) 610 | 611 | # Alpha#58 (-1 * Ts_Rank(decay_linear(correlation(IndNeutralize(vwap, IndClass.sector), volume,3.92795), 7.89291), 5.50322)) 612 | 613 | # Alpha#59 (-1 * Ts_Rank(decay_linear(correlation(IndNeutralize(((vwap * 0.728317) + (vwap *(1 - 0.728317))), IndClass.industry), volume, 4.25197), 16.2289), 8.19648)) 614 | 615 | 616 | # Alpha#60 (0 - (1 * ((2 * scale(rank(((((close - low) - (high - close)) / (high - low)) * volume)))) -scale(rank(ts_argmax(close, 10)))))) 617 | def alpha060(self): 618 | divisor = (self.high - self.low).replace(0, 0.0001) 619 | inner = ((self.close - self.low) - (self.high - self.close)) * self.volume / divisor 620 | return - ((2 * scale(rank(inner))) - scale(rank(ts_argmax(self.close, 10)))) 621 | 622 | # Alpha#61 (rank((vwap - ts_min(vwap, 16.1219))) < rank(correlation(vwap, adv180, 17.9282))) 623 | def alpha061(self): 624 | adv180 = sma(self.volume, 180) 625 | return (rank((self.vwap - ts_min(self.vwap, 16))) < rank(correlation(self.vwap, adv180, 18))) 626 | 627 | # Alpha#62 ((rank(correlation(vwap, sum(adv20, 22.4101), 9.91009)) < rank(((rank(open) +rank(open)) < (rank(((high + low) / 2)) + rank(high))))) * -1) 628 | def alpha062(self): 629 | adv20 = sma(self.volume, 20) 630 | return ((rank(correlation(self.vwap, sma(adv20, 22), 10)) < rank(((rank(self.open) +rank(self.open)) < (rank(((self.high + self.low) / 2)) + rank(self.high))))) * -1) 631 | 632 | # Alpha#63 ((rank(decay_linear(delta(IndNeutralize(close, IndClass.industry), 2.25164), 8.22237))- rank(decay_linear(correlation(((vwap * 0.318108) + (open * (1 - 0.318108))), sum(adv180,37.2467), 13.557), 12.2883))) * -1) 633 | 634 | 635 | # Alpha#64 ((rank(correlation(sum(((open * 0.178404) + (low * (1 - 0.178404))), 12.7054),sum(adv120, 12.7054), 16.6208)) < rank(delta(((((high + low) / 2) * 0.178404) + (vwap * (1 -0.178404))), 3.69741))) * -1) 636 | def alpha064(self): 637 | adv120 = sma(self.volume, 120) 638 | return ((rank(correlation(sma(((self.open * 0.178404) + (self.low * (1 - 0.178404))), 13),sma(adv120, 13), 17)) < rank(delta(((((self.high + self.low) / 2) * 0.178404) + (self.vwap * (1 -0.178404))), 3.69741))) * -1) 639 | 640 | # Alpha#65 ((rank(correlation(((open * 0.00817205) + (vwap * (1 - 0.00817205))), sum(adv60,8.6911), 6.40374)) < rank((open - ts_min(open, 13.635)))) * -1) 641 | def alpha065(self): 642 | adv60 = sma(self.volume, 60) 643 | return ((rank(correlation(((self.open * 0.00817205) + (self.vwap * (1 - 0.00817205))), sma(adv60,9), 6)) < rank((self.open - ts_min(self.open, 14)))) * -1) 644 | 645 | # Alpha#66 ((rank(decay_linear(delta(vwap, 3.51013), 7.23052)) + Ts_Rank(decay_linear(((((low* 0.96633) + (low * (1 - 0.96633))) - vwap) / (open - ((high + low) / 2))), 11.4157), 6.72611)) * -1) 646 | def alpha066(self): 647 | return ((rank(decay_linear(delta(self.vwap, 4).to_frame(), 7).CLOSE) + ts_rank(decay_linear(((((self.low* 0.96633) + (self.low * (1 - 0.96633))) - self.vwap) / (self.open - ((self.high + self.low) / 2))).to_frame(), 11).CLOSE, 7)) * -1) 648 | 649 | # Alpha#67 ((rank((high - ts_min(high, 2.14593)))^rank(correlation(IndNeutralize(vwap,IndClass.sector), IndNeutralize(adv20, IndClass.subindustry), 6.02936))) * -1) 650 | 651 | 652 | # Alpha#68 ((Ts_Rank(correlation(rank(high), rank(adv15), 8.91644), 13.9333) =df['p2'],'max']=df['p1'] 669 | df.at[df['p2']>=df['p1'],'max']=df['p2'] 670 | return df['max'] 671 | #return max(ts_rank(decay_linear(correlation(ts_rank(self.close, 3), ts_rank(adv180,12), 18).to_frame(), 4).CLOSE, 16), ts_rank(decay_linear((rank(((self.low + self.open) - (self.vwap +self.vwap))).pow(2)).to_frame(), 16).CLOSE, 4)) 672 | 673 | # Alpha#72 (rank(decay_linear(correlation(((high + low) / 2), adv40, 8.93345), 10.1519)) /rank(decay_linear(correlation(Ts_Rank(vwap, 3.72469), Ts_Rank(volume, 18.5188), 6.86671),2.95011))) 674 | def alpha072(self): 675 | adv40 = sma(self.volume, 40) 676 | return (rank(decay_linear(correlation(((self.high + self.low) / 2), adv40, 9).to_frame(), 10).CLOSE) /rank(decay_linear(correlation(ts_rank(self.vwap, 4), ts_rank(self.volume, 19), 7).to_frame(),3).CLOSE)) 677 | 678 | # Alpha#73 (max(rank(decay_linear(delta(vwap, 4.72775), 2.91864)),Ts_Rank(decay_linear(((delta(((open * 0.147155) + (low * (1 - 0.147155))), 2.03608) / ((open *0.147155) + (low * (1 - 0.147155)))) * -1), 3.33829), 16.7411)) * -1) 679 | def alpha073(self): 680 | p1=rank(decay_linear(delta(self.vwap, 5).to_frame(), 3).CLOSE) 681 | p2=ts_rank(decay_linear(((delta(((self.open * 0.147155) + (self.low * (1 - 0.147155))), 2) / ((self.open *0.147155) + (self.low * (1 - 0.147155)))) * -1).to_frame(), 3).CLOSE, 17) 682 | df=pd.DataFrame({'p1':p1,'p2':p2}) 683 | df.at[df['p1']>=df['p2'],'max']=df['p1'] 684 | df.at[df['p2']>=df['p1'],'max']=df['p2'] 685 | return -1*df['max'] 686 | #return (max(rank(decay_linear(delta(self.vwap, 5).to_frame(), 3).CLOSE),ts_rank(decay_linear(((delta(((self.open * 0.147155) + (self.low * (1 - 0.147155))), 2) / ((self.open *0.147155) + (self.low * (1 - 0.147155)))) * -1).to_frame(), 3).CLOSE, 17)) * -1) 687 | 688 | # Alpha#74 ((rank(correlation(close, sum(adv30, 37.4843), 15.1365)) =df['p2'],'min']=df['p2'] 708 | df.at[df['p2']>=df['p1'],'min']=df['p1'] 709 | return df['min'] 710 | #return min(rank(decay_linear(((((self.high + self.low) / 2) + self.high) - (self.vwap + self.high)).to_frame(), 20).CLOSE),rank(decay_linear(correlation(((self.high + self.low) / 2), adv40, 3).to_frame(), 6).CLOSE)) 711 | 712 | # Alpha#78 (rank(correlation(sum(((low * 0.352233) + (vwap * (1 - 0.352233))), 19.7428),sum(adv40, 19.7428), 6.83313))^rank(correlation(rank(vwap), rank(volume), 5.77492))) 713 | def alpha078(self): 714 | adv40 = sma(self.volume, 40) 715 | return (rank(correlation(ts_sum(((self.low * 0.352233) + (self.vwap * (1 - 0.352233))), 20),ts_sum(adv40,20), 7)).pow(rank(correlation(rank(self.vwap), rank(self.volume), 6)))) 716 | 717 | # Alpha#79 (rank(delta(IndNeutralize(((close * 0.60733) + (open * (1 - 0.60733))),IndClass.sector), 1.23438)) < rank(correlation(Ts_Rank(vwap, 3.60973), Ts_Rank(adv150,9.18637), 14.6644))) 718 | 719 | # Alpha#80 ((rank(Sign(delta(IndNeutralize(((open * 0.868128) + (high * (1 - 0.868128))),IndClass.industry), 4.04545)))^Ts_Rank(correlation(high, adv10, 5.11456), 5.53756)) * -1) 720 | 721 | 722 | # Alpha#81 ((rank(Log(product(rank((rank(correlation(vwap, sum(adv10, 49.6054),8.47743))^4)), 14.9655))) < rank(correlation(rank(vwap), rank(volume), 5.07914))) * -1) 723 | def alpha081(self): 724 | adv10 = sma(self.volume, 10) 725 | return ((rank(log(product(rank((rank(correlation(self.vwap, ts_sum(adv10, 50),8)).pow(4))), 15))) < rank(correlation(rank(self.vwap), rank(self.volume), 5))) * -1) 726 | 727 | # Alpha#82 (min(rank(decay_linear(delta(open, 1.46063), 14.8717)),Ts_Rank(decay_linear(correlation(IndNeutralize(volume, IndClass.sector), ((open * 0.634196) +(open * (1 - 0.634196))), 17.4842), 6.92131), 13.4283)) * -1) 728 | 729 | 730 | # Alpha#83 ((rank(delay(((high - low) / (sum(close, 5) / 5)), 2)) * rank(rank(volume))) / (((high -low) / (sum(close, 5) / 5)) / (vwap - close))) 731 | def alpha083(self): 732 | return ((rank(delay(((self.high - self.low) / (ts_sum(self.close, 5) / 5)), 2)) * rank(rank(self.volume))) / (((self.high -self.low) / (ts_sum(self.close, 5) / 5)) / (self.vwap - self.close))) 733 | 734 | # Alpha#84 SignedPower(Ts_Rank((vwap - ts_max(vwap, 15.3217)), 20.7127), delta(close,4.96796)) 735 | def alpha084(self): 736 | return pow(ts_rank((self.vwap - ts_max(self.vwap, 15)), 21), delta(self.close,5)) 737 | 738 | # Alpha#85 (rank(correlation(((high * 0.876703) + (close * (1 - 0.876703))), adv30,9.61331))^rank(correlation(Ts_Rank(((high + low) / 2), 3.70596), Ts_Rank(volume, 10.1595),7.11408))) 739 | def alpha085(self): 740 | adv30 = sma(self.volume, 30) 741 | return (rank(correlation(((self.high * 0.876703) + (self.close * (1 - 0.876703))), adv30,10)).pow(rank(correlation(ts_rank(((self.high + self.low) / 2), 4), ts_rank(self.volume, 10),7)))) 742 | 743 | # Alpha#86 ((Ts_Rank(correlation(close, sum(adv20, 14.7444), 6.00049), 20.4195) < rank(((open+ close) - (vwap + open)))) * -1) 744 | 745 | def alpha086(self): 746 | adv20 = sma(self.volume, 20) 747 | return ((ts_rank(correlation(self.close, sma(adv20, 15), 6), 20) < rank(((self.open+ self.close) - (self.vwap +self.open)))) * -1) 748 | 749 | # Alpha#87 (max(rank(decay_linear(delta(((close * 0.369701) + (vwap * (1 - 0.369701))),1.91233), 2.65461)), Ts_Rank(decay_linear(abs(correlation(IndNeutralize(adv81,IndClass.industry), close, 13.4132)), 4.89768), 14.4535)) * -1) 750 | 751 | 752 | # Alpha#88 min(rank(decay_linear(((rank(open) + rank(low)) - (rank(high) + rank(close))),8.06882)), Ts_Rank(decay_linear(correlation(Ts_Rank(close, 8.44728), Ts_Rank(adv60,20.6966), 8.01266), 6.65053), 2.61957)) 753 | def alpha088(self): 754 | adv60 = sma(self.volume, 60) 755 | p1=rank(decay_linear(((rank(self.open) + rank(self.low)) - (rank(self.high) + rank(self.close))).to_frame(),8).CLOSE) 756 | p2=ts_rank(decay_linear(correlation(ts_rank(self.close, 8), ts_rank(adv60,21), 8).to_frame(), 7).CLOSE, 3) 757 | df=pd.DataFrame({'p1':p1,'p2':p2}) 758 | df.at[df['p1']>=df['p2'],'min']=df['p2'] 759 | df.at[df['p2']>=df['p1'],'min']=df['p1'] 760 | return df['min'] 761 | #return min(rank(decay_linear(((rank(self.open) + rank(self.low)) - (rank(self.high) + rank(self.close))).to_frame(),8).CLOSE), ts_rank(decay_linear(correlation(ts_rank(self.close, 8), ts_rank(adv60,20.6966), 8).to_frame(), 7).CLOSE, 3)) 762 | 763 | # Alpha#89 (Ts_Rank(decay_linear(correlation(((low * 0.967285) + (low * (1 - 0.967285))), adv10,6.94279), 5.51607), 3.79744) - Ts_Rank(decay_linear(delta(IndNeutralize(vwap,IndClass.industry), 3.48158), 10.1466), 15.3012)) 764 | 765 | # Alpha#90 ((rank((close - ts_max(close, 4.66719)))^Ts_Rank(correlation(IndNeutralize(adv40,IndClass.subindustry), low, 5.38375), 3.21856)) * -1) 766 | 767 | # Alpha#91 ((Ts_Rank(decay_linear(decay_linear(correlation(IndNeutralize(close,IndClass.industry), volume, 9.74928), 16.398), 3.83219), 4.8667) -rank(decay_linear(correlation(vwap, adv30, 4.01303), 2.6809))) * -1) 768 | 769 | 770 | # Alpha#92 min(Ts_Rank(decay_linear(((((high + low) / 2) + close) < (low + open)), 14.7221),18.8683), Ts_Rank(decay_linear(correlation(rank(low), rank(adv30), 7.58555), 6.94024),6.80584)) 771 | def alpha092(self): 772 | adv30 = sma(self.volume, 30) 773 | p1=ts_rank(decay_linear(((((self.high + self.low) / 2) + self.close) < (self.low + self.open)).to_frame(), 15).CLOSE,19) 774 | p2=ts_rank(decay_linear(correlation(rank(self.low), rank(adv30), 8).to_frame(), 7).CLOSE,7) 775 | df=pd.DataFrame({'p1':p1,'p2':p2}) 776 | df.at[df['p1']>=df['p2'],'min']=df['p2'] 777 | df.at[df['p2']>=df['p1'],'min']=df['p1'] 778 | return df['min'] 779 | #return min(ts_rank(decay_linear(((((self.high + self.low) / 2) + self.close) < (self.low + self.open)).to_frame(), 15).CLOSE,19), ts_rank(decay_linear(correlation(rank(self.low), rank(adv30), 8).to_frame(), 7).CLOSE,7)) 780 | 781 | # Alpha#93 (Ts_Rank(decay_linear(correlation(IndNeutralize(vwap, IndClass.industry), adv81,17.4193), 19.848), 7.54455) / rank(decay_linear(delta(((close * 0.524434) + (vwap * (1 -0.524434))), 2.77377), 16.2664))) 782 | 783 | 784 | # Alpha#94 ((rank((vwap - ts_min(vwap, 11.5783)))^Ts_Rank(correlation(Ts_Rank(vwap,19.6462), Ts_Rank(adv60, 4.02992), 18.0926), 2.70756)) * -1) 785 | def alpha094(self): 786 | adv60 = sma(self.volume, 60) 787 | return ((rank((self.vwap - ts_min(self.vwap, 12))).pow(ts_rank(correlation(ts_rank(self.vwap,20), ts_rank(adv60, 4), 18), 3)) * -1)) 788 | 789 | # Alpha#95 (rank((open - ts_min(open, 12.4105))) < Ts_Rank((rank(correlation(sum(((high + low)/ 2), 19.1351), sum(adv40, 19.1351), 12.8742))^5), 11.7584)) 790 | def alpha095(self): 791 | adv40 = sma(self.volume, 40) 792 | return (rank((self.open - ts_min(self.open, 12))) < ts_rank((rank(correlation(sma(((self.high + self.low)/ 2), 19), sma(adv40, 19), 13)).pow(5)), 12)) 793 | 794 | # Alpha#96 (max(Ts_Rank(decay_linear(correlation(rank(vwap), rank(volume), 3.83878),4.16783), 8.38151), Ts_Rank(decay_linear(Ts_ArgMax(correlation(Ts_Rank(close, 7.45404),Ts_Rank(adv60, 4.13242), 3.65459), 12.6556), 14.0365), 13.4143)) * -1) 795 | def alpha096(self): 796 | adv60 = sma(self.volume, 60) 797 | p1=ts_rank(decay_linear(correlation(rank(self.vwap), rank(self.volume).to_frame(), 4),4).CLOSE, 8) 798 | p2=ts_rank(decay_linear(ts_argmax(correlation(ts_rank(self.close, 7),ts_rank(adv60, 4), 4), 13).to_frame(), 14).CLOSE, 13) 799 | df=pd.DataFrame({'p1':p1,'p2':p2}) 800 | df.at[df['p1']>=df['p2'],'max']=df['p1'] 801 | df.at[df['p2']>=df['p1'],'max']=df['p2'] 802 | return -1*df['max'] 803 | #return (max(ts_rank(decay_linear(correlation(rank(self.vwap), rank(self.volume).to_frame(), 4),4).CLOSE, 8), ts_rank(decay_linear(ts_argmax(correlation(ts_rank(self.close, 7),ts_rank(adv60, 4), 4), 13).to_frame(), 14).CLOSE, 13)) * -1) 804 | 805 | # Alpha#97 ((rank(decay_linear(delta(IndNeutralize(((low * 0.721001) + (vwap * (1 - 0.721001))),IndClass.industry), 3.3705), 20.4523)) - Ts_Rank(decay_linear(Ts_Rank(correlation(Ts_Rank(low,7.87871), Ts_Rank(adv60, 17.255), 4.97547), 18.5925), 15.7152), 6.71659)) * -1) 806 | 807 | 808 | # Alpha#98 (rank(decay_linear(correlation(vwap, sum(adv5, 26.4719), 4.58418), 7.18088)) -rank(decay_linear(Ts_Rank(Ts_ArgMin(correlation(rank(open), rank(adv15), 20.8187), 8.62571),6.95668), 8.07206))) 809 | def alpha098(self): 810 | adv5 = sma(self.volume, 5) 811 | adv15 = sma(self.volume, 15) 812 | return (rank(decay_linear(correlation(self.vwap, sma(adv5, 26), 5).to_frame(), 7).CLOSE) -rank(decay_linear(ts_rank(ts_argmin(correlation(rank(self.open), rank(adv15), 21), 9),7).to_frame(), 8).CLOSE)) 813 | 814 | # Alpha#99 ((rank(correlation(sum(((high + low) / 2), 19.8975), sum(adv60, 19.8975), 8.8136))