Anyone here exploring AI/ML based strategies for active trading?
I have been working on this for couple of years on the side and last few months full time. I have been creating simple ML models of different combinations. Though I am fairly early in my journey, what seems to be working out for me is 0 to 5 min timeframe, where the impact of macro factors in minimal. The best performing model that I have today takes 10 candles of 1 min timeframe and tries to predict the 11th candle. Have been able to achieve profitability without brokerage and transaction costs. Need to fine-tine this model more or apply it on the right stocks. I will continue on this path for a while and see what happens; before calling it quits.
Would love to learn what others have been doing on the AI/ML side. Always open to exchanging notes in this field.
I have a couple of ML logics that I have developed for long term purposes. I am specializing in LFT, so it really does not work, so not using it right now.
Have been able to achieve profitability without brokerage and transaction costs
Whatever you do, you must check the real cost. We can't say profitability without checking the cost. As a trader, brokerage and transaction costs are a nightmare as we are facing tax terrorism. So always check your strategy with cost, then confirm whether your logic is effective or not.
@ANL agreed. The litmus test for any AI or any algorithm for that matter is if it is able to make you any significant money, after all the costs, after taxation, after all the hassle.
I changed my AI model to predict 11th and 12th candle and used its combination to generate a signal. While the number of signals have dropped drastically, the model seems to have achieved profitability after transaction costs. Will keep fine tuning this further.
import numpy as np import pandas as pd from sklearn.preprocessing import MinMaxScaler from tensorflow.keras.models import Sequential from tensorflow.keras.layers import LSTM, Dense
# Load data data = pd.read_csv('one_minute_data.csv')
# Feature selection features = ['Open', 'High', 'Low', 'Close', 'Volume'] data = data[features]
# Build model model = Sequential() model.add(LSTM(50, input_shape=(X_train.shape[1], X_train.shape[2]))) model.add(Dense(1)) # Predicting one value (e.g., next 'Close' price) model.compile(optimizer='adam', loss='mean_squared_error')
# Train model model.fit(X_train, y_train, epochs=10, batch_size=32, validation_split=0.1)
@naveenarya applying LSTM on ohlcv data is the first thing folks tend to do. I did that as well years back. Unfortunately either it did not work out for me or I gave up too soon on it. Simpler deep neural network kind of architecture works for me.
Nonetheless, I would love to hear how does this model perform for you.
LTSM, GRU etc work on dynamic memory. My hypothesis is not dynamic memory, but rather for fixed set of candles, last 10 to be precise. A simile deep neural network that replaces a deterministic approach of technical analysis should work. I have also simplified the input data instead of 5 different inputs, I just input a normalised value of (closePrice - openPrice) over the range.
Also, coupling your neural network with genetic algorithms with save you lot of hassle of trying different combinations of the structure.
I changed my AI model to predict 11th and 12th candle and used its combination to generate a signal. While the number of signals have dropped drastically, the model seems to have achieved profitability after transaction costs. Will keep fine tuning this further.
import pandas as pd
from sklearn.preprocessing import MinMaxScaler
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import LSTM, Dense
# Load data
data = pd.read_csv('one_minute_data.csv')
# Feature selection
features = ['Open', 'High', 'Low', 'Close', 'Volume']
data = data[features]
# Scaling
scaler = MinMaxScaler()
scaled_data = scaler.fit_transform(data)
# Create sequences
def create_sequences(data, seq_length=10):
X, y = [], []
for i in range(len(data) - seq_length):
X.append(data[i:i + seq_length])
y.append(data[i + seq_length, data.columns.get_loc('Close')]) # Predicting 'Close' price
return np.array(X), np.array(y)
X, y = create_sequences(scaled_data)
# Split data
split = int(0.8 * len(X))
X_train, X_test = X[:split], X[split:]
y_train, y_test = y[:split], y[split:]
# Build model
model = Sequential()
model.add(LSTM(50, input_shape=(X_train.shape[1], X_train.shape[2])))
model.add(Dense(1)) # Predicting one value (e.g., next 'Close' price)
model.compile(optimizer='adam', loss='mean_squared_error')
# Train model
model.fit(X_train, y_train, epochs=10, batch_size=32, validation_split=0.1)
Nonetheless, I would love to hear how does this model perform for you.
Yeah it didn't work as expected, too many negative signals.
How is your approach for this.?
Would you mind sharing notes.?
Also, coupling your neural network with genetic algorithms with save you lot of hassle of trying different combinations of the structure.