Thermodynamics-Inspired Trading Strategy

Explore how our trading algorithm uses thermodynamics and statistical mechanics to optimize trading decisions.

Thermodynamics-Inspired Trading Research

All Juice Capital - May 2025. Advancing science through transparency and access. Contact Us on LinkedIn.

Research PDF and Python code Download

Note: Downloads are currently supported only on Google Chrome, Firefox, or other major browsers.

Features

Downloads historical stock data using yfinance - Generates buy/sell signals based on free energy gradients and entropy levels - Calculates moving averages, returns, energy, entropy, and free energy - Exports trade signals to a text file for analysis - Visualizes price trends, entropy changes, and energy metrics over time.

Abstract

This section introduces a trading algorithm inspired by thermodynamics, modeling market dynamics as a statistical mechanical system and optimizing trades via free energy gradient descent.

Thermodynamics in Financial Markets

We model markets as thermodynamic systems, where asset prices fluctuate like particles seeking minimal free energy. Key concepts include:

  • Energy (E): Deviation from equilibrium price squared.
  • Entropy (S): Market uncertainty measured as Shannon entropy.
  • Temperature (T): Market volatility or randomness.
  • Free Energy (F): Trade-off between return and uncertainty.
$F = E - T \cdot S$

In the thermodynamics-inspired trading strategy, what does the energy E represent?

The energy is defined as:

$E = (P_i - \mu)^2$

What does the temperature T represent in the trading model?

Entropy is calculated using Shannon entropy over the price distribution:

$S = -\sum_{i} p_i \log p_i$

How is the entropy S calculated in the trading strategy?

Free Energy Gradient Descent

Trades are optimized by descending the free energy landscape:

$\vec{x}_{t+1} = \vec{x}_t - \eta \nabla F(\vec{x}_t)$

What triggers a trade in the free energy gradient descent model?

# Function to compute free energy gradient
def compute_free_energy_gradient(prices, mean_price, probabilities, temperature):
    energy = sum((p - mean_price) ** 2 for p in prices)
    entropy = -sum(p * math.log(p) for p in probabilities if p > 0)
    free_energy = energy - temperature * entropy
    # Compute gradients (simplified)
    grad_energy = [2 * (p - mean_price) for p in prices]
    grad_entropy = [-(1 + math.log(p)) for p in probabilities if p > 0]
    grad_free_energy = [ge - temperature * gs for ge, gs in zip(grad_energy, grad_entropy)]
    return grad_free_energy

How is the position updated in the gradient descent rule?

Entropy-Based Position Sizing

High entropy indicates noisy markets, prompting reduced position sizes:

# Entropy-based position adjustment
def adjust_position(probabilities, entropy_threshold):
    entropy = -sum(p * math.log(p) for p in probabilities if p > 0)
    if entropy > entropy_threshold:
        return 0.5  # Reduce position size
    return 1.0  # Full position size

What happens when entropy S exceeds the threshold?

Trade Execution

A trade is executed if the free energy reduction exceeds a threshold:

$\Delta F = F_{current} - F_{proposed} > \delta_F$

# Trade execution based on free energy
def execute_trade(current_F, proposed_F, delta_F_threshold):
    delta_F = current_F - proposed_F
    if delta_F > delta_F_threshold:
        return True  # Execute trade
    return False  # Avoid trade

What does the partition function Z do in the trading model?