Example #1
0
def test_yi_1tools_fecon235_paste_function():
    '''Test xau and foo pasted together as xaufoo dataframe.'''
    assert [col for col in xaufoo.columns] == ['XAU', 'FOO']
    assert xaufoo.shape == (30, 2)
    assert tools.tailvalue(xaufoo, pos=0) == 1393.75
    assert tools.tailvalue(xaufoo, pos=1) == 6393.75
    assert xaufoo.index[0] == pd.Timestamp('2013-03-08 00:00:00')
    assert xaufoo.index[-1] == pd.Timestamp('2013-04-18 00:00:00')
Example #2
0
def optimize_holt(dataframe, grids=50, alphas=(0.0, 1.0), betas=(0.0, 1.0)):
    '''Optimize Holt-Winters parameters alpha and beta for given data.
       The alphas and betas are boundaries of respective explored regions.
       Function interpolates "grids" from its low bound to its high bound,
       inclusive. Final output: [alpha, beta, losspc, median absolute loss]
       TIP: narrow down alphas and betas using optimize_holt iteratively.
    '''
    if grids > 49:
        system.warn("Optimizing Holt-Winters alphabetaloss may take TIME!")
        #  Exploring loss at all the grids is COMPUTATIONALLY INTENSE
        #  due to holt(), especially if the primary data is very large.
        #  Tip: truncate dataframe to recent data.
    result = yop.minBrute(fun=loss_holt, funarg=( dataframe, ), 
                          boundpairs=[alphas, betas], grids=grids)
    #  result is a numpy array, so convert to list:
    alpha, beta = list(result)
    #  Compute loss, given optimal parameters:
    loss = loss_holt((alpha, beta), dataframe)
    #  Compute percentage loss relative to absolute tailvalue:
    losspc = (float(loss) / abs(tools.tailvalue(dataframe))) * 100
    #  Since np.round and np.around print ugly, use Python round() to
    #  display alpha and beta. Also include losspc and median absolute loss:
    return [round(alpha, 4), round(beta, 4), round(losspc, 4), loss]
Example #3
0
def test_ys_gauss_mix_fecon235_check_xau_DataFrame():
    '''Check xau dataframe.'''
    assert tools.tailvalue( xau ) == 1393.75
Example #4
0
def test_yi_1tools_fecon235_check_foo_DataFrame():
    '''Check foo dataframe which is just xau + 5000.00 increase.'''
    assert [col for col in foo.columns] == ['FOO']
    assert tools.tailvalue(foo) == 6393.75
Example #5
0
def test_yi_1tools_fecon235_check_xau_DataFrame():
    '''Check xau dataframe.'''
    assert [col for col in xau.columns] == ['XAU']
    assert tools.tailvalue(xau) == 1393.75
Example #6
0
def test_yi_1tools_fecon235_lagdf_function():
    '''Test xaufoolag dataframe created by lagdf on xaufoo with lags=3.'''
    assert [col for col in xaufoolag.columns] == [
        'XAU_0', 'FOO_0', 'XAU_1', 'FOO_1', 'XAU_2', 'FOO_2', 'XAU_3', 'FOO_3'
    ]
    #  Number after underscore indicates lag.
    assert xaufoolag.shape == (27, 8)
    #                lags will introduce NaN, which are then dropped,
    #                so rows are reduced from 30 to 27.

    #  Making sure LAGGED VALUES are correctly placed...
    assert tools.tailvalue(xaufoolag, pos=0, row=1) == 1393.75
    assert tools.tailvalue(xaufoolag, pos=1, row=1) == 6393.75
    assert tools.tailvalue(xaufoolag, pos=2, row=1) == 1392.0
    assert tools.tailvalue(xaufoolag, pos=3, row=1) == 6392.0
    assert tools.tailvalue(xaufoolag, pos=4, row=1) == 1380.0
    assert tools.tailvalue(xaufoolag, pos=5, row=1) == 6380.0
    assert tools.tailvalue(xaufoolag, pos=6, row=1) == 1395.0
    assert tools.tailvalue(xaufoolag, pos=7, row=1) == 6395.0

    assert tools.tailvalue(xaufoolag, pos=0, row=2) == 1392.0
    assert tools.tailvalue(xaufoolag, pos=1, row=2) == 6392.0
    assert tools.tailvalue(xaufoolag, pos=2, row=2) == 1380.0
    assert tools.tailvalue(xaufoolag, pos=3, row=2) == 6380.0
    assert tools.tailvalue(xaufoolag, pos=4, row=2) == 1395.0
    assert tools.tailvalue(xaufoolag, pos=5, row=2) == 6395.0

    assert tools.tailvalue(xaufoolag, pos=0, row=3) == 1380.0
    assert tools.tailvalue(xaufoolag, pos=1, row=3) == 6380.0
    assert tools.tailvalue(xaufoolag, pos=2, row=3) == 1395.0
    assert tools.tailvalue(xaufoolag, pos=3, row=3) == 6395.0

    assert tools.tailvalue(xaufoolag, pos=0, row=4) == 1395.0
    assert tools.tailvalue(xaufoolag, pos=1, row=4) == 6395.0

    assert xaufoolag.index[0] == pd.Timestamp('2013-03-13 00:00:00')
    assert xaufoolag.index[-1] == pd.Timestamp('2013-04-18 00:00:00')
Example #7
0
def test_yi_fred_fecon235_check_xau_DataFrame():
    '''Check xau dataframe.'''
    assert [ col for col in xau.columns ] == ['XAU']
    assert tools.tailvalue( xau ) == 1393.75
Example #8
0
def test_ys_gauss_mix_fecon235_check_xau_DataFrame():
    '''Check xau dataframe.'''
    assert tools.tailvalue(xau) == 1393.75
Example #9
0
def test_yi_timeseries_fecon235_check_xau_DataFrame():
    '''Check xau dataframe.'''
    assert tools.tailvalue( xau ) == 1393.75