yfinance | Finance 's API | Business library
kandi X-RAY | yfinance Summary
kandi X-RAY | yfinance Summary
Download market data from Yahoo! Finance's API
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Download data from the database
- Return all quote objects for a given ISIN number
- Generic download function
- Updates the progress bar
- Return an empty DataFrame
- Prints the progress bar
- Download data from pandas
- Download data
- Advance the progress bar
- Assign ds to the shared dataframes
- Download a single ticker
- Return a namedtuple
- Download the latest options
- Convert options to pandas DataFrame
- Get torrents statistics
- Get a JSON object from the API
- List of available options
yfinance Key Features
yfinance Examples and Code Snippets
import yfinance as yf
msft = yf.Ticker("MSFT")
# get stock info
msft.info
# get historical market data
hist = msft.history(period="max")
# show meta information about the history (requires history() to be called first)
msft.history_metadata
# sh
import yfinance as yf
data = yf.download("SPY AAPL", start="2017-01-01", end="2017-04-30")
data = yf.download( # or pdr.get_data_yahoo(...
# tickers list or string as well
tickers = "SPY AAPL MSFT",
# use "period" instead o
from pandas_datareader import data as pdr
import yfinance as yf
yf.pdr_override() # <== that's all it takes :-)
# download dataframe
data = pdr.get_data_yahoo("SPY", start="2017-01-01", end="2017-04-30")
import yfinance as yf
import pandas as pd
import numpy as np
import plotly.express as px
import plotly.graph_objects as go
from datetime import datetime, timedelta
df = yf.download( tickers = 'BTC-USD',
start = '2021-08-3
import mplfinance as mpf
import yfinance as yf
candlesticks = yf.download("AAPL", start="2022-01-01", end="2022-04-01")
#levels = [155,160,180]
levels = [[('2022-02-16', 160.), ('2022-03-31',160.0)], [('2022-02-16',175.0),('2022-03-31',1
import yfinance as yf
ticker = ['AAPL','GOOGL','TSLA','MSFT']
data = yf.download(ticker, start="2021-01-01", end="2021-03-01")['Close']
import plotly.graph_objects as go
fig = go.Figure()
for t in data.columns:
fig.add_trace(go.Scatt
df = pd.DataFrame({'Date':['2022-01-27','2021-10-28','2021-07-29','2021-04-29','2021-01-28','2013-07-24','2013-05-01','2013-01-30','2012-10-23','2012-07-26'],
'symbol':['CMCSA','CMCSA','CMCSA','CMCSA','CMCSA','FB','FB','
pip install yfinance
import yfinance as yf
df = yf.download('AAPL', period='5y')
ticker = yf.Ticker('AAPL')
df = ticker.history(period="5y")
import yfinance as yf
import plotly.graph_objects as go
data = yf.download(tickers='EURUSD=X', period='1d', interval='30m')
fig = go.Figure(data=[go.Candlestick(x=data.index,
open=data['Open'],
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
import yfinance as yf
import pandas as pd
t = yf.Ticker("T")
df1 = t.earnings
df1.index = pd.to_datetime(df1.index, format='%Y')
df1.index = mdates.date2num(df1.index)
ax
Community Discussions
Trending Discussions on yfinance
QUESTION
I essentially have two different data frames, one for calculating weekly data (df) and a second one (df1) that has the plot values of the stock/crypto. On df, I have created a pandas column 'pivot' ((open+high+low)/3) using the weekly data to create a set of values containing the weekly pivot values.
Now I want to plot these weekly data (as lines) onto df1 which has the daily data. Therefore the x1 would be the start of the week and x2 be the end of the week. the y values being the pivot value from the df(weekly). Here is what I would want it to look like:
My Approach & Problem:
First of all, I am a beginner in Python, this is my second month of learning. My apologies if this was asked before.
I know the pivot values can be calculated using a single data frame & pandas group-by but I want to take the issue after this is done, so both ways should be fine if you are approaching this issue. What I would like to have is those final lines with OHLC candlesticks. I would like to plot these results using Plotly OHLC and go Shapes. What I am stuck with is iterating through the pivot weekly data frame and adding the lines as traces on top of the OHLC data daily data.
Here's my code so far:
...ANSWER
Answered 2022-Apr-14 at 14:39There are two ways to create a line segment: add a shape or use line mode on a scatter plot. I think the line mode of scatter plots is more advantageous because it allows for more detailed settings. For the data frame, introduce a loop process on a line-by-line basis to get the next line using the idx of the data frame. y-axis values are pivot values. I wanted to get Yokohama, so I moved the legend position up. Also, since we are looping through the scatter plot, we will have many legends for the pivot values, so we set the legend display to True for the first time only.
QUESTION
I want to drop entries based on 2 columns in Postgres. The code for to get the data is:
...ANSWER
Answered 2022-Apr-02 at 15:21Revised query. Test before using in production:
QUESTION
This might be a relatively difficult question;
The scope of the code I want to write, is to automate the aligment of Dates that i pull from yfinance regarding BTC and S&P 500
since the S&P500 (SPY) is not traded on weekends, but BTC is, I want to automatically delete the columns of dates from BTC that fall on weekends (or days where the S&P isn't treaded), to consistantly allign my 2 Dataframes.
In this case I have 15 data rows in BTC, whereas I only have 10 in SPY
I only need data where the dates match
Does anyone have an idea how I could do that?
...ANSWER
Answered 2022-Mar-21 at 15:27Here is a faster option for this purpose below:
QUESTION
The available options dates are below. How can I write a code so that it pulls all those dates instead of having to type them all out in a separate row?
2022-03-11, 2022-03-18, 2022-03-25, 2022-04-01, 2022-04-08, 2022-04-14, 2022-04-22, 2022-05-20, 2022-06-17, 2022-07-15, 2022-10-21, 2023-01-20, 2024-01-19
ANSWER
Answered 2022-Mar-10 at 07:55First of all, as these dates have no regular pattern, you should create a list of the dates.
QUESTION
I am calculating very simple daily stock calculations in data frame ( for e.g. SMA, VWAP, RSI etc). After I upgraded to anaconda 3.0, my code stopped working and gives followed error. I don't have much experience in coding and need some help.
KeyError: "Passing list-likes to .loc or [] with any missing labels is no longer supported. The following labels were missing: Index(['RSI', 'ZONE'], dtype='object'). See https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#deprecate-loc-reindex-listlike"
Followed is the code.
...ANSWER
Answered 2022-Feb-28 at 21:40A few lines need to be tweaked
- Instead of
QUESTION
I have the following code:
...ANSWER
Answered 2022-Feb-23 at 06:11Here b.index.strftime('%Y-%m-%d %I:%M:%S')
return one element Index, so for scalar need select first value:
QUESTION
I am trying to add an arrow on a given date and price to mpf plot. To do this i have the following code:
...ANSWER
Answered 2022-Feb-22 at 14:19The data passed into mpf.make_addplot()
must be the same length as the dataframe passed into mpf.plot()
. To plot only some points, the remaining points must be filled with nan values (float('nan')
, or np.nan
).
You can see this clearly in the documentation at cell **In [7]**
(and used in the following cells). See there where the signal data is generated as follows:
QUESTION
I am running the below-mentioned code to create a candlestick chart with traces but an error is being reflected as Exception has occurred: AttributeError 'dict' object has no attribute 'add_trace'
The code is as follows
...ANSWER
Answered 2022-Feb-16 at 08:01You can create figures from dictionaries or from graph objects.
In your example, you create fig
as a standard python dictionary. It only becomes a graph object once you plot it. add_trace
is not a valid python command for a dictionary, that's why it fails.
You want to create a graph object, to which you can apply add_trace
. See here
QUESTION
I have the following code which plots intraday stocks data.
...ANSWER
Answered 2022-Feb-16 at 07:07Maybe a hack:
QUESTION
I want to get historical price data using python and yfinance for Indonesian stocks. I see that there are many stocks that have the same name across different countries, for example AUTO (can be Indonesian company Astra Otoparts Tbk PT or NASDAQ's Autoweb Inc)
When I do yf.download('AUTO')
, it's returning me a price data of Autoweb Inc, instead of Indonesian stock Astra Otoparts Tbk PT.
How can we select which exchange we want the ticker from?
Thanks.
...ANSWER
Answered 2022-Feb-15 at 06:45I've only looked up the brand name in your question, AUTO.JK is the brand name. I have not checked if it is a rule to add abbreviated names.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install yfinance
Install yfinance using pip:. To install yfinance using conda, see this.
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page