numpy.average - python examples

Here are the examples of the python api numpy.average taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

145 Examples 7

3 View Complete Implementation : 06.py
Copyright MIT License
Author : swharden
def yyyyzeSweep(abf,plotToo=True,color=None,label=None):
    Y=abf.sweepYsmartbase()[abf.pointsPerSec*.5:]
    AV,SD=np.average(Y),np.std(Y)
    dev=5 # number of stdevs from the avg to set the range
    R1,R2=[(AV-SD)*dev,(AV+SD)*dev]
    nBins=1000
    hist,bins=np.histogram(Y,bins=nBins,range=[R1,R2],density=True)
    histSmooth=abf.convolve(hist,cm.kernel_gaussian(nBins/5))

    peakI=np.where(histSmooth==max(histSmooth))[0][0]
    peakX=bins[peakI]

    hist,histSmooth=hist/max(histSmooth),histSmooth/max(histSmooth) # normalize height to 1

    if plotToo:
        plt.plot(bins[1:],hist,'.',color=color,alpha=.2,ms=10)
        plt.plot(bins[1:],histSmooth,'-',color=color,lw=5,alpha=.5,label=label)

    return

3 View Complete Implementation : 05.py
Copyright MIT License
Author : swharden
def yyyyzeSweep(abf,plotToo=True,color=None,label=None):
    Y=abf.sweepYsmartbase()[abf.pointsPerSec*.5:]
    AV,SD=np.average(Y),np.std(Y)
    dev=5 # number of stdevs from the avg to set the range
    R1,R2=[(AV-SD)*dev,(AV+SD)*dev]
    nBins=1000
    hist,bins=np.histogram(Y,bins=nBins,range=[R1,R2],density=True)
    histSmooth=abf.convolve(hist,cm.kernel_gaussian(nBins/5))

    if plotToo:
        plt.plot(bins[1:],hist,'.',color=color,alpha=.2,ms=10)
        plt.plot(bins[1:],histSmooth,'-',color=color,lw=5,alpha=.5,label=label)

    return

3 View Complete Implementation : 03b.py
Copyright MIT License
Author : swharden
def yyyyzeSweep(abf,plotColor=None):    
    
    Y=abf.sweepYsmartbase()
    Y=Y[abf.pointsPerSec*.5:]

    # create a 1 Kbin histogram with bins centered around 3x the SD from the mean
    AV,SD=np.average(Y),np.std(Y)
    B1,B2=AV-SD*3,AV+SD*3
    nBins=1000
    hist, bin_edges = np.histogram(Y, density=True, bins=nBins, range=(B1,B2))
    histSmooth=np.convolve(hist,kernel_gaussian(nBins/2),mode='same')
        
    if plotColor:
        plt.plot(bin_edges[:-1],histSmooth,'-',alpha=.3,color=plotColor,lw=2)
    
    return

3 View Complete Implementation : 2016-12-17 04 simplify.py
Copyright MIT License
Author : swharden
    def phasicTonic(self,m1=None,m2=None):
        m1=0 if m1 is None else m1*self.pointsPerSec
        m2=len(abf.sweepY) if m2 is None else m2*self.pointsPerSec
        m1,m2=int(m1),int(m2)
        Y=self.sweepY[m1:m2]
        Y=Y-np.average(Y)
        return [np.average(Y),np.median(Y),np.var(Y),np.std(Y)]

3 View Complete Implementation : statistics.py
Copyright MIT License
Author : justthetips
def sharpe_ratio(returns, rf):
    """
    calculate the sharpe ratio
    :param returns: the returns
    :param rf: the risk free rates
    :return: the sharpe ratio
    """
    return (np.average(returns - rf)) / vol(returns)

3 View Complete Implementation : statistics.py
Copyright MIT License
Author : justthetips
def treynor_ratio(returns, market, rf):
    """
    calculate the treynor ratio
    :param returns: returns
    :param market: market returns
    :param rf: risk free returns
    :return: the treynor ratio
    """
    return (np.average(returns - rf)) / beta(returns, market)

3 View Complete Implementation : statistics.py
Copyright MIT License
Author : justthetips
def sterling_ratio(returns, rf, periods):
    """
    calculare the sterling ratio
    :param returns: the returns
    :param rf: the risk free rate
    :param periods: the number of periods
    :return: the sterling ratio
    """
    return (np.average(returns - rf)) / average_dd(returns, periods)

3 View Complete Implementation : statistics.py
Copyright MIT License
Author : justthetips
def burke_ratio(returns, rf, periods):
    """
    calculate the burke ratio
    :param returns: the returns
    :param rf: the risk free rate
    :param periods: the number of periods
    :return: the burke ratio
    """
    return (np.average(returns - rf)) / math.sqrt(average_dd_squared(returns, periods))

3 View Complete Implementation : statistics.py
Copyright MIT License
Author : justthetips
def kappa_three_ratio(returns, rf, target=0):
    """
    calculate the kappa three ratio
    :param returns: the returns
    :param rf: the risk free rate
    :param target: the return target
    :return: the ktr
    """
    return (np.average(returns - rf)) / math.pow(lpm(returns, target, 3), float(1 / 3))

3 View Complete Implementation : statistics.py
Copyright MIT License
Author : justthetips
def calmar_ratio(returns, rf):
    """
    calculate the calmar ratio
    :param returns: the returns
    :param rf: the risk free rate
    :return: the calmar ratio
    """
    return (np.average(returns - rf)) / max_dd(returns)