当前位置: 首页>>代码示例>>Python>>正文


Python scipy.mean方法代码示例

本文整理汇总了Python中scipy.mean方法的典型用法代码示例。如果您正苦于以下问题:Python scipy.mean方法的具体用法?Python scipy.mean怎么用?Python scipy.mean使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在scipy的用法示例。


在下文中一共展示了scipy.mean方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: sharpeRatio

# 需要导入模块: import scipy [as 别名]
# 或者: from scipy import mean [as 别名]
def sharpeRatio(ticker,begdate=(2012,1,1),enddate=(2016,12,31)):
    """Objective: estimate Sharpe ratio for stock
        ticker  : stock symbol 
        begdate : beginning date
        enddate : ending date
        
       Example #1: sharpeRatio("ibm")
                     0.0068655583807256159
        
       Example #2: date1=(1990,1,1)
                   date2=(2015,12,23)
                   sharpeRatio("ibm",date1,date2)
                     0.027831010497755326
    """
    import scipy as sp
    from matplotlib.finance import quotes_historical_yahoo_ochl as getData
    p = getData(ticker,begdate, enddate,asobject=True,adjusted=True)
    ret=p.aclose[1:]/p.aclose[:-1]-1
    return sp.mean(ret)/sp.std(ret) 
开发者ID:PacktPublishing,项目名称:Python-for-Finance-Second-Edition,代码行数:21,代码来源:c7_16_def_sharpe_ratio.py

示例2: fit_params

# 需要导入模块: import scipy [as 别名]
# 或者: from scipy import mean [as 别名]
def fit_params(self, rfl_meas, geom, *args):
        """Given a reflectance estimate and one or more emissive parameters, 
          fit a state vector."""

        glint_band = s.argmin(abs(900-self.wl))
        glint = s.mean(rfl_meas[(glint_band-2):glint_band+2])
        water_band = s.argmin(abs(400-self.wl))
        water = s.mean(rfl_meas[(water_band-2):water_band+2])
        if glint > 0.05 or water < glint:
            glint = 0
        glint = max(self.bounds[self.glint_ind][0]+eps,
                    min(self.bounds[self.glint_ind][1]-eps, glint))
        lamb_est = rfl_meas - glint
        x = ThermalSurface.fit_params(self, lamb_est, geom)
        x[self.glint_ind] = glint
        return x 
开发者ID:isofit,项目名称:isofit,代码行数:18,代码来源:surface_glint.py

示例3: get_LDpred_sample_size

# 需要导入模块: import scipy [as 别名]
# 或者: from scipy import mean [as 别名]
def get_LDpred_sample_size(n,ns,verbose):
    if n is None:
        #If coefficient of variation is very small, then use one N nevertheless.
        n_cv = sp.std(ns)/sp.mean(ns)
        if n_cv<0.01:
            ldpred_n = sp.mean(ns)
            if verbose:
                print ("Sample size does not vary much (CV=%0.4f).  Using a fixed sample size of %0.2f"%(n_cv,ldpred_n))
        else:
            if verbose:
                print ("Using varying sample sizes")
                print ("Sample size ranges between %d and %d"%(min(ns),max(ns)))
                print ("Average sample size is %0.2f "%(sp.mean(ns)))
        ldpred_inf_n = sp.mean(ns)
        ldpred_n = None
    else:
        ldpred_n = float(n)
        if verbose:
            print ("Using the given fixed sample size of %d"%(n))
        ldpred_inf_n = float(n)
    return ldpred_n,ldpred_inf_n 
开发者ID:bvilhjal,项目名称:ldpred,代码行数:23,代码来源:LDpred_fast.py

示例4: get_html

# 需要导入模块: import scipy [as 别名]
# 或者: from scipy import mean [as 别名]
def get_html(self, base_file_name: str, h_level: int) -> str:
        sp = None # type: SingleProperty
        columns = [
            BOTableColumn("n", "{:5d}", lambda sp, _: sp.observations(), first),
            BOTableColumn("mean", "{:10.5f}", lambda sp, _: sp.mean(), first),
            BOTableColumn("mean / best mean", "{:5.5%}", lambda sp, means: sp.mean() / min(means), first),
            BOTableColumn("mean / mean of first impl", "{:5.5%}", lambda sp, means: sp.mean() / means[0], first),
            BOTableColumn("std / mean", "{:5.5%}", lambda sp, _: sp.std_dev_per_mean(), first),
            BOTableColumn("std / best mean", "{:5.5%}", lambda sp, means: sp.std_dev() / min(means), first),
            BOTableColumn("std / mean of first impl", "{:5.5%}", lambda sp, means: sp.std_dev() / means[0], first),
            BOTableColumn("median", "{:5.5f}", lambda sp, _: sp.median(), first)
        ]
        html = """
        <h{h}>Input: {input}</h{h}>
        The following plot shows the actual distribution of the measurements for each implementation.
        {box_plot}
        """.format(h=h_level, input=repr(self.input), box_plot=self.get_box_plot_html(base_file_name))
        html += self.table_html_for_vals_per_impl(columns, base_file_name)
        return html 
开发者ID:parttimenerd,项目名称:temci,代码行数:21,代码来源:game.py

示例5: get_x_per_impl

# 需要导入模块: import scipy [as 别名]
# 或者: from scipy import mean [as 别名]
def get_x_per_impl(self, property: StatProperty) -> t.Dict[str, t.List[float]]:
        """
        Returns a list of [property] for each implementation.

        :param property: property function that gets a SingleProperty object and a list of all means and returns a float
        """
        means = [x.mean() for x in self.impls.values()]  # type: t.List[float]
        singles = [x.get_single_property() for x in self.impls.values()]
        ret = InsertionTimeOrderedDict() # t.Dict[str, t.List[float]]
        property_arg_number = min(len(inspect.signature(property).parameters), 4)
        for (i, impl) in enumerate(self.impls):
            args = [singles[i], means, singles, i]
            ret[impl] = [property(*args[:property_arg_number])]
        #pprint(ret._dict)
        typecheck(ret._dict, Dict(key_type=Str(), value_type=List(Float()|Int()), unknown_keys=True))
        return ret 
开发者ID:parttimenerd,项目名称:temci,代码行数:18,代码来源:game.py

示例6: meanVarAnnual

# 需要导入模块: import scipy [as 别名]
# 或者: from scipy import mean [as 别名]
def meanVarAnnual(ret):
    meanDaily=sp.mean(ret)
    varDaily=sp.var(ret)
    meanAnnual=(1+meanDaily)**252
    varAnnual=varDaily*252
    return meanAnnual, varAnnual 
开发者ID:PacktPublishing,项目名称:Python-for-Finance-Second-Edition,代码行数:8,代码来源:c9_32_mean_and_var.py

示例7: portfolioRet

# 需要导入模块: import scipy [as 别名]
# 或者: from scipy import mean [as 别名]
def portfolioRet(R,w):
    mean_return=sp.mean(R,axis=0)
    ret = sp.array(mean_return)
    return sp.dot(w,ret) 
开发者ID:PacktPublishing,项目名称:Python-for-Finance-Second-Edition,代码行数:6,代码来源:c9_44_impact_of_correlation_2stock_portfolio.py

示例8: myUtilityFunction

# 需要导入模块: import scipy [as 别名]
# 或者: from scipy import mean [as 别名]
def myUtilityFunction(ret,A=1):
    meanDaily=sp.mean(ret)
    varDaily=sp.var(ret)
    meanAnnual=(1+meanDaily)**252
    varAnnual=varDaily*252
    return meanAnnual- 0.5*A*varAnnual 
开发者ID:PacktPublishing,项目名称:Python-for-Finance-Second-Edition,代码行数:8,代码来源:c9_30_utility_function_impact_Of_A.py

示例9: sharpe

# 需要导入模块: import scipy [as 别名]
# 或者: from scipy import mean [as 别名]
def sharpe(R,w):
    var = portfolio_var(R,w)
    mean_return=sp.mean(R,axis=0)
    ret = sp.array(mean_return)
    return (sp.dot(w,ret) - rf)/sp.sqrt(var)
# function 4: for given n-1 weights, return a negative sharpe ratio 
开发者ID:PacktPublishing,项目名称:Python-for-Finance-Second-Edition,代码行数:8,代码来源:c9_18_sharpe_ratio.py

示例10: treynor

# 需要导入模块: import scipy [as 别名]
# 或者: from scipy import mean [as 别名]
def treynor(R,w):
    betaP=portfolioBeta(betaGiven,w)
    mean_return=sp.mean(R,axis=0)
    ret = sp.array(mean_return)
    return (sp.dot(w,ret) - rf)/betaP
# function 4: for given n-1 weights, return a negative sharpe ratio 
开发者ID:PacktPublishing,项目名称:Python-for-Finance-Second-Edition,代码行数:8,代码来源:c9_21_optimal_portfolio_based_on_Sortino_ratio.py

示例11: treynor

# 需要导入模块: import scipy [as 别名]
# 或者: from scipy import mean [as 别名]
def treynor(R,w):
    betaP=portfolioBeta(betaGiven,w)
    mean_return=sp.mean(R,axis=0)
    ret = sp.array(mean_return)
    return (sp.dot(w,ret) - rf)/betaP
#
# function 4: for given n-1 weights, return a negative sharpe ratio 
开发者ID:PacktPublishing,项目名称:Python-for-Finance-Second-Edition,代码行数:9,代码来源:c9_19_treynor_ratio.py

示例12: __MR_superpixel_mean_vector

# 需要导入模块: import scipy [as 别名]
# 或者: from scipy import mean [as 别名]
def __MR_superpixel_mean_vector(self,img,labels):
        s = sp.amax(labels)+1
        vec = sp.zeros((s,3)).astype(float)
        for i in range(s):
            mask = labels == i
            super_v = img[mask].astype(float)
            mean = sp.mean(super_v,0)
            vec[i] = mean
        return vec 
开发者ID:ruanxiang,项目名称:mr_saliency,代码行数:11,代码来源:MR.py

示例13: amean_std

# 需要导入模块: import scipy [as 别名]
# 或者: from scipy import mean [as 别名]
def amean_std(values: t.List[float]) -> float:
    """
    Calculates the arithmetic mean.
    """
    return sp.std(values) 
开发者ID:parttimenerd,项目名称:temci,代码行数:7,代码来源:game.py

示例14: used_summarize_mean

# 需要导入模块: import scipy [as 别名]
# 或者: from scipy import mean [as 别名]
def used_summarize_mean(values: t.List[float]) -> float:
    if CALC_MODE in [Mode.geom_mean_rel_to_best, Mode.mean_rel_to_one]:
        return stats.gmean(values)
    elif CALC_MODE in [Mode.mean_rel_to_first]:
        return sp.mean(values)
    assert False 
开发者ID:parttimenerd,项目名称:temci,代码行数:8,代码来源:game.py

示例15: rel_mean_property

# 需要导入模块: import scipy [as 别名]
# 或者: from scipy import mean [as 别名]
def rel_mean_property(single: SingleProperty, means: t.List[float], *args) -> float:
    """
    A property function that returns the relative mean (the mean of the single / minimum of means)
    """
    return single.mean() / min(means) 
开发者ID:parttimenerd,项目名称:temci,代码行数:7,代码来源:game.py


注:本文中的scipy.mean方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。