Exemplo n.º 1
0
def test_sharpe_iid():
    data = np.array([
        0.259, .198, .364, -.081, .057, .055, .188, .317, .24, .184, -.01, .526
    ])

    # numpy array
    sharpe = perf.sharpe_iid(data, bench=.05, factor=1, log=True)

    assert (np.isclose(sharpe, .834364))

    sharpe = perf.sharpe_iid(data, bench=.05, factor=1, log=False)

    assert (np.isclose(sharpe, .834364))
    # below is for computing sharpe ratio with pct returns
    # assert(np.isclose(sharpe, 0.8189144744629443))

    # turn data to pandas.Series
    data = pd.Series(data)

    sharpe = perf.sharpe_iid(data, bench=.05, factor=1, log=True)

    assert (np.isclose(sharpe, .834364))

    sharpe = perf.sharpe_iid(data, bench=.05, factor=252, log=True)

    assert (np.isclose(sharpe, .834364 * np.sqrt(252)))

    sharpe = perf.sharpe_iid(data, bench=.05, factor=1, log=False)

    assert (np.isclose(sharpe, .834364))
Exemplo n.º 2
0
def test_sharpe_iid():
    data = np.array([
        0.259, .198, .364, -.081, .057, .055, .188, .317, .24, .184, -.01, .526
    ])

    # numpy array
    sharpe = perf.sharpe_iid(data, bench=.05, factor=1, return_type='log')

    assert (np.isclose(sharpe, .834364))

    sharpe = perf.sharpe_iid(data, bench=.05, factor=1, return_type='pct')

    assert (np.isclose(sharpe, 0.8189144744629443))

    # turn data to pandas.Series
    data = pd.Series(data)

    sharpe = perf.sharpe_iid(data, bench=.05, factor=1, return_type='log')

    assert (np.isclose(sharpe, .834364))

    sharpe = perf.sharpe_iid(data, bench=.05, factor=252, return_type='log')

    assert (np.isclose(sharpe, .834364 * np.sqrt(252)))

    sharpe = perf.sharpe_iid(data, bench=.05, factor=1, return_type='pct')

    assert (np.isclose(sharpe, 0.8189144744629443))
Exemplo n.º 3
0
Arquivo: pbo.py Projeto: jijoy/pypbo
def dsr_from_returns(test_sharpe, returns_df, risk_free=0):
    '''
    Calculate DSR based on a set of given returns_df.

    Parameters:
        test_sharpe : Reported sharpe, to be tested.
        returns_df : Log return series
        risk_free : Risk free return, default 0.
    Returns:
        DSR statistic
    '''
    T, N = returns_df.shape
    sharpe = perf.sharpe_iid(returns_df, bench=risk_free, factor=1)
    sharpe_std = np.std(sharpe, ddof=1)
    skew = returns_df.skew()
    kurtosis = returns_df.kurtosis() + 3

    dsr = dsr(test_sharpe,
              sharpe_std=sharpe_std,
              N=N,
              T=T,
              skew=skew,
              kurtosis=kurtosis)

    return dsr
Exemplo n.º 4
0
def psr_from_returns(returns, risk_free=0, target_sharpe=0):
    """
    PSR from return series.

    Parameters:
        returns:
            return series
        risk_free:
            risk free or benchmark rate for sharpe ratio calculation,
            default 0.
        target_sharpe:
            minimum sharpe ratio

    Returns:
        PSR probabilities.
    """
    T = len(returns)
    sharpe = perf.sharpe_iid(returns, bench=risk_free, factor=1)
    skew = returns.skew()
    kurtosis = returns.kurtosis() + 3

    return psr(
        sharpe=sharpe,
        T=T,
        skew=skew,
        kurtosis=kurtosis,
        target_sharpe=target_sharpe,
    )
Exemplo n.º 5
0
def metric(x):
    return np.sqrt(255) * perf.sharpe_iid(x)