Rolling Skewness (SKEW)
Summary
An estimate, from the trailing window, of the skewness of the distribution its values come from: the third standardised moment. An asymmetry measure: above 0 the distribution has a longer tail above its mean, below 0 a longer tail below it, and a symmetric window reads 0. The companion to KURTOSIS, VAR and STDDEV in the same group.
Chart
Chart metadata i
Outputs
outReal:line·zero·positive·negative
Formula
Adjusted Fisher-Pearson coefficient of skewness, the estimator usually written G1. With window size n, window mean x̄ and population moments mₖ = Σ(x−x̄)ᵏ / n:
g1 = m₃ / m₂^(3/2)
G1 = g1 · √(n(n−1)) / (n−2)
The result is 0 when m₂ = 0, that is when every value in the window is equal: a point mass is symmetric.
optInTimePeriod must be at least 3: the n−2 denominator is undefined below it. The bound is enforced by the parameter range, so a shorter period is refused rather than silently degraded.
Notes
- This is
G1, the form ExcelSKEW,scipy.stats.skew(bias=False)and Re1071::skewness(type = 2)compute. Two other estimators are in circulation, each a constant multiple ofg1rather than a rounding convention:g1itself (scipy.stats.skew(bias=True)) andb1 = g1 · ((n−1)/n)^(3/2)(type = 3). - One reading apart from
n−1equal ones gives exactly√n, above the rest when the odd one is above and−√nwhen it is below. That is the largest magnitude a window can reach, so a window dominated by one outlier is legitimately far from 0.
Inputs
inReal— The series to measure
Outputs
outReal— Skewness of the trailing window, or 0 where the window has no spread
Parameters
| Parameter | Type | Default | Accepted values | Description |
|---|---|---|---|---|
optInTimePeriod | integer | 30 | 3–100000 | Number of trailing values in the window |
Properties
Numerical Stability: Start-Independent
| ☐ Overlap Input |
| ✅ Independent Y-Axis i |
| ☐ Candlestick |
| ☐ Display Shift |
| ☐ Can Output NaN or ±Inf |
| ☐ Identity at Period 1 |
| ☐ Uses Transcendental |
| ☐ Input Must Be Positive |
Example
#include <stdio.h>
#include <ta_libc.h>
int n = 252;
double series[252]; /* your data, oldest first */
double out[252];
int outBegIdx, outNBElement;
TA_Initialize();
TA_SKEW( 0, n - 1, series, 30, &outBegIdx, &outNBElement, out );
printf( "%d values from bar %d: [%.4f, ..., %.4f]\n", outNBElement, outBegIdx, out[0], out[outNBElement - 1] );use ta_lib::Core;
let series = vec![0.0; 252]; // your data, oldest first
let mut out = vec![0.0; 252];
let core = Core::new();
let range = core.skew(0, series.len() - 1, &series, 30, &mut out)?;
println!("{} values from bar {}: [{:.4}, ..., {:.4}]", range.count, range.beg_idx, out[0], out[range.count - 1]);import io.github.talib.Core;
import io.github.talib.OutRange;
import java.util.Locale;
double[] series = new double[252]; // your data, oldest first
double[] out = new double[252];
Core core = Core.DEFAULT;
OutRange r = core.skew(0, series.length - 1, series, 30, out);
System.out.printf(Locale.ROOT, "%d values from bar %d: [%.4f, ..., %.4f]%n", r.count(), r.begIdx(), out[0], out[r.count() - 1]);using System;
using TALib;
var series = new double[252]; // your data, oldest first
var outReal = new double[252];
var core = Core.Default;
OutRange r = core.Skew(0, series.Length - 1, series, 30, outReal);
Console.WriteLine(FormattableString.Invariant($"{r.Count} values from bar {r.BegIdx}: [{outReal[0]:F4}, ..., {outReal[r.Count - 1]:F4}]"));import { skew } from 'ta-lib';
const series = new Float64Array(252); // your data, oldest first
const { begIdx, values } = skew(series, { timePeriod: 30 });
console.log(values.length + ' values from bar ' + begIdx + ': [' + values[0].toFixed(4) + ', ..., ' + values[values.length - 1].toFixed(4) + ']');import (
"fmt"
"log"
talib "ta-lib.github.io/go"
)
series := make([]float64, 252) // your data, oldest first
out := make([]float64, 252)
core := talib.NewCore()
r, err := core.SKEW(0, len(series)-1, series, 30, out)
if err != nil {
log.Fatal(err)
}
fmt.Printf("%d values from bar %d: [%.4f, ..., %.4f]\n", r.NBElement, r.BegIdx, out[0], out[r.NBElement-1])Implementation
Added in 0.8.4.
TA-Lib Definition: skew.c · skew.yaml
| Native | File |
|---|---|
| C | ta_SKEW.c |
| Rust | skew.rs |
| Java | Core_SKEW.java |
| C# | Core_SKEW.cs |
| TypeScript | skew.ts |
| Go | skew.go |
Python: talib.SKEW, see ta-lib-python.
TA-Lib is also available for R and more using a wrapper.
Aliases
Skewness, Sample Skewness, Fisher-Pearson Skewness
See Also
References
- Joanes, D. N. and Gill, C. A. "Comparing measures of sample skewness and kurtosis." Journal of the Royal Statistical Society: Series D, 47(1), 1998, 183-189 — the
g1,G1,b1family and which is unbiased under which assumption. - NIST/SEMATECH e-Handbook of Statistical Methods, §1.3.5.11 — the Fisher-Pearson coefficient and its adjusted form.
- Microsoft, SKEW function — the
G1form.