yFinance - Eli Policape Stock Performance Data for Microsoft and SPY ETF
License: GPL3
ubuntu2204
Kernel: Python 3 (system-wide)
In [1]:
In [3]:
In [4]:
Out[4]:
'C:\\ProgramData\\Anaconda3\\envs\\yfinance'
QuantStats functions
In [5]:
Out[5]:
['basic',
'full',
'html',
'iDisplay',
'iHTML',
'metrics',
'plots',
'relativedelta']
In [6]:
Out[6]:
['daily_returns',
'distribution',
'drawdown',
'drawdowns_periods',
'earnings',
'histogram',
'log_returns',
'monthly_heatmap',
'monthly_returns',
'plotly',
'returns',
'rolling_beta',
'rolling_sharpe',
'rolling_sortino',
'rolling_volatility',
'snapshot',
'to_plotly',
'warnings',
'yearly_returns']
QuantStats is comprised of 3 main modules:
Creating a report
You can create 7 different report tearsheets:
In [7]:
Out[7]:
yfinance.Ticker object <MSFT>
In [8]:
In [9]:
Out[9]:
In [10]:
Out[10]:
In [11]:
Out[11]:
Series([], Name: Dividends, dtype: int64)
In [12]:
Out[12]:
Date
1986-03-13 00:00:00-05:00 NaN
1986-03-14 00:00:00-05:00 0.035712
1986-03-17 00:00:00-05:00 0.017250
1986-03-18 00:00:00-05:00 -0.025431
1986-03-19 00:00:00-05:00 -0.017391
...
2023-10-11 00:00:00-04:00 0.012272
2023-10-12 00:00:00-04:00 -0.003790
2023-10-13 00:00:00-04:00 -0.010358
2023-10-16 00:00:00-04:00 0.014982
2023-10-17 00:00:00-04:00 0.000872
Name: Close, Length: 9476, dtype: float64
In [13]:
Out[13]:
In [14]:
Out[14]:
In [15]:
Out[15]:
In [16]:
Out[16]:
C:\ProgramData\Anaconda3\envs\yfinance\lib\site-packages\quantstats\stats.py:968: FutureWarning: In a future version of pandas all arguments of DataFrame.pivot will be keyword-only.
returns = returns.pivot('Year', 'Month', 'Returns').fillna(0)
In [17]:
Out[17]:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
Cell In [17], line 2
1 from pandas_datareader import data as pdr
----> 2 data = pdr.get_data_yahoo("SPY")
3 data
File C:NaN
, in get_data_yahoo(*args, **kwargs)
79 def get_data_yahoo(*args, **kwargs):
---> 80 return YahooDailyReader(*args, **kwargs).read()
File C:NaN
, in _DailyBaseReader.read(self)
251 # If a single symbol, (e.g., 'GOOG')
252 if isinstance(self.symbols, (string_types, int)):
--> 253 df = self._read_one_data(self.url, params=self._get_params(self.symbols))
254 # Or multiple symbols, (e.g., ['GOOG', 'AAPL', 'MSFT'])
255 elif isinstance(self.symbols, DataFrame):
File C:NaN
, in YahooDailyReader._read_one_data(self, url, params)
151 try:
152 j = json.loads(re.search(ptrn, resp.text, re.DOTALL).group(1))
--> 153 data = j["context"]["dispatcher"]["stores"]["HistoricalPriceStore"]
154 except KeyError:
155 msg = "No data fetched for symbol {} using {}"
TypeError: string indices must be integers
In [18]:
Out[18]:
yfinance.Ticker object <SPY>
In [0]:
In [19]:
Out[19]:
In [20]:
Out[20]:
Date
1993-01-29 00:00:00-05:00 NaN
1993-02-01 00:00:00-05:00 0.007113
1993-02-02 00:00:00-05:00 0.002119
1993-02-03 00:00:00-05:00 0.010570
1993-02-04 00:00:00-05:00 0.004185
...
2023-10-10 00:00:00-04:00 0.005205
2023-10-11 00:00:00-04:00 0.004096
2023-10-12 00:00:00-04:00 -0.006096
2023-10-13 00:00:00-04:00 -0.004981
2023-10-16 00:00:00-04:00 0.010521
Name: Close, Length: 7734, dtype: float64
In [21]:
Out[21]:
-0.02894721345003485
In [22]:
Out[22]:
In [23]:
Out[23]:
In [24]:
Out[24]:
In [25]:
Out[25]:
C:\ProgramData\Anaconda3\envs\yfinance\lib\site-packages\quantstats\stats.py:968: FutureWarning: In a future version of pandas all arguments of DataFrame.pivot will be keyword-only.
returns = returns.pivot('Year', 'Month', 'Returns').fillna(0)
In [26]:
Out[26]:
In [29]:
Out[29]:
0.944087854833915
In [28]:
Out[28]:
1.0925793813066438
In [0]: