# Path: tia/analysis/util.py
# def per_series(result_is_frame=0):
#     def _ps(fct):
#         return PerSeries(fct, result_is_frame=result_is_frame)
# 
#     return _ps


from collections import OrderedDict
from tia.analysis.util import per_series
import pandas as pd
import numpy as np
                import warnings
    import scipy.stats as stats
    import scipy.stats as stats
        else:
            n = rets.count() if full else above.count()
            upside = excess.sum() / n
            downside = downside_deviation(rets, mar=mar, full=full)
            return upside / downside
    else:
        vals = {c: upside_potential_ratio(rets[c], mar=mar, full=full, expanding=expanding) for c in rets.columns}
        if expanding:
            return pd.DataFrame(vals, columns=rets.columns)
        else:
            return pd.Series(vals)


@per_series()
def rolling_percentileofscore(series, window, min_periods=None):
    """Computue the score percentile for the specified window."""

    def _percentile(arr):
        score = arr[-1]
        vals = arr[:-1]
        return stats.percentileofscore(vals, score)

    notnull = series.dropna()
    min_periods = min_periods or window
    if notnull.empty:
        return pd.Series(np.nan, index=series.index)
    else:
        return pd.rolling_apply(notnull, window, _percentile, min_periods=min_periods).reindex(series.index)



# Path: tia/analysis/util.py
# def per_series(result_is_frame=0):
#     def _ps(fct):
#         return PerSeries(fct, result_is_frame=result_is_frame)
# 
#     return _ps


# Path: tia/analysis/perf.py
from collections import OrderedDict
from tia.analysis.util import per_series
import pandas as pd
import numpy as np
                import warnings
    import scipy.stats as stats
    import scipy.stats as stats

        else:
            n = rets.count() if full else above.count()
            upside = excess.sum() / n
            downside = downside_deviation(rets, mar=mar, full=full)
            return upside / downside
    else:
        vals = {c: upside_potential_ratio(rets[c], mar=mar, full=full, expanding=expanding) for c in rets.columns}
        if expanding:
            return pd.DataFrame(vals, columns=rets.columns)
        else:
            return pd.Series(vals)


@per_series()
def rolling_percentileofscore(series, window, min_periods=None):
    """Computue the score percentile for the specified window."""

    def _percentile(arr):
        score = arr[-1]
        vals = arr[:-1]
        return stats.percentileofscore(vals, score)

    notnull = series.dropna()
    min_periods = min_periods or window
    if notnull.empty:
        return pd.Series(np.nan, index=series.index)
    else:
        return pd.rolling_apply(notnull, window, _percentile, min_periods=min_periods).reindex(series.index)



@per_series()