コード例 #1
0
def test_mfdfa_save_load():
    mfdfa = fathon.MFDFA(fu.toAggregated(ts))
    # save and load with empty results
    mfdfa.saveObject(get_object_path('mfdfa_obj'))
    n_load = fu.getObjectMember(get_object_path('mfdfa_obj', ext=True), 'n')
    F_load = fu.getObjectMember(get_object_path('mfdfa_obj', ext=True), 'F')
    q_list_load = fu.getObjectMember(get_object_path('mfdfa_obj', ext=True),
                                     'qList')
    list_h_load = fu.getObjectMember(get_object_path('mfdfa_obj', ext=True),
                                     'listH')
    assert np.array_equal(n_load, [])
    assert np.array_equal(F_load, [])
    assert np.array_equal(q_list_load, [])
    assert np.array_equal(list_h_load, [])
    #save and load with results
    n, F = mfdfa.computeFlucVec(fu.linRangeByStep(10, 500),
                                fu.linRangeByStep(-1, 1))
    H, I = mfdfa.fitFlucVec(100, 300)
    mfdfa.saveObject(get_object_path('mfdfa_obj'))
    n_load = fu.getObjectMember(get_object_path('mfdfa_obj', ext=True), 'n')
    F_load = fu.getObjectMember(get_object_path('mfdfa_obj', ext=True), 'F')
    q_list_load = fu.getObjectMember(get_object_path('mfdfa_obj', ext=True),
                                     'qList')
    list_h_load = fu.getObjectMember(get_object_path('mfdfa_obj', ext=True),
                                     'listH')
    assert np.array_equal(n_load, n)
    assert np.array_equal(F_load, F)
    assert np.array_equal(q_list_load, fu.linRangeByStep(-1, 1))
    assert np.array_equal(list_h_load, H)
    # MFDFA from file
    mfdfa_2 = fathon.MFDFA(get_object_path('mfdfa_obj', ext=True))
    H_2, I_2 = mfdfa_2.fitFlucVec(100, 300)
    assert np.array_equal(H_2, H)
    assert np.array_equal(I_2, I)
コード例 #2
0
def test_mfdfa():
    pymfdfa = fathon.MFDFA(ts3)
    qs = np.arange(-3, 3, 1)
    winSizes = fu.linRangeByStep(10, 200)
    n2, F2 = pymfdfa.computeFlucVec(winSizes, qs, revSeg=True)
    H2, H_int2 = pymfdfa.fitFlucVec()

    assert math.isclose(H2[2], 1.1956312585360254)
コード例 #3
0
def test_multifractal_spectrum():
    pymfdfa = fathon.MFDFA(ts3)
    qs = np.arange(-3, 3, 1)
    winSizes = fu.linRangeByStep(10, 200)
    n2, F2 = pymfdfa.computeFlucVec(winSizes, qs, revSeg=True)
    H2, H_int2 = pymfdfa.fitFlucVec()
    a2, m2 = pymfdfa.computeMultifractalSpectrum()

    assert math.isclose(m2[4], 0.8445200259231695)
コード例 #4
0
def test_mat_mfdfa_wn():
    w_mfdfa = fathon.MFDFA(fu.toAggregated(wn))
    n_w, F_w = w_mfdfa.computeFlucVec(scales,
                                      qList=q_list,
                                      revSeg=False,
                                      polOrd=1)
    idxs = get_idxs(n_w, scales)
    n_w = n_w[idxs]
    F_w_vec = np.zeros((len(q_list), len(idxs)))
    for i in range(len(q_list)):
        F_w_vec[i] = F_w[i, idxs]
    Hq = []
    for i in range(len(q_list)):
        Hq.append(np.polyfit(np.log2(n_w), np.log2(F_w_vec[i]), 1)[0])
    np.testing.assert_allclose(
        Hq, [0.4583, 0.4555, 0.4546, 0.4515, 0.4445, 0.4340],
        rtol=1e-4,
        atol=0)
コード例 #5
0
def test_mat_mfdfa_mf():
    mf_mfdfa = fathon.MFDFA(fu.toAggregated(mf))
    n_mf, F_mf = mf_mfdfa.computeFlucVec(scales,
                                         qList=q_list,
                                         revSeg=False,
                                         polOrd=1)
    idxs = get_idxs(n_mf, scales)
    n_mf = n_mf[idxs]
    F_mf_vec = np.zeros((len(q_list), len(idxs)))
    for i in range(len(q_list)):
        F_mf_vec[i] = F_mf[i, idxs]
    Hq = []
    for i in range(len(q_list)):
        Hq.append(np.polyfit(np.log2(n_mf), np.log2(F_mf_vec[i]), 1)[0])
    np.testing.assert_allclose(
        Hq, [1.4477, 1.3064, 1.0823, 0.8846, 0.6606, 0.5174],
        rtol=1e-4,
        atol=0)
コード例 #6
0
def test_mat_mfdfa_mn():
    mn_mfdfa = fathon.MFDFA(fu.toAggregated(mn))
    n_mn, F_mn = mn_mfdfa.computeFlucVec(scales,
                                         qList=q_list,
                                         revSeg=False,
                                         polOrd=1)
    idxs = get_idxs(n_mn, scales)
    n_mn = n_mn[idxs]
    F_mn_vec = np.zeros((len(q_list), len(idxs)))
    for i in range(len(q_list)):
        F_mn_vec[i] = F_mn[i, idxs]
    Hq = []
    for i in range(len(q_list)):
        Hq.append(np.polyfit(np.log2(n_mn), np.log2(F_mn_vec[i]), 1)[0])
    np.testing.assert_allclose(
        Hq, [0.7542, 0.7392, 0.7301, 0.7240, 0.7149, 0.7023],
        rtol=1e-4,
        atol=0)
        usd_volume_bar_df = testClass.get_concat_data(testClass._bars_dict)['usd_volume_bars']
        calendar_bar_df = testClass.get_concat_data(testClass._bars_dict)['calendar_bars']
        vr = returns(volume_bar_df.micro_price_close).replace([np.inf, -np.inf], 0)  # volume
        tr = returns(tick_bar_df.micro_price_close).replace([np.inf, -np.inf], 0)  # tick
        dr = returns(usd_volume_bar_df.micro_price_close).dropna().replace([np.inf, -np.inf], 0)  # usd volume
        df_ret = returns(calendar_bar_df.micro_price_close).dropna().replace([np.inf, -np.inf], 0)  # calendar
        bar_returns[date] = {'tick': tr,
                             'volume': vr,
                             'dollar': dr,
                             'calendar': df_ret}

    for j, i in itertools.product(['tick', 'volume', 'dollar', 'calendar'], dates):
        data = (bar_returns[i][j])
        a = fu.toAggregated(np.asanyarray(data))
        # MFDFA Computations
        pymfdfa = fathon.MFDFA(a)
        n, F = pymfdfa.computeFlucVec(winSizes, qs, revSeg=revSeg, polOrd=polOrd)

        mfdfa_n_F_dict[j][i] = dict(zip(n, F))
        # dictionary to match all the n and F values this could be
        # more efficient

        # get the list values of H and intercept
        list_H, list_H_intercept = pymfdfa.fitFlucVec()  # same for H values
        mfdfa_H_dict[j][i] = [list_H, list_H_intercept]

        # get the mass exponents
        tau = pymfdfa.computeMassExponents()
        mfdfa_tau_dict[j][i] = tau

        # get the multi-fractal spectrum