如何从雅虎财经图书馆获得调整后的收盘价

时间:2016-11-14 16:36:29

标签: python yahoo-finance

我正在使用Python中的Yahoo Finance Library来提取股票的数据。

<div class="grid-flex">

  <div class="grid_3">
    <div class="fmcircle_out">
      <a href="/article">
        <div class="fmcircle_border">
          <div class="fmcircle_in fmcircle_blue">
            <span>Opprett artikkel</span><img src="/img/article.png" alt="" />
          </div>
        </div>
      </a>
    </div>
  </div>
   
  <div class="grid_3">
    <div class="fmcircle_out">
      <a href="/event">
        <div class="fmcircle_border">
          <div class="fmcircle_in fmcircle_blue">
            <span>Opprett et kurs/event</span><img src="/img/event3.png" alt="" />
          </div>
        </div>
      </a>
    </div>
  </div>

</div>

我想在Y轴上绘制这个调整后的收盘价以及X轴上的相应日期,但是当我尝试这样做时,上面的代码会出错。

我正在使用Python 3.x,Anaconda

2 个答案:

答案 0 :(得分:1)

您可以按如下方式生成列表:

l = [ x['Close'] for x in data1]

情节:

import matplotlib.pyplot as plt
plt.plot(l)
plt.show()

答案 1 :(得分:0)

我明白了。

import yahoo_finance
from pylab import *
import numpy as np
import scipy.signal as sc
import matplotlib.pyplot as plt
import pandas as pd
import datetime as dt

ticker = 'GLD'
begdate = '2014-11-11'
enddate = '2016-11-11'
data = yahoo_finance.Share('GLD')
data1 = data.get_historical(begdate,enddate)
gld_df = pd.DataFrame(data1)
date_df = pd.to_datetime((list(gld_df["Date"])))
adj_close_df = list(gld_df["Adj_Close"])
plt.plot(date_df,adj_close_df)