def sharpe_ratio(r, riskfree_rate):
    '\n    Computes the annualized sharpe ratio of a set of returns\n    '
    r_valid = r[((r != 0) & r.notnull())]
    total_num_periods = r_valid.count()
    date_beg = r_valid.agg((lambda x: x.first_valid_index()))
    date_end = r_valid.agg((lambda x: x.last_valid_index()))
    try:
        years_fraction = ((date_end - date_beg).dt.days / 365.2425)
    except:
        years_fraction = ((date_end - date_beg).days / 365.2425)
    periods_per_year = (total_num_periods / years_fraction)
    rf_per_period = (((1 + riskfree_rate) ** (1 / periods_per_year)) - 1)
    excess_ret = (r - rf_per_period)
    ann_ex_ret = annualize_rets(excess_ret)
    ann_vol = annualize_vol(r)
    return (ann_ex_ret / ann_vol)
Computes the annualized sharpe ratio of a set of returns
def sharpe_ratio(r, riskfree_rate):
    '\n    \n    '
    r_valid = r[((r != 0) & r.notnull())]
    total_num_periods = r_valid.count()
    date_beg = r_valid.agg((lambda x: x.first_valid_index()))
    date_end = r_valid.agg((lambda x: x.last_valid_index()))
    try:
        years_fraction = ((date_end - date_beg).dt.days / 365.2425)
    except:
        years_fraction = ((date_end - date_beg).days / 365.2425)
    periods_per_year = (total_num_periods / years_fraction)
    rf_per_period = (((1 + riskfree_rate) ** (1 / periods_per_year)) - 1)
    excess_ret = (r - rf_per_period)
    ann_ex_ret = annualize_rets(excess_ret)
    ann_vol = annualize_vol(r)
    return (ann_ex_ret / ann_vol)