Skip to content

TA-Lib's STDDEV returning population and not sample. #69

@WitchGod

Description

@WitchGod

Code first:

import pandas as pd
import talib as ta
import numpy as np

df = pd.DataFrame(np.random.randn(11), columns=['Values'])
df["pandas-std"] = pd.rolling_std(df["Values"], window=10)
df["talib-std"] = ta.STDDEV(df["Values"].values, timeperiod=10)

print df

Above gives:

      Values  pandas-std  talib-std
0   0.684808         NaN        NaN
1   0.613100         NaN        NaN
2  -0.016941         NaN        NaN
3  -0.519221         NaN        NaN
4   2.147814         NaN        NaN
5  -0.393357         NaN        NaN
6   0.123275         NaN        NaN
7   0.707619         NaN        NaN
8   2.157508         NaN        NaN
9  -0.138655    0.954126   0.905163
10 -0.028071    0.968347   0.918655

Using independent calculations, I come to the conclusion that TA-Lib calculates standard deviation based on population (divided by n) rather than by sample (divided by n-1).

Can an option be possibly added to STDDEV such that it's possible to switch between sample and population computations? The former is what's needed for calculating historical volatility.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions