A Random Walk through a Random Forest
From Wikipedia, the free encyclopedia


def get_indicators(stocks, period):
stocks_indicators = {}
for i in stocks:
features = pd.DataFrame(SMA(stocks[i], timeperiod=10))
features.columns = ['sma_10']
features['mfi_10'] = pd.DataFrame(MFI(stocks[i], timeperiod=10))
features['mom_10'] = pd.DataFrame(MOM(stocks[i],10))
features['wma_10'] = pd.DataFrame(WMA(stocks[i],10))
features['ultosc_4'] = pd.DataFrame(ULTOSC(stocks[i],timeperiod1=4, timeperiod2=7, timeperiod3=14))
features = pd.concat([features,STOCHF(stocks[i],
fastk_period=14,
fastd_period=3)],
axis=1)
features['macd'] = pd.DataFrame(MACD(stocks[i], fastperiod=5, slowperiod=14)['macd'])
features['rsi'] = pd.DataFrame(RSI(stocks[i], timeperiod=14))
features['willr'] = pd.DataFrame(WILLR(stocks[i], timeperiod=14))
features['cci'] = pd.DataFrame(CCI(stocks[i], timeperiod=14))
features['adosc'] = pd.DataFrame(ADOSC(stocks[i], fastperiod=3, slowperiod=10))
features['raw_pct_change'] = ROCP(stocks[i], timeperiod=period)
features['raw_pct_change'] = features['raw_pct_change'].shift(-period)
features['pct_change'] = features['raw_pct_change'].apply(lambda x: '1' if x > 0.03 else '0')
features = features.dropna()
stocks_indicators[i] = features
return stocks_indicators

>>> pred = clf.predict(test[features])
>>> list(zip(train[features], clf.feature_importances_))
[('sma_10', '0.08805410862396797'), ('mfi_10', '0.09451084071039871'), ('mom_10', '0.069575191927391'), ('wma_10', '0.13220290244507055'), ('ultosc_4', '0.06845575657410827'), ('fastk', '0.05566000353802879'), ('fastd', '0.09610385618777093'), ('macd', '0.07816429691621057'), ('rsi', '0.06785865605512234'), ('willr', '0.07602636981442927'), ('cci', '0.06132717952251619'), ('adosc', '0.1120608376849855')]
>>> pd.crosstab(test['pct_change'],pred)
col_0 0 1
pct_change
0 142 7
1 30 11