Tia*_*doy 10 python python-3.x yfinance
import yfinance as yf
stock = yf.Ticker("ABEV3.SA")
data1= stock.info
print(data1)
Run Code Online (Sandbox Code Playgroud)
有“买入”和“卖出”,但没有实际股价。
小智 19
尝试这个:
import yfinance as yf
stock = yf.Ticker("ABEV3.SA")
price = stock.info['regularMarketPrice']
print(price)
Run Code Online (Sandbox Code Playgroud)
pel*_*ter 16
我使用这个过滤组合来只得到最后一个报价。
tickers = ['ABEV3.SA']
for ticker in tickers:
ticker_yahoo = yf.Ticker(ticker)
data = ticker_yahoo.history()
last_quote = (data.tail(1)['Close'].iloc[0])
print(ticker,last_quote)
Run Code Online (Sandbox Code Playgroud)
小智 6
此方法返回我的测试中最新的值。
def get_current_price(symbol):
ticker = yf.Ticker(symbol)
todays_data = ticker.history(period='1d')
return todays_data['Close'][0]
print(get_current_price('TSLA'))
Run Code Online (Sandbox Code Playgroud)
小智 0
yfinance具有下载功能,可让您下载指定时间段内的股票价格数据。例如,我将使用您想要数据的同一只股票。
import yfinance as yf
data = yf.download("ABEV3.SA", start="2020-03-01", end="2020-03-30")
Run Code Online (Sandbox Code Playgroud)
上面的行下载了指定日期的三月数据。
数据将是 pandas 数据框,因此您可以直接使用它进行操作。
希望这可以帮助。
| 归档时间: |
|
| 查看次数: |
15293 次 |
| 最近记录: |