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

Period Selection Guidelines

The period parameter determines the lookback window for correlation calculation:

Period RangeCharacteristicsUse Case
5-10High sensitivity, more noiseShort-term trading, rapid correlation shifts
10-20Balanced responsiveness (default 20)Swing trading, tactical positioning
20-50Stable correlation trendsPosition trading, portfolio rebalancing
50-100Long-term relationshipStrategic allocation, risk management
100-200+Major correlation regimesLong-term investing, macro analysis

Model Selection Guidelines

Constant Models (for calculating averages):

Deviation Models (for measuring dispersion):

Interpretation

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.