Machine Learning, Investment, AI, Sklearn, Quant.
delta = dataset['Close'].diff(1) gain = (delta.where(delta > 0, 0)).rolling(window=14).mean() loss = (-delta.where(delta < 0, 0)).rolling(window=14).mean() rs = gain / loss dataset['RSI'] = 100 - (100 / (1 + rs)) # Drop rows with NaN values generated by rolling windows dataset.dropna(inplace=True)