Ejemplo n.º 1
0
def omega_empirical(returns, target_rtn=0, log=True, plot=False, steps=1000):
    '''
    Omega Ratio based on empirical distribution.
    '''
    # validate_return_type(return_type)

    if not log:
        returns = pct_to_log_return(returns)

    # TODO
    ecdf = stt.ECDF(returns)

    # Generate computation space
    x = np.linspace(start=returns.min(), stop=returns.max(), num=steps)
    y = ecdf(x)

    norm_cdf = ss.norm.cdf(x, loc=returns.mean(), scale=returns.std(ddof=1))

    # Plot empirical distribution CDF versus Normal CDF with same mean and
    # stdev
    if plot:
        fig, ax = plt.subplots()
        fig.set_size_inches((12, 6))
        ax.plot(x, y, c='r', ls='--', lw=1.5, alpha=.8, label='ECDF')
        ax.plot(x, norm_cdf, alpha=.3, ls='-', c='b', lw=5, label='Normal CDF')
        ax.legend(loc='best')
        plt.show(fig)
        plt.close(fig)
Ejemplo n.º 2
0
import numpy as np  # module for array or mathematical operations
import statsmodels.tools.tools as tools  # Used to obtain ECDF generator
from matplotlib.ticker import MultipleLocator # Used to generate chart tick values

##############################  Open the Excel file  ##############################
xls = pandas.ExcelFile(r'd:\_mycode\python\data\Book1.xlsx')
# Parse the specific Excel sheet name into a pandas data frame object
df = xls.parse('Sheet1')

#######  Then create a data frame for each model containing the dB values #########
TL     = df[(df['Model']=='UA') & (df['txtParam']=='FMRES1')]['txtParamval']
Acc4dr = df[(df['Model']=='CP') & (df['txtParam']=='FMRES1')]['txtParamval']
Acc2dr = df[(df['Model']=='CS') & (df['txtParam']=='FMRES1')]['txtParamval']

############################  Generate ECDF for each model  #######################
ecdf_TL = tools.ECDF(TL)
ecdf_Acc4dr = tools.ECDF(Acc4dr)
ecdf_Acc2dr = tools.ECDF(Acc2dr)

##############################  Begin charting ECDF  ##############################
fig1 = plt.figure(1)
x_TL = np.linspace(TL.min(), TL.max())
y_TL = ecdf_TL(x_TL)
plt.step(x_TL, y_TL, label='TL')
x_Acc4dr = np.linspace(Acc4dr.min(), Acc4dr.max())
y_Acc4dr = ecdf_Acc4dr(x_Acc4dr)
plt.step(x_Acc4dr, y_Acc4dr, label='Acc4dr')
x_Acc2dr = np.linspace(Acc2dr.min(), Acc2dr.max())
y_Acc2dr = ecdf_Acc2dr(x_Acc2dr)
plt.step(x_Acc2dr, y_Acc2dr, label='Acc2dr')
plt.legend(loc='best')