1

I noticed that the skewness returned from scipy stats is not correct. Pandas.skew() actually provide better results. I am recently trying to duplicate a classic paper, Expected Stock Returns and Volatility by French&Schwert. I use S&P500 data from 1928 to 1984. I follow the formula in the paper for standard deviation of the return and I am able to get the same result for mean, std dev of std dev. However, when I use scipy.stats.skew function, I can't not get any number of the std dev of the sp return. The function return "nan", where clearly it should return a value. I switch to Pandas.skew(). it returned me the correct value as in the paper.

Clearly, something is wrong with the scipy.stats.skew() function.

scipy.stats.skew() pandas.skew()

  1. Results by Scipy.stats.skew() ['Adj Close_gspc', 'Adj Close_gspc_lag', 'SP_Return', 'SP_Return_square', 'SP_Return_lag', 'SP_varianceMon', 'SP_varianceMon_sqrRoot']

array([ 0.6922229 , 0.69186265, -0.11292165, 4.23571807, -1.9556035 , 5.39873607, nan])

  1. results by pandas:

Adj Close_gspc 0.693745 Adj Close_gspc_lag 0.693384 SP_Return -0.113170 SP_Return_square 4.245033 SP_Return_lag -1.959904 SP_varianceMon 5.410609 SP_varianceMon_sqrRoot 2.800919 dtype: float64

1

1 Answer 1

1

You haven't provided enough information or sample code to reproduce the nan that you get.

To make scipy.stats.skew compute the same value as the skew() method in Pandas, add the argument bias=False.

Here's an example.

First, the imports:

In [21]: import numpy as np                                                                      

In [22]: import pandas as pd                                                                     

In [23]: from scipy.stats import skew                                                            

Generate some data:

In [24]: np.random.seed(8675309)                                                                 

In [25]: x = np.random.weibull(0.2, size=15)                                                     

Compute the skew with scipy and with Pandas:

In [26]: skew(x, bias=False)                                                                     
Out[26]: 3.7582525674514544

In [27]: pd.Series(x).skew()                                                                     
Out[27]: 3.7582525674514544

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.