EVaR Indicator and Position SizingThe Problem: 
Financial markets consistently show "fat-tailed" distributions where extreme events occur with  higher frequency than predicted by normal distributions (Gaussian or even log-normal). These fat tails manifest in sudden price crashes, volatility spikes, and black swan events that traditional risk measures like volatility can underestimate. Standard deviation and conventional VaR calculations assume normally distributed returns, leaving traders vulnerable to severe drawdowns during market stress.
Cryptocurrencies and volatile instruments display particularly pronounced fat-tailed behavior, with extreme moves occurring 5-10 times more frequently than normal distribution models would predict. This reality demands a more sophisticated approach to risk measurement and position sizing.
 The Solution: Entropic Value at Risk (EVAR) 
EVaR addresses these limitations by incorporating principles from statistical mechanics and information theory through Tsallis entropy. This advanced approach captures the non-linear dependencies and power-law distributions characteristic of real financial markets.
Entropy is more adaptive than standard deviations and volatility measures. 
I was inspired to create this indicator after reading the paper " The End of Mean-Variance? Tsallis Entropy Revolutionises Portfolio Optimisation in Cryptocurrencies " by by Sana Gaied Chortane  and Kamel Naoui.
 Key advantages of EVAR over traditional risk measures: 
 
 Superior tail risk capture: More accurately quantifies the probability of extreme market moves
 Adaptability to market regimes: Self-calibrates to changing volatility environments
 Non-parametric flexibility: Makes less assumptions about the underlying return distribution
 Forward-looking risk assessment: Better anticipates potential market changes (just look at the charts :)
 
 Mathematically, EVAR is defined as: 
 EVAR_α(X) = inf_{z>0} {z * log(1/α * M_X(1/z))} 
Where the moment-generating function is calculated using q-exponentials rather than conventional exponentials, allowing precise modeling of fat-tailed behavior.
 Technical Implementation 
This indicator implements EVAR through a q-exponential approach from Tsallis statistics:
 
 Returns Calculation: Price returns are calculated over the lookback period
 Moment Generating Function: Approximated using q-exponentials to account for fat tails
 EVAR Computation: Derived from the MGF and confidence parameter
 Normalization: Scaled to   for intuitive visualization
 Position Sizing: Inversely modulated based on normalized EVAR
 
The q-parameter controls tail sensitivity—higher values (1.5-2.0) increase the weighting of extreme events in the calculation, making the model more conservative during potentially turbulent conditions.
 Indicator Components 
1. EVAR Risk Visualization
 
 Dynamic EVAR Plot: Color-coded from red to green normalized risk measurement (0-1)
 Risk Thresholds: Reference lines at 0.3, 0.5, and 0.7 delineating risk zones
 
2. Position Sizing Matrix
 
 Risk Assessment: Current risk level and raw EVAR value
 Position Recommendations: Percentage allocation, dollar value, and quantity
 Stop Parameters: Mathematically derived stop price with percentage distance
 Drawdown Projection: Maximum theoretical loss if stop is triggered
 
 Interpretation and Application 
The normalized EVAR reading provides a probabilistic risk assessment:
 
 < 0.3: Low risk environment with minimal tail concerns
 0.3-0.5: Moderate risk with standard tail behavior
 0.5-0.7: Elevated risk with increased probability of significant moves
 > 0.7: High risk environment with substantial tail risk present
 
Position sizing is automatically calculated using an inverse relationship to EVAR, contracting during high-risk periods and expanding during low-risk conditions. This is a counter-cyclical approach that ensures consistent risk exposure across varying market regimes, especially when the market is hyped or overheated. 
 Parameter Optimization 
For optimal risk assessment across market conditions:
 
 Lookback Period: Determines the historical window for risk calculation
 Q Parameter: Controls tail sensitivity (higher values increase conservatism)
 Confidence Level: Sets the statistical threshold for risk assessment
 
For cryptocurrencies and highly volatile instruments, a q-parameter between 1.5-2.0 typically provides the most accurate risk assessment because it helps capturing the fat-tailed behavior characteristic of these markets. You can also increase the q-parameter for more conservative approaches. 
 Practical Applications 
 
 Adaptive Risk Management: Quantify and respond to changing tail risk conditions
 Volatility-Normalized Positioning: Maintain consistent exposure across market regimes
 Black Swan Detection: Early identification of potential extreme market conditions
 Portfolio Construction: Apply consistent risk-based sizing across diverse instruments
 
This indicator is my own approach to entropy-based risk measures as an alterative to volatility and standard deviations and it helps with fat-tailed markets.
Enjoy!
Tsallis
Tsallis Entropy Market RiskTsallis Entropy Market Risk Indicator 
 What Is It? 
The Tsallis Entropy Market Risk Indicator is a market analysis tool that measures the degree of randomness or disorder in price movements. Unlike traditional technical indicators that focus on price patterns or momentum, this indicator takes a statistical physics approach to market analysis.
 Scientific Foundation 
The indicator is based on Tsallis entropy, a generalization of traditional Shannon entropy developed by physicist Constantino Tsallis. The Tsallis entropy is particularly effective at analyzing complex systems with long-range correlations and memory effects—precisely the characteristics found in crypto and stock markets. 
The indicator also borrows from Log-Periodic Power Law (LPPL).
 Core Concepts 
 1. Entropy Deficit 
The primary measurement is the "entropy deficit," which represents how far the market is from a state of maximum randomness:
 
 Low Entropy Deficit (0-0.3): The market exhibits random, uncorrelated price movements typical of efficient markets
 Medium Entropy Deficit (0.3-0.5): Some patterns emerging, moderate deviation from randomness
 High Entropy Deficit (0.5-0.7): Strong correlation patterns, potentially indicating herding behavior
 Extreme Entropy Deficit (0.7-1.0): Highly ordered price movements, often seen before significant market events
 
 2. Multi-Scale Analysis 
The indicator calculates entropy across different timeframes:
 
 Short-term Entropy (blue line): Captures recent market behavior (20-day window)
 Long-term Entropy (green line): Captures structural market behavior (120-day window)
 Main Entropy (purple line): Primary measurement (60-day window)
 
 3. Scale Ratio 
This measures the relationship between long-term and short-term entropy. A healthy market typically has a scale ratio above 0.85. When this ratio drops below 0.85, it suggests abnormal relationships between timeframes that often precede market dislocations.
 How It Works  
 
 Data Collection: The indicator samples price returns over specific lookback periods
 Probability Distribution Estimation: It creates a histogram of these returns to estimate their probability distribution
 Entropy Calculation: Using the Tsallis q-parameter (typically 1.5), it calculates how far this distribution is from maximum entropy
 Normalization: Results are normalized against theoretical maximum entropy to create the entropy deficit measure
 Risk Assessment: Multiple factors are combined to generate a composite risk score and classification
 
 Market Interpretation 
 
 Low Risk Environments (Risk Score < 25) 
 Market is functioning efficiently with reasonable randomness
 Price discovery is likely effective
 Normal trading and investment approaches appropriate
 Medium Risk Environments (Risk Score 25-50) 
 Increasing correlation in price movements
 Beginning of trend formation or momentum
 Time to monitor positions more closely
 High Risk Environments (Risk Score 50-75) 
 Strong herding behavior present
 Market potentially becoming one-sided
 Consider reducing position sizes or implementing hedges
 Extreme Risk Environments (Risk Score > 75) 
 Highly ordered market behavior
 Significant imbalance between buyers and sellers
 Heightened probability of sharp reversals or corrections
 
 Practical Application Examples 
 
 Market Tops: Often characterized by gradually increasing entropy deficit as momentum builds, followed by extreme readings near the actual top
 Market Bottoms: Can show high entropy deficit during capitulation, followed by normalization
 Range-Bound Markets: Typically display low and stable entropy deficit measurements
 Trending Markets: Often show moderate entropy deficit that remains relatively consistent
 
 Advantages Over Traditional Indicators 
 
 Forward-Looking: Identifies changing market structure before price action confirms it
 Statistical Foundation: Based on robust mathematical principles rather than empirical patterns
 Adaptability: Functions across different market regimes and asset classes
 Noise Filtering: Focuses on meaningful structural changes rather than price fluctuations
 Limitations
 Not a Timing Tool: Signals market risk conditions, not precise entry/exit points
 Parameter Sensitivity: Results can vary based on the chosen parameters
 Historical Context: Requires some historical perspective to interpret effectively
 Complementary Tool: Works best alongside other analysis methods
 
Enjoy :)

