Skip to content

Instantly share code, notes, and snippets.

@quantra-go-algo
Last active July 14, 2023 13:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save quantra-go-algo/405f1cb252447663767da6f00fb194b2 to your computer and use it in GitHub Desktop.
Save quantra-go-algo/405f1cb252447663767da6f00fb194b2 to your computer and use it in GitHub Desktop.
# Features construction
data['Open-Close'] = (data.Open - data.Close)/data.Open
data['High-Low'] = (data.High - data.Low)/data.Low
data['percent_change'] = data['Adj Close'].pct_change()
data['std_5'] = data['percent_change'].rolling(5).std()
data['ret_5'] = data['percent_change'].rolling(5).mean()
data.dropna(inplace=True)
# X is the input variable
X = data[['Open-Close', 'High-Low', 'std_5', 'ret_5']]
# Y is the target or output variable
y = np.where(data['Adj Close'].shift(-1) > data['Adj Close'], 1, -1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment