RSquared

Modified on 2008/05/03 10:00 by Administrator — Categorized as: Standard Indicators

Syntax

public RSquared(DataSeries source, int period, string description)
public static RSquared Series(DataSeries source, int period)
public static double Value(int bar, DataSeries source, int period)

Parameter Description

source The source DataSeries
period Indicator calculation period

Description

RSquared is the Correlation Coefficient squared from Linear Regression. It is used to determine how much of the price action over the specified period can be explained by the regression line, and how much should be attributes to random noise. RSquared ranges from 0 to 1.

RSquared is a statistical indicator. Other indicators in the same class are LinearReg, LinearRegSlope, StdError, and StdDev.

Interpretation


The following table show the RSquared values for a given number of periods for a statistically significant trend to be in place. A 95% confidence means that 95% of the prices can be explained by Linear Regression and 5% by unexplained random noise.

RSquared values for Number of periods 95% confidence
5 0.77
10 0.40
14 0.27
20 0.20
25 0.16
30 0.13
50 0.08
60 0.06
120 0.03

Calculation

RSquared is a rather complex statistical calculation. It uses the least square method to fit a trendline to the data by minimizing the distance between the price and the Linear Regression trendline and returns a percentage of price movement that is explained by the regression line.

Example

using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using WealthLab;
using WealthLab.Indicators;

namespace WealthLab.Strategies { public class MyStrategy : WealthScript { protected override void Execute() { // Plot RSquared in order to examine how prices react when they reach different levels. DataSeries r2 = RSquared.Series( Close, 30 ); ChartPane RSquaredPane = CreatePane( 35, true, true ); PlotSeries( RSquaredPane, r2, Color.Red, LineStyle.Solid, 1 ); PlotSeries( RSquaredPane, LinearRegSlope.Series( Close, 30 ), Color.Blue, LineStyle.Solid, 1 ); } } }