【问题标题】:mplfinance moving average of specific columnmplfinance 特定列的移动平均线
【发布时间】:2020-09-19 11:01:20
【问题描述】:

我正在使用 mplfinance,我希望此代码中的移动平均线代表一个特定属性,即开盘价。

AAPL1 =pd.read_csv('./HMW1/AAPL.csv',index_col=0,parse_dates=True)

AAPL1.index.name = 'Date'
   
AAPL1 = AAPL1.loc['2020-03-15' : '2020-06-14']

mpf.plot(AAPL1 ,type='candle',mav=(10,20))

【问题讨论】:

    标签: python finance mplfinance


    【解决方案1】:

    目前 mplfinance 不支持 mav 用于“关闭”以外的任何内容。 (但是,如果您有兴趣为该项目做出贡献,这将是一个相对容易的增强功能;我很乐意为您提供指导)。

    同时,如果您想要“收盘”以外的移动平均线,您必须自己计算,并使用mpf.make_addplot() 绘制它。

    AAPL1 =pd.read_csv('./HMW1/AAPL.csv',index_col=0,parse_dates=True)
    
    AAPL1.index.name = 'Date'
       
    AAPL1 = AAPL1.loc['2020-03-15' : '2020-06-14']
    
    open_mav10 = AAPL1["Open"].rolling(10).mean().values
    open_mav20 = AAPL1["Open"].rolling(20).mean().values
    mavdf = pd.DataFrame(dict(OpMav10=open_mav10,OpMav20=open_mav20),index=df.index)
    
    ap = mpf.make_addplot(mavdf,type='line')
    
    mpf.plot(AAPL1 ,type='candle',addplot=ap)
    

    应该可以的。

    有关使用 mplfinance 的 make_addplot() api 的更多信息,另请参阅 this link
    (或者如果该链接未呈现,请尝试this one)。

    【讨论】:

      猜你喜欢
      • 2022-01-26
      • 1970-01-01
      • 1970-01-01
      • 2017-09-01
      • 2013-12-22
      • 1970-01-01
      • 2012-11-06
      • 1970-01-01
      • 2011-06-29
      相关资源
      最近更新 更多