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


Python DataReader.transpose方法代码示例

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


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

示例1: load

# 需要导入模块: from pandas.io.data import DataReader [as 别名]
# 或者: from pandas.io.data.DataReader import transpose [as 别名]
def load(tickers, start=datetime.now()-timedelta(days=255), 
			end=datetime.now()):
	"""load data from yahoo finance and do technique analysis

	Args:
		tickers (list) : list of valid stock tickers
		start (datetime) : historical data start date
		end (datetime) : historical data end date

	Returns:
		panel (pandas.panel) : a 3-dimensional data structure 
			Item axis : including Open, Close, High, Volume and 
			MACD, etc. TA indicators. 
			Major axis: historical datetime index
			minor axis: tickers
	"""
	panel = DataReader(tickers, "yahoo", start, end)
	panelCopy = panel.transpose(2, 1, 0, copy=True)
	smaDf = pd.DataFrame(index=panel.major_axis)
	BBUDf = pd.DataFrame(index=panel.major_axis)
	BBDDf = pd.DataFrame(index=panel.major_axis)
	BBMDf = pd.DataFrame(index=panel.major_axis)
	CCIDf = pd.DataFrame(index=panel.major_axis)
	MACDDf = pd.DataFrame(index=panel.major_axis)
	MACDSDf = pd.DataFrame(index=panel.major_axis)
	MACDHDf = pd.DataFrame(index=panel.major_axis)
	MFIDf = pd.DataFrame(index=panel.major_axis)
	MOMDf = pd.DataFrame(index=panel.major_axis)
	RSIDf = pd.DataFrame(index=panel.major_axis)
	StochSlowDf = pd.DataFrame(index=panel.major_axis)
	RSIDf = pd.DataFrame(index=panel.major_axis)
	WillDf = pd.DataFrame(index=panel.major_axis)
	HilbertPeriodDf = pd.DataFrame(index=panel.major_axis)
	HilbertPhaseDf = pd.DataFrame(index=panel.major_axis)

	for (t, df) in panelCopy.iteritems():
	    smaDf[t] = talib.SMA(df.Close.values)
	    BBUDf[t], BBMDf[t], BBDDf[t] = talib.BBANDS(df.Close.values)
	    CCIDf[t] = talib.CCI(df.High.values, df.Low.values, df.Close.values)
	    MACDDf[t], MACDSDf[t], MACDHDf[t] = talib.MACD(df.Close.values)
	    MFIDf[t] = talib.MFI(df.High.values, df.Low.values, df.Close.values, df.Volume.values)
	    MOMDf[t] = talib.MOM(df.Close.values)
	    RSIDf[t] = talib.RSI(df.Close.values)
	    WillDf[t] = talib.WILLR(df.High.values, df.Low.values, df.Close.values)
	    HilbertPeriodDf[t] = talib.HT_DCPERIOD(df.Close.values)
	    HilbertPhaseDf[t] = talib.HT_DCPHASE(df.Close.values)
	    
	    
	panel['SMA'] = smaDf
	panel['BB_upper'] = BBUDf
	panel['BB_center'] = BBMDf
	panel['BB_lower'] = BBDDf
	panel['BB_per'] = (panel.Close - panel.BB_lower) / (
						panel.BB_upper - panel.BB_lower)
	panel['BB_width'] = (panel.BB_upper - panel.BB_lower) / panel.BB_center
	panel['CCI'] = CCIDf
	panel['MACD'] = MACDDf
	panel['MACD_signal'] = MACDSDf
	panel['MACD_hist']= MACDHDf
	panel['MFI'] = MFIDf
	panel['MOM'] = MOMDf
	panel['RSI'] = RSIDf
	panel['Will'] = WillDf
	panel['DCPeriod'] = HilbertPeriodDf
	panel['DCPhase'] = HilbertPhaseDf
	return panel.transpose(2, 1, 0)
开发者ID:xingzhong,项目名称:PandasTA,代码行数:68,代码来源:pandasTA.py


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