Correlate Asset Prices
The correlation indicator measures the statistical relationship between two asset price series, quantifying how closely they move together. It calculates a correlation coefficient that ranges from -1 (perfect negative correlation) to +1 (perfect positive correlation), with 0 indicating no correlation. This indicator uses configurable averaging and deviation models to adapt to different market conditions and trading styles.
Correlation analysis is fundamental to portfolio diversification, pairs trading, and risk management. By understanding how assets move relative to each other, traders can identify hedging opportunities, assess diversification effectiveness, and discover potential trading pairs. The indicator's flexibility in choosing different statistical models makes it valuable for various analytical approaches.
What It Measures
The correlation indicator measures the strength and direction of the linear relationship between two asset price series over a specified period. It combines a constant model (for calculating average returns) and a deviation model (for measuring dispersion) to compute the correlation coefficient, revealing whether assets tend to move together, opposite, or independently.
When to Use
- Portfolio Diversification: Identify assets with low or negative correlation to reduce portfolio risk
- Pairs Trading: Find highly correlated asset pairs for spread trading strategies
- Hedging Analysis: Evaluate potential hedging instruments by finding negatively correlated assets
- Risk Assessment: Monitor correlation changes that may affect portfolio risk profiles
- Market Regime Detection: Track correlations to identify shifts in market relationships
- Asset Rotation: Use correlation patterns to time sector or asset class rotation strategies
Period Selection Guidelines
The period parameter determines the lookback window for correlation calculation:
| Period Range | Characteristics | Use Case |
|---|---|---|
| 5-10 | High sensitivity, more noise | Short-term trading, rapid correlation shifts |
| 10-20 | Balanced responsiveness (default 20) | Swing trading, tactical positioning |
| 20-50 | Stable correlation trends | Position trading, portfolio rebalancing |
| 50-100 | Long-term relationship | Strategic allocation, risk management |
| 100-200+ | Major correlation regimes | Long-term investing, macro analysis |
Model Selection Guidelines
Constant Models (for calculating averages):
- SimpleMovingAverage: Standard equal-weighted average, most common choice
- ExponentialMovingAverage: Weights recent prices more heavily, responsive to changes
- SmoothedMovingAverage: Gradual smoothing, reduces noise
Deviation Models (for measuring dispersion):
- StandardDeviation: Traditional measure, assumes normal distribution
- MeanAbsoluteDeviation: Less sensitive to outliers than standard deviation
- MedianAbsoluteDeviation: Robust to extreme values
- ModeAbsoluteDeviation: Uses mode-based deviation, useful for multimodal distributions
- UlcerIndex: Emphasizes downside deviations
- LogStandardDeviation: Standard deviation of log returns, handles multiplicative processes
- LaplaceStdEquivalent: Laplace distribution equivalent, robust to outliers
- CauchyIQRScale: Based on Cauchy distribution IQR, handles heavy-tailed distributions
Interpretation
- Correlation > 0.7: Strong positive correlation - assets tend to move together
- Correlation 0.3 to 0.7: Moderate positive correlation - some relationship exists
- Correlation -0.3 to 0.3: Weak or no correlation - assets move independently
- Correlation -0.7 to -0.3: Moderate negative correlation - assets tend to move opposite
- Correlation < -0.7: Strong negative correlation - assets move in opposite directions
- Rising Correlation: Assets becoming more synchronized, potentially reducing diversification benefits
- Falling Correlation: Assets becoming more independent, potentially improving diversification
- Correlation Near 1.0: Perfect positive relationship - minimal diversification benefit
- Correlation Near -1.0: Perfect negative relationship - ideal for hedging
- Shifting Correlations: May signal changing market conditions or regime shifts
Default Usage
use rust_ti::correlation_indicators::bulk::correlate_asset_prices;
use rust_ti::{ConstantModelType, DeviationModel};
pub fn main() {
// fetch the data in your preferred way
// let prices_asset_a = vec![...]; // price data for first asset
// let prices_asset_b = vec![...]; // price data for second asset
let period = 20;
let constant_model = ConstantModelType::SimpleMovingAverage;
let deviation_model = DeviationModel::StandardDeviation;
let correlation = correlate_asset_prices(
&prices_asset_a,
&prices_asset_b,
constant_model,
deviation_model,
period
);
println!("Correlation: {:?}", correlation);
}
import pytechnicalindicators as pti
# Correlate two asset price series
period = 20
constant_model = "SimpleMovingAverage"
deviation_model = "StandardDeviation"
correlation = pti.correlation_indicators.bulk.correlate_asset_prices(
prices_asset_a,
prices_asset_b,
constant_model,
deviation_model,
period
)
print("Correlation:", correlation)
import init, {
correlation_bulk_correlateAssetPrices,
ConstantModelType,
DeviationModel
} from 'https://cdn.jsdelivr.net/npm/ti-engine@latest/dist/web/ti_engine.js';
await init();
// fetch the data in your preferred way
// const pricesAssetA = [...]; // price data for first asset
// const pricesAssetB = [...]; // price data for second asset
const period = 20;
const constantModel = ConstantModelType.SimpleMovingAverage;
const deviationModel = DeviationModel.StandardDeviation;
const correlation = correlation_bulk_correlateAssetPrices(
pricesAssetA,
pricesAssetB,
constantModel,
deviationModel,
period
);
console.log("Correlation:", correlation);
Interactive Chart
Use the interactive playground below to explore how different parameters affect the indicator's behavior.