Statistical Arbitrage Pairs Trading - Long-Side OnlyThis strategy implements a simplified statistical arbitrage (" stat arb ") approach focused on mean reversion between two correlated instruments. It identifies opportunities where the spread between their normalized price series (Z-scores) deviates significantly from historical norms, then executes long-only trades anticipating reversion to the mean.
Key Mechanics:
1. Spread Calculation: The strategy computes Z-scores for both instruments to normalize price movements, then tracks the spread between these Z-scores.
2. Modified Z-Score: Uses a robust measure combining the median and Median Absolute Deviation (MAD) to reduce outlier sensitivity.
3. Entry Signal: A long position is triggered when the spread’s modified Z-score falls below a user-defined threshold (e.g., -1.0), indicating extreme undervaluation of the main instrument relative to its pair.
4. Exit Signal: The position closes automatically when the spread reverts to its historical mean (Z-score ≥ 0).
Risk management:
Trades are sized as a percentage of equity (default: 10%).
Includes commissions and slippage for realistic backtesting.
Statisticalarbritrage
Autocorrelation Price Forecasting [ScrimpleAI]Discover how to predict future price movements using autocorrelation and linear regression models to identify potential trading opportunities.
An advanced model to predict future price movements using autocorrelation and linear regression. This script helps identify recurring market cycles and calculates potential gains, with clear visual signals for quick and informed decisions.
Main Function
This script leverages an autocorrelation model to estimate the future price of an asset based on historical price relationships. It also integrates linear regression on percentage returns to provide more accurate predictions of price movements.
Key Features
1. Customizable Inputs:
- Analysis Length: number of historical bars used for autocorrelation calculation. Adjustable between 1 and 200.
- Forecast Colors: customize colors for bullish and bearish signals.
2. Price Autocorrelation: uses the ta.correlation function to measure price autocorrelation, detecting significant cycles when the value exceeds a defined threshold ( signal_threshold = 0.50 ).
3. Linear Regression on Returns: calculates percentage returns and applies linear regression to identify the future projected price value.
4. Hypothetical Gain Assessment: evaluates potential profit by comparing the estimated future price with the current price.
5. Visual Alerts:
- Labels: hypothetical gains or losses are displayed as labels above or below the bars.
- Dynamic Coloring: bullish (green) and bearish (red) signals are highlighted directly on the chart.
- Forecast Line: A continuous line is plotted to represent the estimated future price values.
Practical Applications
Short-term Trading : identify repetitive market cycles to anticipate future movements.
Visual Decision-making : colored signals and labels make it easier to visualize potential profit or loss for each trade.
Advanced Customization : adjust the data length and colors to tailor the indicator to your strategies.
💡 What do you think about this model?
If you already use autocorrelation-based analysis or want to try predictive strategies, leave a comment with your feedback!
[ AlgoChart ] - Pearson Index CorrelationCorrelation Indicator (Pearson Index)
The correlation indicator measures the strength and direction of the relationship between two financial assets using the Pearson Index.
Correlation values range from +100 to -100, where:
+100 indicates perfect positive correlation, meaning the two assets tend to move in the same direction.
-100 indicates perfect negative correlation, where the two assets move in opposite directions.
The neutral zone ranges from +25% to -25%, suggesting that the asset movements are independent, with no clear correlation between them.
Interpreting Correlation Levels:
Correlation above +75%: The two assets tend to move similarly and in the same direction. This may indicate a risk of overexposure if both assets are traded in the same direction, as their movements will be very similar, increasing the likelihood of double losses or gains.
Correlation below -75%: The two assets tend to move similarly but in opposite directions. This correlation level can be useful for strategies that benefit from opposing movements between assets, such as trading pairs with inverse dynamics.
Practical Use of the Indicator:
Risk management: Use the indicator to monitor asset correlations before opening positions. High correlation may indicate you are duplicating exposure, as two highly correlated assets tend to move similarly. This helps avoid excessive risk and improves portfolio diversification.
Statistical Arbitrage: During moments of temporary decorrelation between two assets, the indicator can be used for statistical arbitrage strategies. In such cases, you can take advantage of the divergence by opening positions and closing them when the correlation returns to higher or positive levels, thus potentially profiting from the reconvergence of movements.
While the correlation indicator provides valuable insights into asset relationships, it is most effective when used in conjunction with other concepts and tools. On its own, it may offer limited relevance in trading decisions.