本文整理匯總了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)
示例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
示例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
示例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
示例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
示例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
示例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
示例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
示例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
示例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)
示例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
示例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)