Sitemap

How to Use Neural Networks to Win Every Trade Before It Even Starts

4 min readJun 3, 2026

--

Press enter or click to view image in full size

Step 1: Data acquisition and cleaning

Use Polygondotio for institutional-grade tick and OHLCV data. For learning, yfinance is sufficient. Handle missing data, corporate actions, and splits before any feature engineering.

import yfinance as yf
import pandas as pd

ticker = yf.Ticker("SPY")
df = ticker.history(period="5y", interval="1d")
df = df[['Open', 'High', 'Low', 'Close', 'Volume']].copy()
df.dropna(inplace=True)

Step 2: Feature engineering

Build your complete stationary feature set. Every feature must pass the Augmented Dickey-Fuller test.

def build_features(df):
features = pd.DataFrame(index=df.index)

close = df['Close']
volume = df['Volume']
returns = close.pct_change()

features['return_1d'] = returns
features['return_5d'] = close.pct_change(5)
features['return_20d'] = close.pct_change(20)

vol_5 = returns.rolling(5).std()
vol_20 = returns.rolling(20).std()
features['vol_ratio'] = vol_5 / vol_20
features['momentum_norm'] = returns / vol_20

features['volume_zscore'] = (
(volume - volume.rolling(20).mean()) / volume.rolling(20).std()
)

high_low_range = (df['High'] - df['Low']) / close
features['range_norm'] = high_low_range / high_low_range.rolling(20).mean()

sma_5 = close.rolling(5).mean()
sma_20 = close.rolling(20).mean()
features['sma_ratio'] = sma_5 / sma_20 - 1

target = (returns.shift(-1) > 0).astype(int)

features = features.dropna()
target = target.loc[features.index]

return features, target

Step 3: Sequential split and scaling

def prepare_data(features, target, lookback=10, train_ratio=0.6, val_ratio=0.2):
n = len(features)
train_end = int(n * train_ratio)
val_end = int(n * (train_ratio + val_ratio))

scaler = StandardScaler()
features_scaled = scaler.fit_transform(features[:train_end])

features_array = np.vstack([
features_scaled,
scaler.transform(features[train_end:val_end]),
scaler.transform(features[val_end:])
])

X, y = prepare_sequences(features_array, target.values, lookback)

X_train = torch.FloatTensor(X[:train_end - lookback])
y_train = torch.FloatTensor(y[:train_end - lookback])
X_val = torch.FloatTensor(X[train_end - lookback:val_end - lookback])
y_val = torch.FloatTensor(y[train_end - lookback:val_end - lookback])
X_test = torch.FloatTensor(X[val_end - lookback:])
y_test = torch.FloatTensor(y[val_end - lookback:])

return X_train, y_train, X_val, y_val, X_test, y_test, scaler

Step 4: Model evaluation

Beyond directional accuracy, evaluate your model using metrics that matter for trading.

from sklearn.metrics import accuracy_score, roc_auc_score
import pandas as pd

def evaluate_trading_signal(predictions, actuals, returns):
pred_direction = (predictions > 0.5).astype(int)

accuracy = accuracy_score(actuals, pred_direction)
auc = roc_auc_score(actuals, predictions)

signal = np.where(pred_direction == 1, 1, -1)
strategy_returns = signal * returns

sharpe = strategy_returns.mean() / strategy_returns.std() * np.sqrt(252)

cumulative = (1 + strategy_returns).cumprod()
rolling_max = cumulative.cummax()
drawdown = (cumulative - rolling_max) / rolling_max
max_drawdown = drawdown.min()

print(f"Directional Accuracy: {accuracy:.4f}")
print(f"AUC-ROC: {auc:.4f}")
print(f"Annualized Sharpe: {sharpe:.4f}")
print(f"Maximum Drawdown: {max_drawdown:.4f}")

return accuracy, sharpe, max_drawdown

Step 5: Signal to position sizing

Get Retro Valix’s stories in your inbox

Join Medium for free to get updates from this writer.

A neural network signal alone is not a trading strategy. You need position sizing. The Kelly fraction translates your model’s edge into an optimal bet size:

f* = (p × b — q) / b

Where p is your directional accuracy, q = 1 — p, and b is the average win-to-loss ratio. In practice, use half Kelly to account for parameter estimation error. Never risk more than 2 percent of capital on a single signal regardless of what Kelly recommends.

Step 6: Continuous monitoring and retraining

A model trained on historical data begins degrading the moment it is deployed. Market regimes shift. The conditional expectation the model learned becomes a progressively worse approximation of the current expectation. You must implement a monitoring system that tracks live performance against your validation baseline and triggers retraining when the distribution has shifted beyond an acceptable threshold.

The standard metric is the Kolmogorov-Smirnov statistic comparing your recent live prediction distribution to the historical validation distribution. When the KS statistic exceeds 0.1, retrain on the most recent data and re-evaluate before continuing to deploy.

For prediction markets and crypto specifically, regime shifts are more frequent and more violent than in equity markets. Retraining on a rolling 90-day window with walk-forward re-evaluation every 30 days is a reasonable baseline.

The Summary

Neural networks do not give you a crystal ball. What they give you is a systematic, mathematically rigorous framework for extracting the conditional expectation of market behavior from historical data. When the features are stationary, the architecture is appropriate for sequential data, the training is disciplined and validated correctly, and the signal is sized with proper position management, the result is an edge that is consistent, scalable, and reproducible.

Two Sigma runs 10,000 signals simultaneously through this framework. Renaissance built the highest returning fund in financial history on it. The entry level researcher implementing it earns $650,000 per year.

The complete implementation is in this article. The mathematics is learnable. The code is buildable in a weekend. The only thing that separates the systematic funds from everyone else is knowing the correct framework and the discipline to follow it without cutting corners.

Now you know the framework.

Here is the question I want you to sit with.

A neural network trained on your current indicator set will learn the conditional expectation of market returns given those indicators. But the conditional expectation is only as good as the features you condition on. If you had to add exactly one new feature to your model that you believe no other systematic trader is using, what would it be and why?

Drop your answer in the comments.

There is no wrong answer but there are very revealing ones.

--

--

Retro Valix
Retro Valix

Written by Retro Valix

AI Builder & Researcher | 5Y in Crypto | Polymarket Trader || Telegram: @RetroValix