简体   繁体   English

如何在 Python 中使用 pandas_ta 库添加 ichimoku?

[英]How can add ichimoku with the pandas_ta library in Python?

https://github.com/twopirllc/pandas-ta#overlap-33 https://github.com/twopirllc/pandas-ta#overlap-33

import pandas_ta as ta
import pandas as pd


ichimoku = ta.ichimoku(df['high'], df['low'], df['close'])
df = pd.concat([df, ichimoku], axis=1)

TypeError: cannot concatenate object of type '<class 'tuple'>'; TypeError: 无法连接类型为“<class 'tuple'>”的 object; only Series and DataFrame objs are valid只有 Series 和 DataFrame 对象有效

ichimoku returns two data frames. ichimoku 返回两个数据帧。 One returns the high and low indicators, and the other returns the look-ahead indicator, so combining them requires a data frame for each.一个返回高低指标,另一个返回前瞻指标,因此将它们组合起来需要一个数据框。

import yfinance as yf
import pandas_ta as ta
import pandas as pd

df = yf.download("AAPL", start="2021-01-01", end="2022-01-01")

ichimoku = ta.ichimoku(df['High'], df['Low'], df['Close'])
df = pd.concat([df, ichimoku[0], ichimoku[1]], axis=1)

df.head()
Open    High    Low     Close   Adj Close   Volume  ISA_9   ISB_26  ITS_9   IKS_26  ICS_26  ISA_9   ISB_26
2021-01-04  133.520004  133.610001  126.760002  129.410004  128.617111  143301900.0     NaN     NaN     NaN     NaN     135.389999  NaN     NaN
2021-01-05  128.889999  131.740005  128.429993  131.009995  130.207291  97664900.0      NaN     NaN     NaN     NaN     135.130005  NaN     NaN
2021-01-06  127.720001  131.050003  126.379997  126.599998  125.824326  155088000.0     NaN     NaN     NaN     NaN     135.369995  NaN     NaN
2021-01-07  128.360001  131.630005  127.860001  130.919998  130.117859  109578200.0     NaN     NaN     NaN     NaN     133.190002  NaN     NaN
2021-01-08  132.429993  132.630005  130.229996  132.050003  131.240936  105158200.0     NaN     NaN     NaN     NaN     130.839996  NaN     NaN

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM