Code Monkey home page Code Monkey logo

thepassiveinvestor's Introduction

The Passive Investor

GitHub Sponsors Buy Me a Coffee Twitter LinkedIn Documentation PYPI Version PYPI Downloads

Theories and research about the stock market have stated that the semi-strong form of market efficiency seems to hold. This means that all public information is accurately reflected in the price of a financial instrument. This makes the job of a portfolio manager primarily managing the desired risk appetite of the client and not explicitly trying to outperform the market. This fact in combination with Finance professionals all around the world looking for that 'edge' to make their investment decisions as profitable as possible, makes it so the average joe can not compete.

Therefore, the term 'Passive Investing' is often coined around. This refers to buying funds (either ETFs or Mutual Funds) that follow the index (i.e. S&P 500, Dow Jones Index) or a broad market (Developed Markets, MSCI World) for diversification benefits. This means that a sudden decrease in performance of one stock within the index does not (on average) lead to a significant decline in the index as a whole. This allows the holder to spend limited time monitoring his holdings, therefore the term 'Passive'.

With a large increase in ETFs available (over 5,000 in 2020), it can become difficult to make the best choice in what you wish to invest. There are many different providers (iShares, Vanguard, Invesco) as well as with changes to the underlying stocks (i.e. High Yield, Super Dividends, Equal Weighted). This is quickly reflected when looking for a S&P 500 ETF as there are over 20 different ETFs available. With this package, I wish to make investment decisions easier to make and manage.

An example of the output can be found in the GIF below. This depicts several ETFs collected from the Top ETFs according to Yahoo Finance.

outputExample

Installation

The package can be installed via the following commands:

  1. pip install thepassiveinvestor
    • Alternatively, download this repository.
  2. (within Python) import thepassiveinvestor as pi

The functions within this package are:

  • collect_data(ticker) - collects the most important data for ETFs as listed in the Functionality section.
  • create_ETF_report(tickers, filename, folder=None) - uses collect_data to create an Excel report with data, as depicted in the GIF above, per sheet for each ticker.

Therefore, if you wish to collect data on an ETF or create a report of a selection of ETFs you can use the following example:

import thepassiveinvestor as pi

# Collect data from a specific ETF
vanguard_sp500 = pi.collect_data('VOO')

# Show the data
vanguard_sp500

Which returns the following:

{'long_name': 'Vanguard 500 Index Fund', 'summary': "The fund employs an indexing investment approach designed to track the performance of the Standard & Poor's 500 Index, a widely recognized benchmark of U.S. stock market performance that is dominated by the stocks of large U.S. companies. The advisor attempts to replicate the target index by investing all, or substantially all, of its assets in the stocks that make up the index, holding each stock in approximately the same proportion as its weighting in the index.", 'image_URL': 'https://s.yimg.com/lq/i/fi/3_0stylelargeeq2.gif', 'sector_holdings': {'realestate': '2.75%', 'consumer_cyclical': '10.13%', 'basic_materials': '2.4%', 'consumer_defensive': '7.38%', 'technology': '23.65%', 'communication_services': '7.43%', 'financial_services': '13.7%', 'utilities': '2.43%', 'industrials': '8.82%', 'energy': '5.11%', 'healthcare': '15.27%'}, 'company_holdings': {'Apple Inc': '5.92%', 'Microsoft Corp': '5.62%', 'Amazon.com Inc': '4.06%', 'Facebook Inc Class A': '2.29%', 'Alphabet Inc Class A': '2.02%', 'Alphabet Inc Class C': '1.97%', 'Berkshire Hathaway Inc Class B': '1.44%', 'Tesla Inc': '1.44%', 'NVIDIA Corp': '1.37%', 'JPMorgan Chase & Co': '1.3%'}, 'annual_returns': {'2022': '-18.15%', '2021': '28.66%', '2020': '18.35%', '2019': '31.46%', '2018': '-4.42%', '2017': '21.78%'}, 'risk_data': {'5y': {'year': '5y', 'alpha': -0.04, 'beta': 1, 'meanAnnualReturn': 0.89, 'rSquared': 100, 'stdDev': 18.69, 'sharpeRatio': -0.19, 'treynorRatio': 8.04}, '3y': {'year': '3y', 'alpha': -0.04, 'beta': 1, 'meanAnnualReturn': 0.8, 'rSquared': 100, 'stdDev': 21.17, 'sharpeRatio': -0.55, 'treynorRatio': 6.76}, '10y': {'year': '10y', 'alpha': -0.04, 'beta': 1, 'meanAnnualReturn': 1.08, 'rSquared': 100, 'stdDev': 14.78, 'sharpeRatio': 0.88, 'treynorRatio': 11.7}}, 'key_characteristics': {'fundInceptionDate': '2010-09-07', 'category': 'Large Blend', 'totalAssets': 744769716224, 'currency': 'USD', 'navPrice': 366.24, 'previousClose': 365.67}}

You also have the option to generate a comparison report as follows:

import thepassiveinvestor as pi

# Collect data from a set of ETFs and compare them
etf_comparison = pi.collect_data(['VOO', 'QQQ', 'ARKG', 'VUG', 'SCHA', 'VWO'], comparison=True)

# Show the comparison
etf_comparison

Which returns the following:

VOO QQQ ARKG VUG SCHA VWO
('sector_holdings', 'realestate') 2.75% 0.29% 0% 2.55% 7.16% 2.95%
('sector_holdings', 'consumer_cyclical') 10.13% 14.2% 0% 18.09% 12.75% 12.92%
('sector_holdings', 'basic_materials') 2.4% 0% 0% 2.01% 4.35% 9.34%
('sector_holdings', 'consumer_defensive') 7.38% 6.67% 0% 2.92% 4.12% 6.23%
('sector_holdings', 'technology') 23.65% 47.62% 3.41% 41.19% 14.18% 15.49%
('sector_holdings', 'communication_services') 7.43% 15.99% 0% 11.96% 2.74% 8.72%
('sector_holdings', 'financial_services') 13.7% 0.74% 0% 6.95% 15.68% 20.63%
('sector_holdings', 'utilities') 2.43% 0.88% 0% 0% 1.83% 3.78%
('sector_holdings', 'industrials') 8.82% 4.75% 0% 4.64% 16.16% 7.26%
('sector_holdings', 'energy') 5.11% 0.49% 0% 1.35% 5.85% 5.36%
('sector_holdings', 'healthcare') 15.27% 7.54% 96.58% 8.13% 13.98% 4.6%
('annual_returns', '2022') -18.15% -32.49% -53.94% -33.13% -19.8% -17.72%
('annual_returns', '2021') 28.66% 27.24% -33.89% 27.26% 16.35% 0.96%
('annual_returns', '2020') 18.35% 48.6% 180.51% 40.16% 19.35% 15.32%
('annual_returns', '2019') 31.46% 39.12% 43.75% 37.26% 26.54% 20.4%
('annual_returns', '2018') -4.42% -0.14% 0.59% -3.32% -11.75% -14.57%
('annual_returns', '2017') 21.78% 32.7% 45.41% 27.8% 15.04% 31.38%
('key_characteristics', 'fundInceptionDate') 2010-09-07 1999-03-10 2014-10-31 2004-01-26 2009-11-03 2005-03-04
('key_characteristics', 'category') Large Blend Large Growth Health Large Growth Small Blend Diversified Emerging Mkts
('key_characteristics', 'totalAssets') 744769716224 145931501568 1899108352 132303921152 13327223808 93044613120
('key_characteristics', 'currency') USD USD USD USD USD USD
('key_characteristics', 'navPrice') 366.24 281.03 32.79 225.08 43.42 41.9
('key_characteristics', 'previousClose') 365.67 281.54 33.43 225.66 43.41 41.92
('risk_data_3y', 'year') 3y 3y 3y 3y 3y 3y
('risk_data_3y', 'alpha') -0.04 0.76 -4.62 -1.7 -3.72 -1.28
('risk_data_3y', 'beta') 1 1.08 1.32 1.11 1.15 0.9
('risk_data_3y', 'meanAnnualReturn') 0.8 0.92 0.25 0.74 0.6 0.05
('risk_data_3y', 'rSquared') 100 87.57 41.82 90.79 82.66 76.68
('risk_data_3y', 'stdDev') 21.17 24.49 41.28 24.6 26.8 20.04
('risk_data_3y', 'sharpeRatio') -0.55 -0.7 0.27 -0.72 1.58 2
('risk_data_3y', 'treynorRatio') 6.76 7.04 -4.51 4.7 2.44 -2.53
('risk_data_5y', 'year') 5y 5y 5y 5y 5y 5y
('risk_data_5y', 'alpha') -0.04 2.15 2.44 -0.2 -5.06 -0.93
('risk_data_5y', 'beta') 1 1.1 1.5 1.1 1.16 0.94
('risk_data_5y', 'meanAnnualReturn') 0.89 1.16 0.98 0.96 0.6 0.11
('risk_data_5y', 'rSquared') 100 88.49 45.66 91.7 83.48 78.97
('risk_data_5y', 'stdDev') 18.69 21.85 39.32 21.4 23.73 18.27
('risk_data_5y', 'sharpeRatio') -0.19 -0.44 -0.12 -0.3 1.77 1.58
('risk_data_5y', 'treynorRatio') 8.04 9.81 1.98 7.55 2.69 -1.74
('risk_data_10y', 'year') 10y 10y 10y 10y 10y 10y
('risk_data_10y', 'alpha') -0.04 2.46 0 -0.51 -4.08 -1.79
('risk_data_10y', 'beta') 1 1.1 0 1.08 1.16 0.98
('risk_data_10y', 'meanAnnualReturn') 1.08 1.39 0 1.13 0.9 0.24
('risk_data_10y', 'rSquared') 100 85.33 0 91.48 80.44 75.61
('risk_data_10y', 'stdDev') 14.78 17.56 0 16.76 19.06 16.38
('risk_data_10y', 'sharpeRatio') 0.88 0.39 0 0.78 2.92 1.44
('risk_data_10y', 'treynorRatio') 11.7 14.01 0 11.05 7.38 0.79

Lastly, if you wish to export to Excel this is also a possibility generating an Excel file that contains the most relevant information for each ticker.

import thepassiveinvestor as pi

# Create a report from a list of ETFs
etf_list = ['VOO', 'QQQ', 'ARKG', 'VUG', 'SCHA', 'VWO']
pi.create_ETF_report(etf_list, 'Popular ETFs.xlsx')

Which returns the following:

Screenshot 2023-01-19 at 13 26 48

Functionality

The package outputs an overview of each fund on a separate sheet. In this overview the following data is shown:

Topic Contains
General The title of the fund and a summary about the fund's purpose and goal.
Characteristics Inception date (the start of the fund), the category, assets under management (AUM), the denominated currency, net asset value (NAV), the latest close price and the Morningstar Style Box (if available).
Holdings Sector holdings (% in each sector) and company holdings (top 10 companies with highest %).
Risk Metrics All metrics are displayed in an interval of 3, 5 and 10 years. This includes Jensen's Alpha, Beta, Mean Annual Return, R-squared, Standard Deviation, Sharpe Ratio and Treynor Ratio.
Performance The last five annual returns of the fund as well as a graph depicting the adjusted close prices over the last 10 years. The actual data for this graph is available on a hidden sheet.

Contact

If you have any questions about the FinanceToolkit or would like to share with me what you have been working on, feel free to reach out to me via:

If you'd like to support my efforts, either help me out by contributing to the package or Sponsor Me.

Star History Chart

thepassiveinvestor's People

Contributors

bn-openx avatar dependabot[bot] avatar jerbouma avatar nwylynko avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

thepassiveinvestor's Issues

[Errno 22] Invalid argument: 'Example: C:\\Documents\\Investing\\Output\\S&P500_Output.xlsx'

Describe the error
After I entered the URL 'https://finance.yahoo.com/lookup/etf?s=developed%20markets' and click button "Create Report", I got error as follow:


Error

The program has crashed with the following error:

[Errno 22] Invalid argument: 'Example: C:\Documents\Investing\Output\S&P500_Output.xlsx'

If the problem persists, please create an Issue with the error message on the project's GitHub page:https://github.com/JerBouma/ThePassiveInvestor/issues.

To Reproduce
Include the input (filepath and ticker url/file)

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: [e.g. iOS] Windows 10
  • Browser [e.g. chrome, safari]
  • Version [e.g. 22]

Additional context
Add any other context about the problem here.

ValueError: Cannot mix tz-aware with tz-naive values

pi.create_ETF_report(['VOO'], 'Popular ETFs.xlsx')
D:\code\pycash\venv\Lib\site-packages\yahooquery\utils_init_.py:1470: FutureWarning: 'S' is deprecated and will be removed in a future version. Please use 's' instead of 'S'.
has_live_indice = index_utc[-1] >= last_trade - pd.Timedelta(2, "S")
D:\code\pycash\venv\Lib\site-packages\yahooquery\ticker.py:1333: FutureWarning: A value is trying to be set on a copy of a DataFrame or Series through chained assignment using an inplace method.
The behavior will change in pandas 3.0. This inplace method will never work because the intermediate object on which we are setting values always behaves as a copy.
For example, when doing 'df[col].method(value, inplace=True)', try using 'df.method({col: value}, inplace=True)' or df[col] = df[col].method(value) instead, to perform the operation inplace on the original object.
df["dividends"].fillna(0, inplace=True)
Traceback (most recent call last):
File "C:\Users\cohend\AppData\Local\JetBrains\PyCharm Community Edition 2023.1.1\plugins\python-ce\helpers\pydev\pydevconsole.py", line 364, in runcode
coro = func()
^^^^^^
File "", line 1, in
File "D:\code\pycash\venv\Lib\site-packages\thepassiveinvestor\create_report.py", line 49, in create_ETF_report
stock_data.index = pd.to_datetime(stock_data.index)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\code\pycash\venv\Lib\site-packages\pandas\core\tools\datetimes.py", line 1076, in to_datetime
result = convert_listlike(arg, format, name=arg.name)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\code\pycash\venv\Lib\site-packages\pandas\core\tools\datetimes.py", line 435, in _convert_listlike_datetimes
result, tz_parsed = objects_to_datetime64(
^^^^^^^^^^^^^^^^^^^^^^
File "D:\code\pycash\venv\Lib\site-packages\pandas\core\arrays\datetimes.py", line 2398, in objects_to_datetime64
result, tz_parsed = tslib.array_to_datetime(
^^^^^^^^^^^^^^^^^^^^^^^^
File "tslib.pyx", line 414, in pandas._libs.tslib.array_to_datetime
File "tslib.pyx", line 630, in pandas._libs.tslib.array_to_datetime
ValueError: Cannot mix tz-aware with tz-naive values

Issue with yahooquery/fc.yahoo.com causing theprivateinvestor not to work

Hi Jeroen,

There seems to be a problem with yahooquery/fc.yahoo.com that causes various applications, including your package thepassiveinvestor, to be unable to retrieve information for any ticker.

More details here: YahooQueryIssue

I personally kept getting the following error in the beginning:
ConnectionError: HTTPSConnectionPool(host= fc.yahoo.com , port=443): Max retries exceeded with url: / (Caused by ReadTimeoutError( HTTPSConnectionPool(host= fc.yahoo.com , port=443): Read timed out. (read timeout=5) ))

And then I tried to follow some of the suggested solutions (I am based in Europe/Germany) but none worked for me.
I also tried with different versions of yahooquery (the one I got when installing your package was 2.3.3, but what the posts recommended were more recent ones - 2.3.5 or 2.3.7 - but also none of those worked).

Now I am getting from thepassiveinvestor package this error: see the attached pic.
code_error

I was wondering if you have an idea how this can be fixed.
Thanks in advance.

Kind regards,
Niko

Error: Not able to collect data for V00

Hi!

While running the code, with the required libraries, send me this error:

"Not able to collect data for V00"

The code is just the one in the description:

import thepassiveinvestor as pi

Collect data from a specific ETF

vanguard_sp500 = pi.collect_data('V00')

Much thanks in advance

Getting errors running your base script

Running just your demo flows...

import thepassiveinvestor as pi

etf_list = ['BOTZ', 'ROBO', 'IRBO', 'ROBT']
pi.create_ETF_report(etf_list, 'MFReport.xlsx')

--- Result --
(sf) pages % python funds.py
Not able to collect data for BOTZ
Not able to collect data for ROBO
Not able to collect data for IRBO
Not able to collect data for ROBT
Traceback (most recent call last):
File "/myproject/pages/funds.py", line 11, in
msft.info
File "/sf/lib/python3.11/site-packages/yfinance/ticker.py", line 138, in info
return self.get_info()
^^^^^^^^^^^^^^^
File "/sf/lib/python3.11/site-packages/yfinance/base.py", line 1475, in get_info
data = self._quote.info
^^^^^^^^^^^^^^^^
File "/sf/lib/python3.11/site-packages/yfinance/scrapers/quote.py", line 95, in info
self._scrape(self.proxy)
File "/sf/lib/python3.11/site-packages/yfinance/scrapers/quote.py", line 124, in _scrape
json_data = self._data.get_json_data_stores(proxy=proxy)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/sf/lib/python3.11/site-packages/yfinance/data.py", line 41, in wrapped
return func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File "/sf/lib/python3.11/site-packages/yfinance/data.py", line 311, in get_json_data_stores
stores = decrypt_cryptojs_aes_stores(data, keys)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/sf/lib/python3.11/site-packages/yfinance/data.py", line 162, in decrypt_cryptojs_aes_stores
raise Exception("yfinance failed to decrypt Yahoo data response")
Exception: yfinance failed to decrypt Yahoo data response

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.