Exemple #1
0
def carry_forecast(df, carryoffset):
    vol = util.robust_vol_calc(df.sprice.diff())    
    # we multiply with the sign of the carryoffset below because
    # the offset shows where the carry contract is - if it was
    # -1, meaning we look at the earlier contract, then we need
    # to have carry-price, if ahead then price-carry. The trick
    # with the sign() call below achieves that flip.
    raw_carry = (df.effprice-df.carryprice) / (carryoffset/12.)
    #raw_carry = raw_carry / np.abs(carryoffset/12.)
    forecast = util.carry(raw_carry, vol)
    forecast.loc[forecast > util.MAX_FORECAST] = util.MAX_FORECAST
    forecast.loc[forecast < -util.MAX_FORECAST] = -util.MAX_FORECAST
    return forecast
Exemple #2
0
def test_returns_sharpe_skew():
    import util, zipfile, pandas as pd

    with zipfile.ZipFile("../alg/legacycsv.zip", "r") as z:
        df = pd.read_csv(z.open("EDOLLAR_price.csv"), index_col=0, parse_dates=True)

    fast_ewma = pd.ewma(df.PRICE, span=32)
    slow_ewma = pd.ewma(df.PRICE, span=128)
    raw_ewmac = fast_ewma - slow_ewma
    vol = util.robust_vol_calc(df.PRICE.diff())
    forecast = raw_ewmac / vol
    sr, tval, pval = util.sharpe(df.PRICE, forecast)
    assert sr - 0.50 < 0.01
    s = util.skew(df.PRICE, forecast)
    assert s - (-0.57) < 0.01
Exemple #3
0
def test_returns_sharpe_skew():
    import util, zipfile, pandas as pd
    with zipfile.ZipFile('../alg/legacycsv.zip', 'r') as z:
        df = pd.read_csv(z.open('EDOLLAR_price.csv'),
                         index_col=0,
                         parse_dates=True)

    fast_ewma = pd.ewma(df.PRICE, span=32)
    slow_ewma = pd.ewma(df.PRICE, span=128)
    raw_ewmac = fast_ewma - slow_ewma
    vol = util.robust_vol_calc(df.PRICE.diff())
    forecast = raw_ewmac / vol
    sr, tval, pval = util.sharpe(df.PRICE, forecast)
    assert sr - 0.50 < 0.01
    s = util.skew(df.PRICE, forecast)
    assert s - (-0.57) < 0.01
Exemple #4
0
def calc_ewmac_forecast(price, slow, fast):
    vol = util.robust_vol_calc(price.diff())
    fast_ewma = pd.ewma(price, span=slow)
    slow_ewma = pd.ewma(price, span=fast)
    raw_ewmac = fast_ewma - slow_ewma
    return raw_ewmac / vol
Exemple #5
0
def calc_ewmac_forecast(price,slow,fast):
    vol = util.robust_vol_calc(price.diff())
    fast_ewma = pd.ewma(price, span=slow)
    slow_ewma = pd.ewma(price, span=fast)
    raw_ewmac = fast_ewma - slow_ewma
    return raw_ewmac /  vol