File tree Expand file tree Collapse file tree 1 file changed +38
-0
lines changed
Term 1/1. Stock Prices/Quizes Expand file tree Collapse file tree 1 file changed +38
-0
lines changed Original file line number Diff line number Diff line change 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}\n p-value: {:.6f}" .format (t , p ))
35+
36+
37+ if __name__ == '__main__' :
38+ test_run ()
You can’t perform that action at this time.
0 commit comments