Fundamentals 9 min read

Python Stock Fair‑Value Valuation Using Financial Data and Multiple Models

This tutorial demonstrates how to download a company's fundamental data via the EOD API and yfinance, compute financial metrics such as free‑cash‑flow, revenue and earnings growth, and combine three valuation models (FCF, sales and PE) in Python to estimate a stock's fair value and compare it with the current market price.

Python Programming Learning Circle
Python Programming Learning Circle
Python Programming Learning Circle
Python Stock Fair‑Value Valuation Using Financial Data and Multiple Models

This article explains how to build a Python project that estimates a stock's fair value using three different valuation methods based on financial statements.

First, it shows how to download quarterly fundamental data (balance sheet, income statement, cash‑flow) for a given ticker (e.g., FVRR.US ) using the EOD API and retrieve recent price data with yfinance .

<code>import matplotlib.pyplot as
import requests
import pandas as pd
from datetime import *
import numpy as np
import json
import urllib.request
import yfinance as yf
import warnings
warnings.filterwarnings('ignore')

EOD_API_KEY = 'your-api-key'
SYMBOL = 'FVRR.US'
</code>

The script defines get_data(symbol) to fetch JSON data from the EOD endpoint and prints the available keys.

<code>def get_data(symbol):
    url = f'https://eodhistoricaldata.com/api/fundamentals/{symbol}?api_token={EOD_API_KEY}'
    response = urllib.request.urlopen(url)
    data = json.loads(response.read())
    return data

data = get_data(symbol=SYMBOL)
print(data.keys())
</code>

Three valuation models are then implemented:

Free‑cash‑flow (FCF) model: calculates the latest quarterly free cash flow, its 20‑quarter average growth, shares outstanding, and price per share to compute fcf_fair_value .

Sales (Revenue) model: uses the latest quarterly total revenue, its 20‑quarter average growth, shares outstanding and price per share to compute sps_fair_value .

Price‑Earnings (PE) model: extracts the most recent EPS, average earnings‑estimate growth, and current price to compute pe_fair_value .

<code># Example for FCF valuation
fcf = pd.DataFrame(data['Financials']['Cash_Flow']['quarterly']).T.sort_index()['freeCashFlow'].astype(float)[-1]
fcf_growth = pd.DataFrame(data['Financials']['Cash_Flow']['quarterly']).T.sort_index()['freeCashFlow'].astype(float).pct_change().rolling(20).mean()[-1]
shares_outs = round(pd.DataFrame(data['outstandingShares']['quarterly']).T.set_index('dateFormatted').sort_index()['shares'].astype(float)[-1],0)
price = yf.download(SYMBOL.split('.')[0], date.today()-pd.DateOffset(5), date.today())['Adj Close'][-1]
fcf_per_share = fcf/shares_outs
print(f'fcf_fair_value: {fcf_per_share*(1+fcf_growth)*(price/fcf_per_share)}')
</code>

After calculating the three intrinsic values, the script aggregates them into a single DataFrame and prints the results, allowing a quick visual comparison with the current market price.

<code>def get_financial_metrics_valuation(data):
    # compute eps, eps_growth, fcf, fcf_growth, sales, sales_growth, shares_outs, price, pe, etc.
    # build dictionary df with keys: 'pe_intrinsic_value', 'fcf_intrinsic_value', 'sales_intrinsic_value', 'current_price'
    return pd.DataFrame(df, index=pd.Series(SYMBOL))

data = get_data(symbol=SYMBOL, api_key=EOD_API_KEY)
fair_values = get_financial_metrics_valuation(data)
print(fair_values)
</code>

The final output shows that the current price of Fiverr (FVRR) may be slightly undervalued according to the models, and the script can be reused for any stock by changing the ticker symbol.

At the end, the article includes a promotional section offering a free Python course and additional learning resources via QR codes.

pandasfinancial modelingeod apifair valuestock valuationyfinance
Python Programming Learning Circle
Written by

Python Programming Learning Circle

A global community of Chinese Python developers offering technical articles, columns, original video tutorials, and problem sets. Topics include web full‑stack development, web scraping, data analysis, natural language processing, image processing, machine learning, automated testing, DevOps automation, and big data.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.