1
1
import numpy as np
2
2
3
- def StationaryBootstrap (data : np .ndarray , m , sampleLength )-> np .ndarray :
3
+ def StationaryBootstrap (data : np .ndarray , m : float , sampleLength : int )-> np .ndarray :
4
4
"""
5
5
Returns a bootstraped sample of the time-series "data" of length "sampleLength.
6
6
The algorithm used is stationary bootstrap from 1994 Politis & Romano.
@@ -37,12 +37,12 @@ def StationaryBootstrap(data: np.ndarray, m, sampleLength)-> np.ndarray:
37
37
Association, 89:428, 1303-1313, DOI: 10.1080/01621459.1994.10476870
38
38
39
39
Implemented by Gregor Fabjan from Qnity Consultants on 12/11/2021.
40
+
40
41
"""
41
-
42
42
accept = 1 / m
43
43
lenData = data .shape [0 ]
44
44
45
- sampleIndex = np .random .randint (0 ,high = lenData ,size = 1 );
45
+ sampleIndex = np .random .randint (0 ,high = lenData ,size = 1 )
46
46
sample = np .zeros ((sampleLength ,1 ))
47
47
for iSample in range (sampleLength ):
48
48
if np .random .uniform (0 ,1 ,1 )>= accept :
@@ -53,4 +53,4 @@ def StationaryBootstrap(data: np.ndarray, m, sampleLength)-> np.ndarray:
53
53
sampleIndex = np .random .randint (0 ,high = lenData ,size = 1 )
54
54
55
55
sample [iSample ,0 ] = data [sampleIndex ]
56
- return sample
56
+ return sample
0 commit comments