Loading...
Karpathy's micrograd is 150 lines that teach you every line of PyTorch. We adapt it to predict next-bar direction.
micrograd is a tiny autograd engine. You build expressions like x*w + b and it tracks gradients automatically through backprop.
For trading: a single neuron that takes (RSI, ROC, volume) and predicts P(next bar is up).
y_pred = sigmoid(w1*rsi + w2*roc + w3*volume + b)
loss = -y_actual * log(y_pred) - (1-y_actual) * log(1-y_pred)
# backprop — adjust w1, w2, w3, b to reduce lossBecause you can hand-verify the math. When you later use 100M-parameter networks, that intuition stays.
Implement manual gradient descent for the single neuron below. Train it to predict whether tomorrow's BTC close is higher than today's, using today's RSI and ROC.
Target: train loss < 0.65 after 200 steps.