micro-neuron-finance
v1.0.0
Published
Experimental comparison of a classical (degree-0) neuron against a degree-(-1) microstate neuron on Yahoo Finance data.
Maintainers
Readme
micro-neuron-finance
An experimental comparison of a classical (degree-0) neuron against a degree-(-1) microstate neuron on real Yahoo Finance data, derived from the logarithmic-exponential conjugation principle.
This repository is the finance-focused sibling of conjugate-neuron. Where conjugate-neuron explored the degree (-1) microstate neuron on synthetic data and MNIST handwriting (finding it suffered from gradient dilution in high-dimensional classification), this repo applies the same neuron to financial return prediction — a domain where its probabilistic, partition-function semantics give it a structural advantage.
The hypothesis
Financial markets are inherently probabilistic systems. At each timestep, the market "chooses" among multiple scenarios, and the aggregate outcome is a weighted sum over these scenarios. The microstate neuron (degree -1) computes exactly this aggregation natively:
z = log( Σ exp(w_i + x_i) + exp(b) )This is the logarithm of a local partition function — the same mathematical object used in statistical mechanics to aggregate microstates, and in McFadden's multinomial logit model (Nobel Prize in Economics, 2000) to model discrete choice under uncertainty.
The classical neuron (degree 0), by contrast, computes a weighted sum:
z = Σ w_i · x_i + bwhich has no probabilistic interpretation.
The hypothesis: because financial returns are generated by a mixture of latent probabilistic scenarios, the microstate neuron's partition-function inductive bias should produce better predictions than the classical neuron's additive bias.
Key results (confirmed)
On real Yahoo Finance data (AAPL and GLD, 2010-2024, 9 walk-forward windows per asset):
| Metric | Classical | Microstate | Verdict | |--------|-----------|------------|---------| | MSE ratio (micro / classical) | — | 0.58 - 0.68 | Microstate 32-42% better | | R² | -0.56 to -0.85 | -0.05 to -0.10 | Microstate 6-18x closer to zero | | Correlation | -0.04 to -0.06 (anti-signal) | +0.005 to +0.044 (weak signal) | Sign flip | | Directional accuracy | 49-54% | 53-57% | +2-3 pp |
The key finding
The classical neuron doesn't just fail to predict — it anti-predicts. Its negative correlation means it systematically points in the wrong direction. The microstate neuron, by producing near-zero (but positive) correlation, avoids catastrophic predictions. In trading, avoiding catastrophic predictions is often more valuable than making accurate ones.
The mathematical core
The conjugation principle defines an infinite hierarchy of binary operations *_k:
a *_(k+1) b = exp( log(a) *_k log(b) )Setting *_0 = + gives:
| Degree | Operation | Closed form | Neuron type |
|--------|-----------|-------------|------------|
| -1 | *_{-1} | log(e^a + e^b) (LogSumExp) | Microstate (this repo) |
| 0 | + | a + b (addition) | Classical |
| +1 | *_2 | exp(log a · log b) | Cobb-Douglas (see cobb-douglas-neuron) |
The microstate neuron (degree -1)
A classical neuron uses × (degree 1) to combine weights and inputs, and + (degree 0) to aggregate. A degree-(-1) microstate neuron displaces both operations downward by one level:
- Combination:
×(degree 1) ->+(degree 0) - Aggregation:
+(degree 0) ->LogSumExp(degree -1)
The resulting neuron computes:
z = log( Σ exp(w_i + x_i) + exp(b) )The gradient of this expression with respect to each weight is exactly the softmax function — no external softmax layer is needed. The microstate neuron has attention built into its arithmetic.
Unlike the Cobb-Douglas neuron, the microstate neuron does not require positive inputs. It works with any real-valued features, including z-scored log-returns — the standard representation in quantitative finance.
What the experiment tests
For each walk-forward window, the runner trains two networks under identical conditions:
| | Classical neuron (degree 0) | Microstate neuron (degree -1) |
|---|---|---|
| Pre-activation | z = Σ wᵢxᵢ + b | z = log( Σ exp(wᵢ + xᵢ) + exp(b) ) |
| Combination op | × | + |
| Aggregation op | Σ | LogSumExp |
| Gradient | xᵢ (unbounded) | softmax (bounded in [0,1]) |
| Positivity constraint | None | None (works with any real values) |
| Natural domain | Additive/linear data | Probabilistic/high-uncertainty data |
Both share the same optimizer, learning rate, seed, architecture, and epoch budget. The only independent variable is the arithmetic of the hidden layers. The output layer is always classical (target can be negative).
Quick start
git clone https://github.com/Justo-Tapiador/micro-neuron-finance.git
cd micro-neuron-finance
npm install
# Download Yahoo Finance data (requires Python + yfinance)
python -m venv .venv
.venv\Scripts\pip install yfinance pandas # Windows
.venv\Scripts\python scripts\download_yahoo.py
# Run the finance experiment (headless, 9 windows, ~3 min)
npm start -- --finance --ticker AAPL --epochs 20 --max-windows 9
# Or start the interactive dashboard
npm start
# -> open http://localhost:3000Dashboard features
The dashboard at http://localhost:3000 provides:
- Synthetic experiments — test on XOR, spiral, Gaussian mixtures, etc.
- Finance experiments — train on real Yahoo Finance data (AAPL, GLD, SPY)
- Live training charts — loss and accuracy curves for both arithmetics
- Summary table — MSE, R², directional accuracy, correlation per model
- Structured log stream — color-coded, live progress updates
- Help modal — built-in user guide explaining how to use the dashboard and interpret results
CLI reference
# Finance experiment (classical vs microstate on Yahoo Finance data)
npm start -- --finance --ticker AAPL --epochs 20 --max-windows 9
npm start -- --finance --ticker GLD --temperature 0.3 --max-windows 5
# Synthetic experiment (quick test)
npm start -- --headless --dataset xor --epochs 300
# Dashboard
npm startFinance flags
| Flag | Default | Description |
|------|---------|-------------|
| --ticker <SYM> | SPY | SPY, AAPL, or GLD (must be downloaded first) |
| --epochs <n> | 20 | Epochs per walk-forward window |
| --lr <x> | 0.001 | Learning rate |
| --batch-size <n> | 32 | Mini-batch size |
| --max-windows <n> | 0 (all) | Walk-forward windows to run. Set to 1 for quick test. |
| --patience <n> | 20 | Early stopping patience |
| --temperature <T> | 1 | LSE temperature. T<1 sharpens softmax. |
Features (11, all log-return based)
Unlike the Cobb-Douglas experiments (which required positive features), the microstate neuron works with any real-valued features. We use log-returns and z-score normalisation — the standard representation in quantitative finance.
| # | Feature | Description |
|---|---------|-------------|
| 0 | log_ret_1d | Daily log-return |
| 1 | log_ret_5d | Weekly log-return |
| 2 | log_ret_21d | Monthly log-return |
| 3 | log_vol_ratio | Volume change (log) |
| 4 | log_hl_ratio | Intraday range (log) |
| 5 | log_co_ratio | Intraday move (log) |
| 6 | vol_21d | 21-day realised volatility |
| 7 | log_ma_ratio | MA5/MA20 crossover (log) |
| 8 | rsi_norm | Normalised RSI (centered at 0) |
| 9 | log_price_ma | Price/MA20 ratio (log) |
| 10 | momentum_10 | 10-day momentum |
Target: 5-day forward log-return y = log(P_{t+5} / P_t)
Architecture (hybrid)
- Hidden layers (16 tanh -> 8 tanh): use the chosen arithmetic (classical or microstate)
- Output layer (1 identity): always classical (target can be negative)
This isolates the effect of the arithmetic to the feature-processing layers, where the inductive bias matters.
Total parameter count: 337 per model.
Walk-forward validation
- Train: 5 years (~1,260 trading days)
- Validation: 6 months (~126 days, for early stopping)
- Test: 6 months (~126 days)
- Gap: 5 days (prevents target leakage)
- Step: 1 year forward
- Total: 9 windows covering 2015-2024
Repository structure
micro-neuron-finance/
├── src/
│ ├── arithmetic/
│ │ ├── Arithmetic.ts
│ │ ├── ClassicalArithmetic.ts
│ │ ├── MicroArithmetic.ts
│ │ └── index.ts
│ ├── tensor/
│ ├── nn/
│ ├── activations/
│ ├── losses/
│ ├── optimizers/
│ ├── datasets/
│ │ ├── Dataset.ts
│ │ └── YahooFinance.ts
│ ├── experiments/
│ │ ├── ExperimentRunner.ts
│ │ ├── FinanceExperiment.ts
│ │ └── runComparison.ts
│ ├── server/
│ │ ├── LogBus.ts
│ │ ├── server.ts
│ │ └── public/
│ ├── main.ts
│ └── index.ts
├── scripts/
│ └── download_yahoo.py
├── tests/
│ └── arithmetic.test.ts
├── docs/
│ ├── theory.md
│ ├── Microstate Neurons for Financial Return Prediction.pdf
│ └── mnn-finance.png
└── .github/workflows/ci.ymlRelated repositories
| Repo | Degree | Domain | Result | |------|--------|--------|--------| | conjugate-neuron | -1 | Synthetic + MNIST | Mixed: better calibration, gradient dilution in high-dim | | cobb-douglas-neuron | +1 | Synthetic + Finance | Success on multiplicative data; failed on finance | | micro-neuron-finance (this repo) | -1 | Finance | Success: 32-42% lower MSE, 6-18x better R² |
License
MIT — see LICENSE.
Citation
@software{micro-neuron-finance,
title = {micro-neuron-finance: Microstate Neurons for Financial Return Prediction},
author = {Tapiador García, Justo},
year = {2026},
url = {https://github.com/Justo-Tapiador/micro-neuron-finance},
}