def test_MBM_mgn(n_good, hurst_func_good, length_good, mbm_method_good): m = MBM(n_good, hurst_func_good, length_good, mbm_method_good) mgn_sample = m.mgn() assert isinstance(mgn_sample, np.ndarray) assert len(mgn_sample) == n_good
def test_MBM_times(n_good, hurst_func_good, length_good, mbm_method_good): m = MBM(n_good, hurst_func_good, length_good, mbm_method_good) ts = m.times() assert isinstance(ts, np.ndarray) assert len(ts) == n_good + 1
def test_MBM_init_method_bad(n_good, hurst_func_good, length_good, method_bad): with pytest.raises((TypeError, ValueError)): m = MBM(n_good, hurst_func_good, length_good, method_bad)
def test_MBM_change(n_good, hurst_func_good, length_good, mbm_method_good): m = MBM(n_good, hurst_func_good, length_good, mbm_method_good) m.n = 42 assert m._changed == True sample = m.mbm() assert m._changed == False
def test_MBM_init(n_good, hurst_func_good, length_good, mbm_method_good): m = MBM(n_good, hurst_func_good, length_good, mbm_method_good) print(str(m)) print(repr(m))
# flake8: noqa from fbm import MBM import matplotlib.pyplot as plt import time import math def h(t): # return 0.499*math.sin(t) + 0.5 # return 0.6 * t + 0.3 return 0.5 * math.exp(-8 * t**2) + 0.35 m = MBM(2**8, h, 1) t = m.times() mbm = m.mbm() plt.plot(t, mbm) plt.plot(t, [h(tt) for tt in t]) plt.show()
hurst = np.array(data.Hurst1[::-1]) def H(t): t = t * (data.shape[0] - 1) t = int(t) return hurst[t] def Hplot(t): t = t * (data.shape[0] - 1) t = t.astype(int) return hurst[t] m = MBM(n=size, hurst=H, length=1) #m0 = MBM(1024, h0) #m1 = MBM(1024, h1) #m2 = MBM(1024, h2) fig = plt.figure() ax1 = fig.add_subplot(2, 1, 1) ax2 = fig.add_subplot(2, 1, 2) ax1.set_title(r'MBM simulation for BTC prices', ) ax1.plot(m.times(), m.mbm(), 'r') ax2.set_title(r'Hurst function') ax2.plot(m.times(), Hplot(m.times()), 'r') ax2.set_yticks(np.arange(0.35, 0.6, 0.05))