Skip to content

Commit 86de0f6

Browse files
authored
Create statistical_returns.py
1 parent b529fe6 commit 86de0f6

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import pandas as pd
2+
import numpy as np
3+
import scipy.stats as stats
4+
5+
def analyze_returns(net_returns):
6+
"""
7+
Perform a t-test, with the null hypothesis being that the mean return is zero.
8+
9+
Parameters
10+
----------
11+
net_returns : Pandas Series
12+
A Pandas Series for each date
13+
14+
Returns
15+
-------
16+
t_value
17+
t-statistic from t-test
18+
p_value
19+
Corresponding p-value
20+
"""
21+
# TODO: Perform one-tailed t-test on net_returns
22+
# Hint: You can use stats.ttest_1samp() to perform the test.
23+
# However, this performs a two-tailed t-test.
24+
# You'll need to divde the p-value by 2 to get the results of a one-tailed p-value.
25+
null_hypothesis = 0.0
26+
t_value, p_value = stats.ttest_1samp(net_returns, null_hypothesis)
27+
28+
return t_value, p_value/2
29+
30+
def test_run(filename='net_returns.csv'):
31+
"""Test run analyze_returns() with net strategy returns from a file."""
32+
net_returns = pd.Series.from_csv(filename, header=0)
33+
t, p = analyze_returns(net_returns)
34+
print("t-statistic: {:.3f}\np-value: {:.6f}".format(t, p))
35+
36+
37+
if __name__ == '__main__':
38+
test_run()

0 commit comments

Comments
 (0)