Skip to main content

PyValuation

A library for stock and portfolio valuation.

This was originally made to help aid in my own stock valuation approach but I wanted to allow others to utilize this code as well.

The library is made up of four basic parent classes that inherent from two child classes.

The four parent classes are DCF, Valuation, RelativeValue and PortfolioValuation and the two child classes are FinancialData and ValuationCharts.

Installation

pip install PyValuation

Get started

FinancialData

The child class FinancialData is used for calculating numerous stock valuation metrics. These valuation metrics include Price to Earnings, Price to Sales, Return on Capital, company margins and others.

FinancialData class also acts as a parent class and inherents the FinancialStatements child class.

The FinancialStatements child class uses two methods to pull companies Income Statements, Balance Sheets and Cash Flow Statements. The first method is a basic call to the yfinance modules respective get_financials, get_balancesheet, get_cashflow functions. The second method FinancialStatements uses is a webscrapping version where we utilize BeautifulSoup from the bs4 module to pull the companies financial statements from yahoo finance directly.

How to pull specific financial statments using both methods.

  1. yfinance module

import PyValuation as pv



stock = pv.FinancialData('TICKER')



stock.balancesheet()

  1. BeautifulSoup

import PyValuation as pv



stock = pv.FinancialData('TICKER')



stock.soupbalancesheet()

FinancialData's main method is the input function used to calculate multiple valuation metrics and inputs for a discounted cash flow model.

How to use FinancialData's input function.


import PyValuation as pv



stock = pv.FinancialData('TICKER')



stock._inputs()

The inputs function will return a dictonary of valutaion metrics including the following, Retention Ratio's, Reinvestment Rate, Cost of Equity, Return on Capital and others.

ValuationCharts

ValuationCharts is another child class that calculates valuation metrics and plots them over time. This is useful for analyzing how specific company metrics change during certain market periods.

ValuationCharts relies on the bs4 module to web scrape historical shares outstanding. The historical shares outstanding is used in numerous other calculations like calculating and plotting a historical price to earnings ratio.

How to use Valuation charts

  1. Plotting shares outstanding over time.

import PyValuation as pv



stock = pv.ValuationCharts('TICKER')



stock.sharesoutstanding_chart()

  1. Plotting basic valuation metric over time

import PyValuation as pv



stock = pv.ValuationCharts('TICKER')



stock.pb_chart()

Valuation

The Valuation class acts as a parent class to ValuationCharts so it has multiple plotting capabilities within it. Valuation also calculates multiple valuation metrics but displays them using print statements in a more visually pleasing manner.

The Valuation classes main methods are credit_score, cogp and undervalue spotting.

  1. credit_score

The credit_score method uses the modified Altman's Z-score to calculate a make shift credit score and uses a print statement to display the stock in questions credit score compared to what its potential credit rating would be.


import PyValuation as pv



stock = pv.Valuation('TICKER')



stock.credit_score()

  1. cogp

cogp or core operating growth profile is a useful metric for calculting the cash generating power of a company. The cogp method calculates the operating cushion and subtracts that from the working capital to revenue percentage to get the core operating growth profile.


import PyValuation as pv



stock = pv.Valuation('TICKER')



stock.cogp()

  1. undervalue_spotting

The undervalue_spotting method calculates numeroud valuation metrics and uses print statements to display them in a way that is easy to read and compare in order to spot if a company is traditionaly undervalued.


import PyValuation as pv



stock = pv.Valuation('TICKER')



stock.undervalue_spotting()

DCF

The DCF class is used for dicounted cash flow modeling of a company. The DCF class has methods current_cashflows, growth_rates, projected_cashflows, intrinsic_value and outside_spread.

We will use the outside_spread as an example.


import PyValuation as pv



stock = pv.DCF('TICKER')



stock.outside_spread()

We can also specify the inputs for the free cash flow equity and free cash flow to the firm that will be used


import PyValuation as pv



stock = pv.DCF('TICKER')



stock.outside_spread(10000000000, 10000000000)



RelativeValue

The RelativeValue class does similar calculations as the Valuation class but on a larger scale. The RelativeValue class uses a csv that has a list of S&P 500 company tickers and there respective industries in order to calculate multiple metrics for the specific industry as a whole.

There is also a market_share function that calculates the total revenue of an idustry and then plots pie charts and bar charts showing all the companies revenue as a percent of the total industries revenue.


import PyValuation as pv



stock = pv.RelativeValue('TICKER')



stock.market_share()

PortfolioValuation

The PortfolioValuation class is used to evaluate an investors portfolio. The class takes as parameters a start date and end date, cash in the portfolio and uses the keyword arguments functionality of python for a user to input any amount of tickers as the keys and the quantity of shares as the value.

The PortfolioValuation class has methods portfolio_performance, asset_allocation and efficient_frontier.

  1. portfolio_performance

The portfolio_performance method uses the pandas_datareader module to pull the stock prices of the given tickers for the specified time period then calculates and plots the cumulative return of the aggregated portfolio.


import PyValuation as pv



stock = pv.PortfolioValuation(start, end, TICKER = Quantity)



stock.portfolio_performance()

  1. asset_allocation

The asset_allocation method visualises the holding in the portfolio as a percent of the aggregate capital in the portfolio as a pie chart.


import PyValuation as pv



stock = pv.PortfolioValuation(start, end, TICKER = Quantity)



stock.asset_allocation()

  1. efficient_frontier

The efficient_frontier module takes as parameters a lower bound and upper bound for a target return level, and also takes in as an optional parameter the volatility of a portfolio along the effecient frontier.

The method returns a graph of the effecient frontier and if given the volatility parameter the method returns the weights of the optimal portfolio.


import PyValuation as pv



stock = pv.PortfolioValuation(start, end, TICKER = Quantity)



stock.efficient_frontier(.1, .3)

Release files for PyValuation 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for PyValuation 0.1.2
File Size Uploaded
PyValuation-0.1.2.tar.gz 3.0 MB Details

Built distribution (wheel)

Table of built distributions (wheels) for PyValuation 0.1.2
File Interpreter ABI Platform
PyValuation-0.1.2-py3-none-any.whl Python 3 none any Details

Total release size: 3.1 MB

Release files / PyValuation-0.1.2.tar.gz

Download URL PyValuation-0.1.2.tar.gz
Size 3.0 MB
Tags Source
SHA-256 checksum
How to use checksums
2fa4d0fbd7690a7a9e168513bed4e088d16bf23079704b425de86f114a5eac94
BLAKE2b-256 checksum
How to use checksums
cd6a1a5e92899c61d3eed3e30946fb171e6dbd8fe2e5d2f5c971f18a06510a8f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.7

Release files / PyValuation-0.1.2-py3-none-any.whl

Download URL PyValuation-0.1.2-py3-none-any.whl
Size 72.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
73f0f9a96d5cc8cdf1df552063f121eed5aa58e403f949715a13cdc5a9756502
BLAKE2b-256 checksum
How to use checksums
72458d546de07232d3be3076deaa5ac9e0da9a0d132902905fb54620b86ed99b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.7

Release history Release notifications | RSS feed

This release

0.1.2 This release

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page