Random useful code snippets

Random stuff that I found on the net that looks to be useful.

note: might be useful to export jupyter notebooks as markdown and then insert it into the blog

# when computing multiple moving averages:
#for i in range(2, 10):
#    df['MA{}'.format(i)] = df.rolling(window=i).mean()

# aggreagate average of all MAs, but you can modify this easily to do other stuff    
#df[[f for f in list(df) if "MA" in f]].mean(axis=1)    
reversed_string=string[::-1]
import glob
filepaths = glob.glob(path.join(output_folder, "*.csv.gz"))
filepaths = sorted(filepaths)
filepaths
crossover = ( (SMA_50 <= SMA_200) & (SMA_50.shift(1) > SMA_100.shift(1) | 
(SMA_50 >= SMA_200) & (SMA_50.shift(1) < SMA_100.shift(1)))
)

crossover_price = df.loc[crossover, 'SMA_200']
plt.scatter(crossover_price.index, crossover_price)
tickers = ['AAPL', 'GOOG']
for ticker in tickers:
    globals()[ticker] = web.DataReader(stock,'yahoo',start,end) 
AAPL.head()