-
-
Notifications
You must be signed in to change notification settings - Fork 410
Expand file tree
/
Copy pathtest_FinStatistics.py
More file actions
45 lines (26 loc) · 1.04 KB
/
Copy pathtest_FinStatistics.py
File metadata and controls
45 lines (26 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# Copyright (C) 2018, 2019, 2020 Dominic O'Kane
import numpy as np
from financepy.utils.stats import mean, stdev, correlation
seed = 1972
np.random.seed(seed)
num_trials = 1000000
x = np.random.normal(0.0, 1.0, size=num_trials)
y = np.random.normal(0.0, 1.0, size=num_trials)
########################################################################################
def test_mean():
np_result = x.mean()
fp_result = mean(x)
assert round(fp_result, 10) == round(np_result, 10)
########################################################################################
def test_stdev():
np_result = x.std()
fp_result = stdev(x)
assert round(fp_result, 10) == round(np_result, 10)
# TODO: tests for stderr, var, moment
########################################################################################
def test_correlation():
beta = 0.4
z = x * beta + y * np.sqrt(1.0 - beta * beta)
np_result = np.corrcoef(x, z)[0, 1]
fp_result = correlation(x, z)
assert round(fp_result, 10) == round(np_result, 10)