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


Python finance.quotes_historical_yahoo_ochl方法代码示例

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


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

示例1: sharpeRatio

# 需要导入模块: from matplotlib import finance [as 别名]
# 或者: from matplotlib.finance import quotes_historical_yahoo_ochl [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: ret_f

# 需要导入模块: from matplotlib import finance [as 别名]
# 或者: from matplotlib.finance import quotes_historical_yahoo_ochl [as 别名]
def ret_f(ticker,begdate, enddate):
    p = quotes_historical_yahoo_ochl(ticker, begdate,    
    enddate,asobject=True,adjusted=True)
    return((p.aclose[1:] - p.aclose[:-1])/p.aclose[:-1])
# 
开发者ID:PacktPublishing,项目名称:Python-for-Finance-Second-Edition,代码行数:7,代码来源:c6_08_dailyReturn_4_annual.py

示例3: dailyReturn

# 需要导入模块: from matplotlib import finance [as 别名]
# 或者: from matplotlib.finance import quotes_historical_yahoo_ochl [as 别名]
def dailyReturn(ticker,begdate,enddate):
     p = aa(ticker, begdate,enddate,asobject=True,adjusted=True)
     return p.aclose[1:]/p.aclose[:-1]-1
# 
开发者ID:PacktPublishing,项目名称:Python-for-Finance-Second-Edition,代码行数:6,代码来源:c6_27_get_beta_good.py

示例4: ret_f

# 需要导入模块: from matplotlib import finance [as 别名]
# 或者: from matplotlib.finance import quotes_historical_yahoo_ochl [as 别名]
def ret_f(ticker,begdate,enddate):
     p = getData(ticker,begdate, enddate,asobject=True,adjusted=True)
     ret=p.aclose[1:]
     ret=p.aclose[1:]/p.aclose[:-1]-1
     return(ret) 
开发者ID:PacktPublishing,项目名称:Python-for-Finance-Second-Edition,代码行数:7,代码来源:c4_16_ttest_2stocks.py

示例5: ret_f

# 需要导入模块: from matplotlib import finance [as 别名]
# 或者: from matplotlib.finance import quotes_historical_yahoo_ochl [as 别名]
def ret_f(ticker,begdate,enddte):
    x=getData(ticker,begdate,enddate,asobject=True,adjusted=True)
    ret =x.aclose[1:]/x.aclose[:-1]-1
    return ret 
开发者ID:PacktPublishing,项目名称:Python-for-Finance-Second-Edition,代码行数:6,代码来源:c9_32_mean_and_var.py

示例6: ret_annual

# 需要导入模块: from matplotlib import finance [as 别名]
# 或者: from matplotlib.finance import quotes_historical_yahoo_ochl [as 别名]
def ret_annual(ticker,begdate,enddte):
    x=getData(ticker,begdate,enddate,asobject=True,adjusted=True)
    logret =sp.log(x.aclose[1:]/x.aclose[:-1])
    date=[]
    d0=x.date
    for i in range(0,sp.size(logret)):
        date.append(d0[i].strftime("%Y"))
    y=pd.DataFrame(logret,date,columns=[ticker])
    return sp.exp(y.groupby(y.index).sum())-1 
开发者ID:PacktPublishing,项目名称:Python-for-Finance-Second-Edition,代码行数:11,代码来源:c9_44_impact_of_correlation_2stock_portfolio.py

示例7: ret_monthly

# 需要导入模块: from matplotlib import finance [as 别名]
# 或者: from matplotlib.finance import quotes_historical_yahoo_ochl [as 别名]
def ret_monthly(ticker):  #	function 1
    x = getData(ticker,(begYear,1,1),(endYear,12,31),asobject=True,adjusted=True)
    logret=np.log(x.aclose[1:]/x.aclose[:-1]) 
    date=[]
    d0=x.date
    for i in range(0,np.size(logret)): 
        date.append(''.join([d0[i].strftime("%Y"),d0[i].strftime("%m")]))
    y=pd.DataFrame(logret,date,columns=[ticker]) 
    return y.groupby(y.index).sum()

# function 2: objective function 
开发者ID:PacktPublishing,项目名称:Python-for-Finance-Second-Edition,代码行数:13,代码来源:c9_50_efficient_frontier.py

示例8: ret_f

# 需要导入模块: from matplotlib import finance [as 别名]
# 或者: from matplotlib.finance import quotes_historical_yahoo_ochl [as 别名]
def ret_f(ticker):  #	function 1
    x = getData(ticker,begdate,enddate,asobject=True,adjusted=True)
    ret=x.aclose[1:]/x.aclose[:-1]-1 
    ddate=x['date'][1:]
    y=pd.DataFrame(ret,columns=[ticker],index=ddate) 
    return y.groupby(y.index).sum() 
开发者ID:PacktPublishing,项目名称:Python-for-Finance-Second-Edition,代码行数:8,代码来源:c9_77_Modigliani_m2_performance_measure.py

示例9: ret_annual

# 需要导入模块: from matplotlib import finance [as 别名]
# 或者: from matplotlib.finance import quotes_historical_yahoo_ochl [as 别名]
def ret_annual(ticker,begdate,enddte):
    x=getData(ticker,begdate,enddate,asobject=True,adjusted=True)
    logret =sp.log(x.aclose[1:]/x.aclose[:-1])
    date=[]
    d0=x.date
    for i in range(0,sp.size(logret)):
        date.append(d0[i].strftime("%Y"))
    y=pd.DataFrame(logret,date,columns=[ticker])
    return sp.exp(y.groupby(y.index).sum())-1
# function 2: estimate portfolio variance 
开发者ID:PacktPublishing,项目名称:Python-for-Finance-Second-Edition,代码行数:12,代码来源:c9_18_sharpe_ratio.py

示例10: ret_annual

# 需要导入模块: from matplotlib import finance [as 别名]
# 或者: from matplotlib.finance import quotes_historical_yahoo_ochl [as 别名]
def ret_annual(ticker,begdate,enddte):
    x=getData(ticker,begdate,enddate,asobject=True,adjusted=True)
    logret =sp.log(x.aclose[1:]/x.aclose[:-1])
    date=[]
    d0=x.date
    for i in range(0,sp.size(logret)):
        date.append(d0[i].strftime("%Y"))
    y=pd.DataFrame(logret,date,columns=[ticker])
    return sp.exp(y.groupby(y.index).sum())-1
# function 2: estimate portfolio beta 
开发者ID:PacktPublishing,项目名称:Python-for-Finance-Second-Edition,代码行数:12,代码来源:c9_21_optimal_portfolio_based_on_Sortino_ratio.py

示例11: ret_annual

# 需要导入模块: from matplotlib import finance [as 别名]
# 或者: from matplotlib.finance import quotes_historical_yahoo_ochl [as 别名]
def ret_annual(ticker,begdate,enddte):
    x=getData(ticker,begdate,enddate,asobject=True,adjusted=True)
    logret =sp.log(x.aclose[1:]/x.aclose[:-1])
    date=[]
    d0=x.date
    for i in range(0,sp.size(logret)):
        date.append(d0[i].strftime("%Y"))
    y=pd.DataFrame(logret,date,columns=[ticker])
    return sp.exp(y.groupby(y.index).sum())-1

# function 2: estimate LPSD 
开发者ID:PacktPublishing,项目名称:Python-for-Finance-Second-Edition,代码行数:13,代码来源:c9_23_efficient_based_on_sortino_ratio.py

示例12: ret_monthly

# 需要导入模块: from matplotlib import finance [as 别名]
# 或者: from matplotlib.finance import quotes_historical_yahoo_ochl [as 别名]
def ret_monthly(ticker):  #	function 1
    x = getData(ticker,(begYear,1,1),(endYear,12,31),asobject=True,adjusted=True)
    logret=np.log(x.aclose[1:]/x.aclose[:-1]) 
    date=[]
    d0=x.date
    for i in range(0,np.size(logret)): 
        date.append(''.join([d0[i].strftime("%Y"),d0[i].strftime("%m")]))
    y=pd.DataFrame(logret,date,columns=[ticker]) 
    return y.groupby(y.index).sum() 
开发者ID:PacktPublishing,项目名称:Python-for-Finance-Second-Edition,代码行数:11,代码来源:c9_52_impact_of_correlation_on_efficient_frontier_notWorking.py

示例13: dailyRet

# 需要导入模块: from matplotlib import finance [as 别名]
# 或者: from matplotlib.finance import quotes_historical_yahoo_ochl [as 别名]
def dailyRet(ticker,begdate,enddate):
    p =getData(ticker, begdate, enddate,asobject=True,adjusted=True)
    return p.aclose[1:]/p.aclose[:-1]-1 
开发者ID:PacktPublishing,项目名称:Python-for-Finance-Second-Edition,代码行数:5,代码来源:c8_34_Durbin_Watson_test_CAPM_IBM_residual.py

示例14: ret_f

# 需要导入模块: from matplotlib import finance [as 别名]
# 或者: from matplotlib.finance import quotes_historical_yahoo_ochl [as 别名]
def ret_f(ticker,begdate,enddate): 
    p = getData(ticker,begdate, enddate,asobject=True,adjusted=True) 
    return p.aclose[1:]/p.aclose[:-1]-1 
开发者ID:PacktPublishing,项目名称:Python-for-Finance-Second-Edition,代码行数:5,代码来源:c8_27_test_equal_variances.py

示例15: ret_f

# 需要导入模块: from matplotlib import finance [as 别名]
# 或者: from matplotlib.finance import quotes_historical_yahoo_ochl [as 别名]
def ret_f(ticker,begdate,enddate):
    p =getData(ticker, begdate, enddate,asobject=True, adjusted=True)
    ret = p.aclose[1:]/p.aclose[:-1]-1 
    date_=p.date
    return pd.DataFrame(data=ret,index=date_[1:],columns=['ret'])
#
# call the above function twice 
开发者ID:PacktPublishing,项目名称:Python-for-Finance-Second-Edition,代码行数:9,代码来源:c15_07_equal_vol_2periods.py


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