10.12.2019 Views

Python for Finance

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Time-Series Analysis

The output for those five values, including the number of observations, is given here:

This result is very close to the result in the paper titled Study of Fat Tail Risk by

Cook Pine Capital (2008). Using the same argument, we conclude that the SP500

daily returns are skewed to the left, that is, a negative skewness, and have fat tails

(kurtosis is 20.81 instead of zero).

T-test and F-test

In finance, a T-test could be viewed as one of the most widely used statistical

hypothesis tests in which the test statistic follows a student's t distribution if the null

hypothesis is supported. We know that the mean for a standard normal distribution

is zero. In the following program, we generate 1,000 random numbers from a

standard normal distribution. Then, we conduct two tests: test whether the mean is

0.5, and test whether the mean is zero:

>>>from scipy import stats

>>>import numpy as np

>>>np.random.seed(1235)

>>>x = stats.norm.rvs(size=10000)

>>>print("T-value P-value (two-tail)")

>>>print(stats.ttest_1samp(x,0.5))

>>>print(stats.ttest_1samp(x,0))

T-value P-value (two-tail)

Ttest_1sampResult(statistic=-49.763471231428966, pvalue=0.0)

Ttest_1sampResult(statistic=-0.26310321925083019,

pvalue=0.79247644375164861)

For the first test, in which we test whether the time-series has a mean of 0.5, we reject

the null hypothesis since the T-value is 49.76 and the P-value is 0. For the second test,

we accept the null hypothesis since the T-value is close to -0.26 and the P-value is

0.79. In the following program, we test whether the mean of the daily returns from

IBM in 2013 is zero:

from scipy import stats

import scipy as sp

from matplotlib.finance import quotes_historical_yahoo_ochl as getData

[ 262 ]

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!