Explore how our trading algorithm uses thermodynamics and statistical mechanics to optimize trading decisions.
All Juice Capital - May 2025. Advancing science through transparency and access. Contact Us on LinkedIn.
Note: Downloads are currently supported only on Google Chrome, Firefox, or other major browsers.
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.
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.
We model markets as thermodynamic systems, where asset prices fluctuate like particles seeking minimal free energy. Key concepts include:
The energy is defined as:
Entropy is calculated using Shannon entropy over the price distribution:
Trades are optimized by descending the free energy landscape:
# 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
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
A trade is executed if the free energy reduction exceeds a threshold:
# 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