Example #1
0
def test_dfa_pow_count():
    pydfa = fathon.DFA(ts1)
    winSizes = fu.powRangeByCount(1, 5, count=4, base=3)
    n1, F1 = pydfa.computeFlucVec(winSizes, revSeg=True)
    H1, H_int1 = pydfa.fitFlucVec()

    assert math.isclose(H1, 0.8465301940909294)
Example #2
0
def test_dfa_pow_step():
    pydfa = fathon.DFA(ts1)
    winSizes = fu.powRangeByStep(2, 7, step=2)
    n1, F1 = pydfa.computeFlucVec(winSizes, revSeg=True)
    H1, H_int1 = pydfa.fitFlucVec()

    assert math.isclose(H1, 0.7316763359204684)
Example #3
0
def test_dfa_lin_count():
    pydfa = fathon.DFA(ts1)
    winSizes = fu.linRangeByCount(10, 200)
    n1, F1 = pydfa.computeFlucVec(winSizes, revSeg=True)
    H1, H_int1 = pydfa.fitFlucVec()

    assert math.isclose(H1, 0.7982194289592676)
Example #4
0
def test_mat_dfa_mf():
    mf_dfa = fathon.DFA(fu.toAggregated(mf))
    n_mf, F_mf = mf_dfa.computeFlucVec(scales, revSeg=False, polOrd=1)
    idxs = get_idxs(n_mf, scales)
    n_mf = n_mf[idxs]
    F_mf = F_mf[idxs]
    H, _ = np.polyfit(np.log2(n_mf), np.log2(F_mf), 1)
    assert math.isclose(H, 0.77, rel_tol=1e-2, abs_tol=0)
Example #5
0
def test_mat_dfa_wn():
    w_dfa = fathon.DFA(fu.toAggregated(wn))
    n_w, F_w = w_dfa.computeFlucVec(scales, revSeg=False, polOrd=1)
    idxs = get_idxs(n_w, scales)
    n_w = n_w[idxs]
    F_w = F_w[idxs]
    H, _ = np.polyfit(np.log2(n_w), np.log2(F_w), 1)
    assert math.isclose(H, 0.45, rel_tol=1e-2, abs_tol=0)
Example #6
0
def test_dfa_H_log():
    pydfa = fathon.DFA(ts1)
    winSizes = fu.powRangeByCount(1, 5, count=4, base=3)
    n1, F1 = pydfa.computeFlucVec(winSizes, revSeg=True)
    H1, H_int1 = pydfa.fitFlucVec()
    H2, H_int2 = pydfa.fitFlucVec(logBase=2)
    H3, H_int3 = pydfa.fitFlucVec(logBase=10)
    H4, H_int4 = pydfa.fitFlucVec(logBase=1.4)

    assert (math.isclose(H1, H2) and math.isclose(H1, H3)
            and math.isclose(H1, H4) and math.isclose(H2, H3)
            and math.isclose(H2, H4) and math.isclose(H3, H4))
Example #7
0
def test_dfa_save_load():
    dfa = fathon.DFA(fu.toAggregated(ts))
    # save and load with empty results
    dfa.saveObject(get_object_path('dfa_obj'))
    n_load = fu.getObjectMember(get_object_path('dfa_obj', ext=True), 'n')
    F_load = fu.getObjectMember(get_object_path('dfa_obj', ext=True), 'F')
    assert np.array_equal(n_load, [])
    assert np.array_equal(F_load, [])
    #save and load with results
    n, F = dfa.computeFlucVec(fu.linRangeByStep(10, 500))
    H, I = dfa.fitFlucVec(100, 300)
    dfa.saveObject(get_object_path('dfa_obj'))
    n_load = fu.getObjectMember(get_object_path('dfa_obj', ext=True), 'n')
    F_load = fu.getObjectMember(get_object_path('dfa_obj', ext=True), 'F')
    assert np.array_equal(n_load, n)
    assert np.array_equal(F_load, F)
    # DFA from file
    dfa_2 = fathon.DFA(get_object_path('dfa_obj', ext=True))
    H_2, I_2 = dfa_2.fitFlucVec(100, 300)
    assert H_2 == H
    assert I_2 == I
        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
        alpha, mfSpect = pymfdfa.computeMultifractalSpectrum()
        mfdfa_alpha_spect[j][i] = [mfSpect, alpha]
        pydfa = fathon.DFA(a)
        n, F = pydfa.computeFlucVec(winSizes, revSeg=revSeg, polOrd=polOrd)
        dict_dfa[j][i] = dict(zip(n, F))  # dictionary to match all the n and F values

        H, H_intercept = pydfa.fitFlucVec()  # same for H values
        h_dict[j][i] = [H, H_intercept]

        print('for date', i, ' and bar type', j, 'you get', H)

    # everything below here is to store
    # saving DFA files first

    # -1-

    pickle_out_filename = os.path.join(experimentsDestination, symbol, 'DFA_' +
                                       'n_f_values' + "volume_width" + str(trade_volume_width)