Financial Ratios and Percentages: Tools for Analysis

30 minbeginner

6. Financial Ratios and Percentages: Tools for Analysis

Financial ratios and percentages are essential tools for analyzing companies, investments, and markets. They condense complex financial information into simple, comparable numbers that help investors, traders, and analysts make decisions. Understanding financial ratios is crucial for fundamental analysis and investment decision-making.

Return Measures

Returns measure how much you gain or lose on an investment. There are several ways to measure returns:

Simple Return (Holding Period Return): The percentage change in value over a period.

R=P1−P0P0=P1P0−1R = \frac{P_1 - P_0}{P_0} = \frac{P_1}{P_0} - 1

Where P_0 is the initial price and P_1 is the ending price.

Example: If you buy a stock at $100 and sell it at $110:

  • Return = ($110 - $100) / $100 = 10%

Practice Problem 6.1: Company Financial Analysis

Company XYZ has the following financial data:

  • Revenue: $10,000,000
  • Cost of Goods Sold: $6,000,000
  • Operating Expenses: $2,500,000
  • Interest Expense: $200,000
  • Taxes: $325,000
  • Net Income: $975,000
  • Total Assets: $15,000,000
  • Shareholders' Equity: $8,000,000
  • Current Assets: $4,000,000
  • Current Liabilities: $2,000,000
  • Inventory: $1,000,000
  • Stock Price: $50
  • Shares Outstanding: 1,000,000
  • Annual Dividends: $500,000

Calculate key profitability, efficiency, leverage, and liquidity ratios.

Solution:

Profitability Ratios:

Gross Margin:

  • Gross Profit = Revenue - COGS = $10,000,000 - $6,000,000 = $4,000,000
  • Gross Margin = $4,000,000 / $10,000,000 = 40%

Operating Margin:

  • Operating Income = Revenue - COGS - Operating Expenses = $10,000,000 - $6,000,000 - $2,500,000 = $1,500,000
  • Operating Margin = $1,500,000 / $10,000,000 = 15%

Net Margin:

  • Net Margin = $975,000 / $10,000,000 = 9.75%

ROA:

  • ROA = $975,000 / $15,000,000 = 6.5%

ROE:

  • ROE = $975,000 / $8,000,000 = 12.19%

Efficiency Ratios:

Asset Turnover:

  • Asset Turnover = $10,000,000 / $15,000,000 = 0.67

Leverage Ratios:

Debt-to-Equity:

  • Total Debt = Total Assets - Shareholders' Equity = $15,000,000 - $8,000,000 = $7,000,000
  • Debt/Equity = $7,000,000 / $8,000,000 = 0.875 or 87.5%

Interest Coverage:

  • EBIT = Operating Income = $1,500,000
  • Interest Coverage = $1,500,000 / $200,000 = 7.5 times

Liquidity Ratios:

Current Ratio:

  • Current Ratio = $4,000,000 / $2,000,000 = 2.0

Quick Ratio:

  • Quick Ratio = ($4,000,000 - $1,000,000) / $2,000,000 = 1.5

Market Ratios:

P/E Ratio:

  • Earnings Per Share = $975,000 / 1,000,000 = $0.975
  • P/E = $50 / $0.975 = 51.28

Dividend Yield:

  • Dividends Per Share = $500,000 / 1,000,000 = $0.50
  • Dividend Yield = $0.50 / $50 = 1%

Analysis:

  • Profitability: The company has healthy margins (40% gross, 15% operating, 9.75% net) and good returns (12.19% ROE)
  • Efficiency: Asset turnover of 0.67 suggests the company generates $0.67 of revenue per dollar of assets
  • Leverage: Debt-to-equity of 87.5% indicates moderate leverage, but interest coverage of 7.5x shows the company can comfortably service its debt
  • Liquidity: Current ratio of 2.0 and quick ratio of 1.5 indicate strong liquidity
  • Valuation: P/E of 51.28 is quite high, suggesting investors expect high growth. Dividend yield of 1% is low, typical for growth companies.

Python exercise

#| label: practice-6-1
#| fig-cap: "Practice Problem 6.1: Company Financial Analysis"
#| fig-width: 14
#| fig-height: 6
#| echo: false
#| warning: false

# Sandbox metadata (auto-generated from lesson.ts)
# libraries: numpy, matplotlib, pandas

import numpy as np
import matplotlib.pyplot as plt
from IPython.display import display

# Financial ratios
profitability_ratios = ['Gross\nMargin', 'Operating\nMargin', 'Net\nMargin', 'ROA', 'ROE']
profitability_values = [40, 15, 9.75, 6.5, 12.19]

other_ratios = ['Asset\nTurnover', 'Debt/\nEquity', 'Interest\nCoverage', 'Current\nRatio', 'Quick\nRatio']
other_values = [0.67, 87.5, 7.5, 2.0, 1.5]

fig, axes = plt.subplots(1, 2, figsize=(16, 6))
fig.suptitle('Practice Problem 6.1: Company Financial Analysis', fontsize=14, fontweight='bold')

# Plot 1: Profitability Ratios
ax1 = axes[0]
bars1 = ax1.bar(profitability_ratios, profitability_values, color=['green', 'blue', 'orange', 'purple', 'red'],
                alpha=0.7, edgecolor='black', linewidth=1.5)
ax1.set_ylabel('Percentage (%)', fontsize=11, fontweight='bold')
ax1.set_title('Profitability Ratios', fontsize=12, fontweight='bold')
ax1.grid(True, alpha=0.3, linestyle='--', axis='y')
for bar, val in zip(bars1, profitability_values):
    height = bar.get_height()
    ax1.text(bar.get_x() + bar.get_width()/2., height + 0.5,
             f'{val:.1f}%', ha='center', va='bottom', fontsize=9, fontweight='bold')

# Plot 2: Other Ratios (Mixed scales)
ax2 = axes[1]
# Normalize other ratios for visualization (scale debt/equity and interest coverage)
scaled_values = [other_values[0] * 100, other_values[1], other_values[2] * 10, other_values[3] * 10, other_values[4] * 10]
bars2 = ax2.bar(other_ratios, scaled_values, color=['blue', 'red', 'green', 'orange', 'purple'],
                alpha=0.7, edgecolor='black', linewidth=1.5)
ax2.set_ylabel('Ratio Value (Scaled for Comparison)', fontsize=11, fontweight='bold')
ax2.set_title('Efficiency, Leverage, and Liquidity Ratios', fontsize=12, fontweight='bold')
ax2.grid(True, alpha=0.3, linestyle='--', axis='y')
# Add actual values as labels
labels = ['0.67', '87.5%', '7.5x', '2.0', '1.5']
for bar, label in zip(bars2, labels):
    height = bar.get_height()
    ax2.text(bar.get_x() + bar.get_width()/2., height + 2,
             label, ha='center', va='bottom', fontsize=9, fontweight='bold')

plt.tight_layout()
display(fig)
plt.close(fig)

Real-World Context: This comprehensive ratio analysis is exactly what financial analysts do when evaluating companies. Each ratio tells part of the story - profitability, efficiency, financial health, and market valuation. By comparing these ratios to industry averages and historical trends, analysts can identify strengths, weaknesses, and investment opportunities.

Practice Problem 6.2: Investment Performance Comparison

You're comparing two investment options over a 5-year period:

Investment A:

  • Year 1: +15%
  • Year 2: +10%
  • Year 3: -5%
  • Year 4: +20%
  • Year 5: +8%

Investment B:

  • Year 1: +12%
  • Year 2: +12%
  • Year 3: +12%
  • Year 4: +12%
  • Year 5: +12%

Calculate the total return, annualized return, and standard deviation for each. Which investment performed better?

Solution:

Investment A:

Total Return (using compound growth):

  • Final Value = 1×1.15×1.10×0.95×1.20×1.08−FinalValue=1 × 1.15 × 1.10 × 0.95 × 1.20 × 1.08 - Final Value =1×1.487=$1.4871 × 1.487 = \text{\$}1.487=$1×(1.12)5=$1×1.7623=$1.7623= \text{\$}1 \times (1.12)^{5} = \text{\$}1 \times 1.7623 = \text{\$}1.7623
  • Total Return = 76.23%

Annualized Return (CAGR):

  • CAGR = 12% (already annualized)

Standard Deviation:

  • Since all returns are the same, standard deviation = 0%

Analysis:

  • Investment B has a higher total return (76.23% vs 48.7%) and higher annualized return (12% vs 8.27%)
  • Investment A has volatility (standard deviation of 8.39%) while Investment B has no volatility (0%)
  • Investment B is clearly superior in this case - higher returns with no risk

Python exercise

#| label: practice-6-2
#| fig-cap: "Practice Problem 6.2: Investment Performance Comparison"
#| fig-width: 14
#| fig-height: 6
#| echo: false
#| warning: false

# Sandbox metadata (auto-generated from lesson.ts)
# libraries: numpy, matplotlib, pandas

import numpy as np
import matplotlib.pyplot as plt
from IPython.display import display

# Investment A returns
returns_a = np.array([15, 10, -5, 20, 8])
years = np.arange(1, 6, 1)
cumulative_a = np.cumprod(1 + returns_a / 100)
total_return_a = (cumulative_a[-1] - 1) * 100
cagr_a = (cumulative_a[-1]**(1/5) - 1) * 100
std_a = np.std(returns_a)

# Investment B returns
returns_b = np.array([12, 12, 12, 12, 12])
cumulative_b = np.cumprod(1 + returns_b / 100)
total_return_b = (cumulative_b[-1] - 1) * 100
cagr_b = 12.0
std_b = 0.0

fig, axes = plt.subplots(1, 2, figsize=(16, 6))
fig.suptitle('Practice Problem 6.2: Investment Performance Comparison', fontsize=14, fontweight='bold')

# Plot 1: Cumulative Growth
ax1 = axes[0]
ax1.plot(years, cumulative_a, 'b-', linewidth=3, marker='o', markersize=8, label='Investment A', alpha=0.8)
ax1.plot(years, cumulative_b, 'g-', linewidth=3, marker='s', markersize=8, label='Investment B', alpha=0.8)
ax1.axhline(y=1, color='gray', linestyle=':', linewidth=1, alpha=0.5)
ax1.set_xlabel('Year', fontsize=11, fontweight='bold')
ax1.set_ylabel('Cumulative Value ($1 invested)', fontsize=11, fontweight='bold')
ax1.set_title('Cumulative Growth Over 5 Years', fontsize=12, fontweight='bold')
ax1.grid(True, alpha=0.3, linestyle='--')
ax1.legend(loc='upper left', fontsize=9)
ax1.plot(5, cumulative_a[-1], 'bo', markersize=12, zorder=5)
ax1.plot(5, cumulative_b[-1], 'go', markersize=12, zorder=5)
ax1.annotate(f'A: ${cumulative_a[-1]:.2f}\n({total_return_a:.1f}%)',
             xy=(5, cumulative_a[-1]), xytext=(4.5, cumulative_a[-1] + 0.1),
             fontsize=9, fontweight='bold', bbox=dict(boxstyle='round,pad=0.3', facecolor='lightblue', edgecolor='blue'))
ax1.annotate(f'B: ${cumulative_b[-1]:.2f}\n({total_return_b:.1f}%)',
             xy=(5, cumulative_b[-1]), xytext=(4.5, cumulative_b[-1] - 0.15),
             fontsize=9, fontweight='bold', bbox=dict(boxstyle='round,pad=0.3', facecolor='lightgreen', edgecolor='green'))

# Plot 2: Performance Metrics Comparison
ax2 = axes[1]
metrics = ['Total\nReturn', 'CAGR\n(Annualized)', 'Std Dev\n(Risk)']
investment_a_metrics = [total_return_a, cagr_a, std_a]
investment_b_metrics = [total_return_b, cagr_b, std_b]
x = np.arange(len(metrics))
width = 0.35
bars1 = ax2.bar(x - width/2, investment_a_metrics, width, label='Investment A', color='blue', alpha=0.7, edgecolor='black')
bars2 = ax2.bar(x + width/2, investment_b_metrics, width, label='Investment B', color='green', alpha=0.7, edgecolor='black')
ax2.set_ylabel('Percentage (%)', fontsize=11, fontweight='bold')
ax2.set_title('Performance Metrics Comparison', fontsize=12, fontweight='bold')
ax2.set_xticks(x)
ax2.set_xticklabels(metrics)
ax2.legend(loc='upper left', fontsize=9)
ax2.grid(True, alpha=0.3, linestyle='--', axis='y')
for bars in [bars1, bars2]:
    for bar in bars:
        height = bar.get_height()
        ax2.text(bar.get_x() + bar.get_width()/2., height + 1,
                 f'{height:.1f}%', ha='center', va='bottom', fontsize=9, fontweight='bold')
ax2.text(0.5, 0.95, 'Investment B is superior:\nHigher returns, no volatility',
         transform=ax2.transAxes, ha='center', va='top', fontsize=10, fontweight='bold',
         bbox=dict(boxstyle='round,pad=0.5', facecolor='yellow', edgecolor='black', linewidth=1.5))

plt.tight_layout()
display(fig)
plt.close(fig)

Real-World Context: This demonstrates why consistent returns are valuable. While Investment A had some high years (+20%, +15%), the negative year (-5%) and variability hurt overall performance. Investment B's consistent 12% returns, compounded over 5 years, produced significantly better results. This is why many investors prefer consistent, steady returns over volatile, high-return investments - the power of compounding works better with consistency.

Practice Problem 6.3: Stock Valuation Using P/E Ratio

You're analyzing two stocks in the same industry:

Stock X:

  • Current Price: $75
  • Earnings Per Share (EPS): $3.00
  • Expected EPS Growth: 15% per year

Stock Y:

  • Current Price: $60
  • Earnings Per Share (EPS): $2.50
  • Expected EPS Growth: 10% per year

Calculate P/E ratios and PEG ratios. Which stock appears to be a better value?

Solution:

Stock X:

P/E Ratio:

  • P/E = $75 / $3.00 = 25

PEG Ratio:

  • PEG = P/E / Growth Rate = 25 / 15 = 1.67

Stock Y:

P/E Ratio:

  • P/E = $60 / $2.50 = 24

PEG Ratio:

  • PEG = 24 / 10 = 2.40

Analysis:

  • Both stocks have similar P/E ratios (25 vs 24), suggesting similar valuation
  • However, Stock X has a lower PEG ratio (1.67 vs 2.40), suggesting better value when accounting for growth
  • A PEG ratio below 1.0 is considered undervalued, 1.0-2.0 is reasonable, and above 2.0 may be overvalued
  • Stock X appears to be better value because it has higher growth (15% vs 10%) at a similar P/E ratio

Python exercise

#| label: practice-6-3
#| fig-cap: "Practice Problem 6.3: Stock Valuation Using P/E Ratio"
#| fig-width: 14
#| fig-height: 6
#| echo: false
#| warning: false

# Sandbox metadata (auto-generated from lesson.ts)
# libraries: numpy, matplotlib, pandas

import numpy as np
import matplotlib.pyplot as plt
from IPython.display import display

# Stock parameters
price_x = 75
eps_x = 3.00
growth_x = 15
pe_x = price_x / eps_x
peg_x = pe_x / growth_x

price_y = 60
eps_y = 2.50
growth_y = 10
pe_y = price_y / eps_y
peg_y = pe_y / growth_y

# Future EPS projections (5 years)
years = np.arange(0, 6, 1)
eps_x_future = eps_x * ((1 + growth_x/100) ** years)
eps_y_future = eps_y * ((1 + growth_y/100) ** years)

fig, axes = plt.subplots(1, 2, figsize=(16, 6))
fig.suptitle('Practice Problem 6.3: Stock Valuation Using P/E Ratio', fontsize=14, fontweight='bold')

# Plot 1: P/E and PEG Comparison
ax1 = axes[0]
stocks = ['Stock X', 'Stock Y']
pe_ratios = [pe_x, pe_y]
peg_ratios = [peg_x, peg_y]
x = np.arange(len(stocks))
width = 0.35
bars1 = ax1.bar(x - width/2, pe_ratios, width, label='P/E Ratio', color='blue', alpha=0.7, edgecolor='black')
bars2 = ax1.bar(x + width/2, peg_ratios, width, label='PEG Ratio', color='green', alpha=0.7, edgecolor='black')
ax1.axhline(y=1.0, color='red', linestyle='--', linewidth=2, alpha=0.7, label='PEG = 1.0 (Undervalued)')
ax1.axhline(y=2.0, color='orange', linestyle=':', linewidth=2, alpha=0.7, label='PEG = 2.0 (Overvalued)')
ax1.set_ylabel('Ratio Value', fontsize=11, fontweight='bold')
ax1.set_title('Valuation Ratios Comparison', fontsize=12, fontweight='bold')
ax1.set_xticks(x)
ax1.set_xticklabels(stocks)
ax1.legend(loc='upper left', fontsize=9)
ax1.grid(True, alpha=0.3, linestyle='--', axis='y')
for bars in [bars1, bars2]:
    for bar in bars:
        height = bar.get_height()
        ax1.text(bar.get_x() + bar.get_width()/2., height + 0.5,
                 f'{height:.2f}', ha='center', va='bottom', fontsize=9, fontweight='bold')
ax1.text(0.5, 0.7, f'Stock X: Lower PEG\nBetter value',
         transform=ax1.transAxes, ha='center', fontsize=10, fontweight='bold',
         bbox=dict(boxstyle='round,pad=0.5', facecolor='yellow', edgecolor='black', linewidth=1.5))

# Plot 2: EPS Growth Projection
ax2 = axes[1]
ax2.plot(years, eps_x_future, 'b-', linewidth=3, marker='o', markersize=8, label=f'Stock X ({growth_x}% growth)', alpha=0.8)
ax2.plot(years, eps_y_future, 'g-', linewidth=3, marker='s', markersize=8, label=f'Stock Y ({growth_y}% growth)', alpha=0.8)
ax2.set_xlabel('Year', fontsize=11, fontweight='bold')
ax2.set_ylabel('Earnings Per Share ($)', fontsize=11, fontweight='bold')
ax2.set_title('Projected EPS Growth (5 Years)', fontsize=12, fontweight='bold')
ax2.grid(True, alpha=0.3, linestyle='--')
ax2.legend(loc='upper left', fontsize=9)
ax2.set_xticks(years)
# Add annotations
ax2.annotate(f'Year 5:\nX: ${eps_x_future[-1]:.2f}\nY: ${eps_y_future[-1]:.2f}',
             xy=(5, eps_x_future[-1]), xytext=(3.5, eps_x_future[-1] + 1),
             fontsize=9, fontweight='bold',
             bbox=dict(boxstyle='round,pad=0.5', facecolor='lightblue', edgecolor='blue', linewidth=2),
             arrowprops=dict(arrowstyle='->', color='blue', lw=1.5))

plt.tight_layout()
display(fig)
plt.close(fig)

Real-World Context: This is a common valuation comparison. The P/E ratio alone can be misleading - a stock with a high P/E might be fairly valued if it has high growth. The PEG ratio adjusts for growth, making it easier to compare stocks with different growth rates. Value investors often look for stocks with PEG ratios below 1.0, while growth investors may accept higher PEG ratios if they believe in the growth story.

Total Return: Includes both price appreciation and income (dividends, interest).

TotalReturn=P1−P0+IncomeP0Total Return = \frac{P_1 - P_0 + Income}{P_0}

Example: If you buy a stock at $100, it pays a $2 dividend, and you sell it at $110:

  • Total Return = ($110 - $100 + $2) / $100 = 12%

Python exercise

#| label: total-return-visualization
#| fig-cap: "Total Return: Price Appreciation and Income"
#| fig-width: 14
#| fig-height: 6
#| echo: false
#| warning: false

# Sandbox metadata (auto-generated from lesson.ts)
# libraries: numpy, matplotlib, pandas

import numpy as np
import matplotlib.pyplot as plt
from IPython.display import display

# Example investment
initial_price = 100
final_price = 110
dividend = 2
total_return = ((final_price - initial_price + dividend) / initial_price) * 100

# Breakdown
price_appreciation = ((final_price - initial_price) / initial_price) * 100
dividend_yield = (dividend / initial_price) * 100

fig, axes = plt.subplots(1, 2, figsize=(16, 6))
fig.suptitle('Total Return: Price Appreciation and Income', fontsize=14, fontweight='bold')

# Plot 1: Return Components
ax1 = axes[0]
components = ['Price\nAppreciation', 'Dividend\nIncome', 'Total\nReturn']
values = [price_appreciation, dividend_yield, total_return]
colors = ['blue', 'green', 'purple']
bars = ax1.bar(components, values, color=colors, alpha=0.7, edgecolor='black', linewidth=1.5)
ax1.set_ylabel('Return (%)', fontsize=11, fontweight='bold')
ax1.set_title('Total Return Breakdown', fontsize=12, fontweight='bold')
ax1.grid(True, alpha=0.3, linestyle='--', axis='y')
for bar, val in zip(bars, values):
    height = bar.get_height()
    ax1.text(bar.get_x() + bar.get_width()/2., height + 0.5,
             f'{val:.1f}%', ha='center', va='bottom', fontsize=10, fontweight='bold')

# Plot 2: Investment Timeline
ax2 = axes[1]
time_points = [0, 1]
values_timeline = [initial_price, final_price]
ax2.plot(time_points, values_timeline, 'b-', linewidth=3, marker='o', markersize=12, alpha=0.8, label='Stock Price')
ax2.barh([0.5], [dividend], left=1, height=0.3, color='green', alpha=0.7, edgecolor='black', label='Dividend')
ax2.set_xlabel('Time', fontsize=11, fontweight='bold')
ax2.set_ylabel('Value ($)', fontsize=11, fontweight='bold')
ax2.set_title('Investment Timeline: Price + Dividend', fontsize=12, fontweight='bold')
ax2.set_xticks([0, 1])
ax2.set_xticklabels(['Purchase\n($100)', 'Sale + Dividend\n($110 + $2)'])
ax2.grid(True, alpha=0.3, linestyle='--', axis='y')
ax2.legend(loc='upper left', fontsize=9)
ax2.text(0.5, 0.95, f'Total Return: {total_return:.1f}%\n= {price_appreciation:.1f}% (price) + {dividend_yield:.1f}% (dividend)',
         transform=ax2.transAxes, ha='center', va='top', fontsize=10, fontweight='bold',
         bbox=dict(boxstyle='round,pad=0.5', facecolor='yellow', edgecolor='black', linewidth=1.5))

plt.tight_layout()
display(fig)
plt.close(fig)

Annualized Return: Converts returns to an annual basis for comparison.

AnnualizedReturn=(1+R)1/n−1Annualized Return = (1 + R)^{1/n} - 1

Where n is the number of years.

Example: If you earn 20% over 2 years:

  • Annualized Return = (1.20)^(1/2) - 1 = 9.54% per year

Python exercise

#| label: annualized-return-visualization
#| fig-cap: "Annualized Return: Normalizing Returns Across Time Periods"
#| fig-width: 14
#| fig-height: 6
#| echo: false
#| warning: false

# Sandbox metadata (auto-generated from lesson.ts)
# libraries: numpy, matplotlib, pandas

import numpy as np
import matplotlib.pyplot as plt
from IPython.display import display

# Example: 20% over 2 years
total_return = 0.20
years = 2
annualized = (1 + total_return)**(1/years) - 1

# Comparison: different time periods
time_periods = [1, 2, 3, 5, 10]
total_returns = [0.10, 0.20, 0.30, 0.50, 1.00]
annualized_returns = [(1 + tr)**(1/tp) - 1 for tr, tp in zip(total_returns, time_periods)]

# Annualized return sensitivity
years_range = np.linspace(1, 10, 100)
total_return_fixed = 0.50
annualized_range = (1 + total_return_fixed)**(1/years_range) - 1

fig, axes = plt.subplots(1, 2, figsize=(16, 6))
fig.suptitle('Annualized Return: Normalizing Returns Across Time Periods', fontsize=14, fontweight='bold')

# Plot 1: Annualized Return Comparison
ax1 = axes[0]
bars = ax1.bar(range(len(time_periods)), [ar * 100 for ar in annualized_returns], 
               color=['green', 'blue', 'orange', 'red', 'purple'], alpha=0.7, edgecolor='black', linewidth=1.5)
ax1.set_ylabel('Annualized Return (%)', fontsize=11, fontweight='bold')
ax1.set_title('Annualized Returns: Same Total Return, Different Periods', fontsize=12, fontweight='bold')
ax1.set_xticks(range(len(time_periods)))
ax1.set_xticklabels([f'{tp}yr\n({tr*100:.0f}% total)' for tp, tr in zip(time_periods, total_returns)])
ax1.grid(True, alpha=0.3, linestyle='--', axis='y')
for bar, ar, tr, tp in zip(bars, annualized_returns, total_returns, time_periods):
    height = bar.get_height()
    ax1.text(bar.get_x() + bar.get_width()/2., height + 0.5,
             f'{ar*100:.1f}%', ha='center', va='bottom', fontsize=9, fontweight='bold')

# Plot 2: Annualized Return vs Time Period
ax2 = axes[1]
ax2.plot(years_range, annualized_range * 100, 'b-', linewidth=3, alpha=0.8, 
         label=f'Total Return: {total_return_fixed*100:.0f}%')
ax2.plot(years, annualized * 100, 'ro', markersize=12, markeredgewidth=2, 
         markeredgecolor='white', zorder=5, label=f'Example: {years}yr = {annualized*100:.2f}%')
ax2.set_xlabel('Number of Years', fontsize=11, fontweight='bold')
ax2.set_ylabel('Annualized Return (%)', fontsize=11, fontweight='bold')
ax2.set_title('Annualized Return: Impact of Time Period', fontsize=12, fontweight='bold')
ax2.grid(True, alpha=0.3, linestyle='--')
ax2.legend(loc='upper right', fontsize=9)
ax2.annotate('Longer periods → Lower annualized\n(for same total return)',
             xy=(5, annualized_range[49] * 100), xytext=(7, annualized_range[49] * 100 + 5),
             arrowprops=dict(arrowstyle='->', color='green', lw=2),
             fontsize=10, fontweight='bold',
             bbox=dict(boxstyle='round,pad=0.5', facecolor='lightgreen', edgecolor='green', linewidth=2))

plt.tight_layout()
display(fig)
plt.close(fig)

Compound Annual Growth Rate (CAGR): The annualized return that would produce the same ending value.

CAGR=(EndingValueBeginningValue)1/n−1CAGR = \left(\frac{Ending Value}{Beginning Value}\right)^{1/n} - 1

Python exercise

#| label: cagr-visualization
#| fig-cap: "CAGR: Compound Annual Growth Rate"
#| fig-width: 14
#| fig-height: 6
#| echo: false
#| warning: false

# Sandbox metadata (auto-generated from lesson.ts)
# libraries: numpy, matplotlib, pandas

import numpy as np
import matplotlib.pyplot as plt
from IPython.display import display

# Example investments
beginning_values = [1000, 1000, 1000, 1000]
ending_values = [2000, 3000, 5000, 10000]
years_list = [5, 10, 15, 20]
cagr_values = [((ev / bv)**(1/y) - 1) * 100 for ev, bv, y in zip(ending_values, beginning_values, years_list)]

# CAGR sensitivity
years_range = np.linspace(1, 30, 100)
ending_fixed = 5000
beginning_fixed = 1000
cagr_range = ((ending_fixed / beginning_fixed)**(1/years_range) - 1) * 100

fig, axes = plt.subplots(1, 2, figsize=(16, 6))
fig.suptitle('CAGR: Compound Annual Growth Rate', fontsize=14, fontweight='bold')

# Plot 1: CAGR Comparison
ax1 = axes[0]
colors = ['green', 'blue', 'orange', 'red']
bars = ax1.bar(range(len(cagr_values)), cagr_values, color=colors, alpha=0.7, edgecolor='black', linewidth=1.5)
ax1.set_ylabel('CAGR (%)', fontsize=11, fontweight='bold')
ax1.set_title('CAGR: Different Investment Scenarios', fontsize=12, fontweight='bold')
ax1.set_xticks(range(len(cagr_values)))
ax1.set_xticklabels([f'{y}yr\n${ev:,}' for y, ev in zip(years_list, ending_values)])
ax1.grid(True, alpha=0.3, linestyle='--', axis='y')
for bar, cagr, bv, ev, y in zip(bars, cagr_values, beginning_values, ending_values, years_list):
    height = bar.get_height()
    ax1.text(bar.get_x() + bar.get_width()/2., height + 0.5,
             f'{cagr:.1f}%\n${bv:,} → ${ev:,}',
             ha='center', va='bottom', fontsize=9, fontweight='bold')

# Plot 2: CAGR vs Time Period
ax2 = axes[1]
ax2.plot(years_range, cagr_range, 'b-', linewidth=3, alpha=0.8, 
         label=f'${beginning_fixed:,} → ${ending_fixed:,}')
ax2.set_xlabel('Number of Years', fontsize=11, fontweight='bold')
ax2.set_ylabel('CAGR (%)', fontsize=11, fontweight='bold')
ax2.set_title('CAGR: How Time Affects Growth Rate', fontsize=12, fontweight='bold')
ax2.grid(True, alpha=0.3, linestyle='--')
ax2.legend(loc='upper right', fontsize=9)
ax2.annotate('Same ending value:\nLonger time → Lower CAGR',
             xy=(15, cagr_range[49]), xytext=(20, cagr_range[49] + 5),
             arrowprops=dict(arrowstyle='->', color='green', lw=2),
             fontsize=10, fontweight='bold',
             bbox=dict(boxstyle='round,pad=0.5', facecolor='lightgreen', edgecolor='green', linewidth=2))

plt.tight_layout()
display(fig)
plt.close(fig)

Profitability Ratios

Profitability ratios measure a company's ability to generate profits:

Gross Profit Margin: Measures profitability after cost of goods sold.

GrossMargin=GrossProfitRevenue=Revenue−CostofGoodsSoldRevenueGross Margin = \frac{Gross Profit}{Revenue} = \frac{Revenue - Cost of Goods Sold}{Revenue}

Operating Profit Margin: Measures profitability after operating expenses.

OperatingMargin=OperatingIncomeRevenueOperating Margin = \frac{Operating Income}{Revenue}

Net Profit Margin: Measures profitability after all expenses.

NetMargin=NetIncomeRevenueNet Margin = \frac{Net Income}{Revenue}

Return on Assets (ROA): Measures how efficiently assets generate profits.

ROA=NetIncomeTotalAssetsROA = \frac{Net Income}{Total Assets}

Return on Equity (ROE): Measures how efficiently equity generates profits.

ROE=NetIncomeShareholders′EquityROE = \frac{Net Income}{Shareholders' Equity}

Python exercise

#| label: profitability-ratios-visualization
#| fig-cap: "Profitability Ratios: Comprehensive Profitability Analysis"
#| fig-width: 14
#| fig-height: 8
#| echo: false
#| warning: false

# Sandbox metadata (auto-generated from lesson.ts)
# libraries: numpy, matplotlib, pandas

import numpy as np
import matplotlib.pyplot as plt
from IPython.display import display

# Example company income statement breakdown
revenue = 10000
cogs = 6000
operating_expenses = 2500
interest = 200
taxes = 325
net_income = 975

gross_profit = revenue - cogs
operating_income = gross_profit - operating_expenses
gross_margin = (gross_profit / revenue) * 100
operating_margin = (operating_income / revenue) * 100
net_margin = (net_income / revenue) * 100

# For ROA and ROE
total_assets = 15000
equity = 8000
roa = (net_income / total_assets) * 100
roe = (net_income / equity) * 100

fig, axes = plt.subplots(2, 2, figsize=(16, 12))
fig.suptitle('Profitability Ratios: Comprehensive Profitability Analysis', fontsize=14, fontweight='bold')

# Plot 1: Income Statement Waterfall
ax1 = axes[0, 0]
categories = ['Revenue', 'COGS', 'Gross\nProfit', 'Operating\nExpenses', 'Operating\nIncome', 
              'Interest', 'Taxes', 'Net\nIncome']
values = [revenue, -cogs, gross_profit, -operating_expenses, operating_income, -interest, -taxes, net_income]
colors = ['green', 'red', 'blue', 'red', 'blue', 'red', 'red', 'purple']
bars = ax1.bar(categories, values, color=colors, alpha=0.7, edgecolor='black', linewidth=1.5)
ax1.set_ylabel('Amount ($)', fontsize=11, fontweight='bold')
ax1.set_title('Income Statement Breakdown', fontsize=12, fontweight='bold')
ax1.grid(True, alpha=0.3, linestyle='--', axis='y')
ax1.axhline(y=0, color='black', linestyle='-', linewidth=1)
for bar, val in zip(bars, values):
    height = bar.get_height()
    if abs(height) > 500:
        ax1.text(bar.get_x() + bar.get_width()/2., height + height*0.02 if height > 0 else height - height*0.02,
                 f'${val/1000:.1f}K', ha='center', va='bottom' if height > 0 else 'top', fontsize=8, fontweight='bold')

# Plot 2: Profitability Margins
ax2 = axes[0, 1]
margins = ['Gross\nMargin', 'Operating\nMargin', 'Net\nMargin']
margin_values = [gross_margin, operating_margin, net_margin]
colors_margins = ['green', 'blue', 'purple']
bars2 = ax2.bar(margins, margin_values, color=colors_margins, alpha=0.7, edgecolor='black', linewidth=1.5)
ax2.set_ylabel('Margin (%)', fontsize=11, fontweight='bold')
ax2.set_title('Profitability Margins', fontsize=12, fontweight='bold')
ax2.grid(True, alpha=0.3, linestyle='--', axis='y')
for bar, val in zip(bars2, margin_values):
    height = bar.get_height()
    ax2.text(bar.get_x() + bar.get_width()/2., height + 0.5,
             f'{val:.1f}%', ha='center', va='bottom', fontsize=10, fontweight='bold')

# Plot 3: Return Ratios
ax3 = axes[1, 0]
returns = ['ROA', 'ROE']
return_values = [roa, roe]
colors_returns = ['orange', 'red']
bars3 = ax3.bar(returns, return_values, color=colors_returns, alpha=0.7, edgecolor='black', linewidth=1.5)
ax3.set_ylabel('Return (%)', fontsize=11, fontweight='bold')
ax3.set_title('Return on Assets and Equity', fontsize=12, fontweight='bold')
ax3.grid(True, alpha=0.3, linestyle='--', axis='y')
for bar, val, label in zip(bars3, return_values, returns):
    height = bar.get_height()
    ax3.text(bar.get_x() + bar.get_width()/2., height + 0.3,
             f'{val:.2f}%', ha='center', va='bottom', fontsize=10, fontweight='bold')
    if label == 'ROA':
        ax3.text(bar.get_x() + bar.get_width()/2., height/2,
                 f'Assets: ${total_assets/1000:.0f}K', ha='center', va='center', fontsize=9, fontweight='bold', color='white')
    else:
        ax3.text(bar.get_x() + bar.get_width()/2., height/2,
                 f'Equity: ${equity/1000:.0f}K', ha='center', va='center', fontsize=9, fontweight='bold', color='white')

# Plot 4: Profitability Comparison
ax4 = axes[1, 1]
companies = ['Company A', 'Company B', 'Company C']
gross_margins = [40, 35, 45]
net_margins = [9.75, 8, 12]
roe_values = [12.19, 10, 15]
x = np.arange(len(companies))
width = 0.25
bars1_4 = ax4.bar(x - width, gross_margins, width, label='Gross Margin', color='green', alpha=0.7, edgecolor='black')
bars2_4 = ax4.bar(x, net_margins, width, label='Net Margin', color='blue', alpha=0.7, edgecolor='black')
bars3_4 = ax4.bar(x + width, roe_values, width, label='ROE', color='red', alpha=0.7, edgecolor='black')
ax4.set_ylabel('Percentage (%)', fontsize=11, fontweight='bold')
ax4.set_title('Profitability: Multi-Company Comparison', fontsize=12, fontweight='bold')
ax4.set_xticks(x)
ax4.set_xticklabels(companies)
ax4.legend(loc='upper left', fontsize=9)
ax4.grid(True, alpha=0.3, linestyle='--', axis='y')

plt.tight_layout()
display(fig)
plt.close(fig)

Return on Invested Capital (ROIC): Measures return on all capital invested.

ROIC=NetOperatingProfitAfterTaxInvestedCapitalROIC = \frac{Net Operating Profit After Tax}{Invested Capital}

Valuation Ratios

Valuation ratios help determine if a stock is fairly valued:

Price-to-Earnings (P/E) Ratio: Compares stock price to earnings per share.

P/E=StockPriceEarningsPerShareP/E = \frac{Stock Price}{Earnings Per Share}

A lower P/E might indicate a cheaper stock, but context matters (growth, industry, etc.).

Python exercise

#| label: pe-ratio-visualization
#| fig-cap: "P/E Ratio: Understanding Stock Valuation"
#| fig-width: 14
#| fig-height: 6
#| echo: false
#| warning: false

# Sandbox metadata (auto-generated from lesson.ts)
# libraries: numpy, matplotlib, pandas

import numpy as np
import matplotlib.pyplot as plt
from IPython.display import display

# Example stocks
stocks = ['Stock A', 'Stock B', 'Stock C', 'Stock D']
prices = [50, 75, 30, 100]
eps_values = [2.00, 3.00, 1.50, 5.00]
pe_ratios = [p / e for p, e in zip(prices, eps_values)]

# P/E sensitivity analysis
eps_range = np.linspace(0.5, 10, 100)
price_fixed = 50
pe_range = price_fixed / eps_range

fig, axes = plt.subplots(1, 2, figsize=(16, 6))
fig.suptitle('P/E Ratio: Understanding Stock Valuation', fontsize=14, fontweight='bold')

# Plot 1: P/E Comparison Across Stocks
ax1 = axes[0]
colors = ['green' if pe < 20 else 'orange' if pe < 30 else 'red' for pe in pe_ratios]
bars = ax1.bar(stocks, pe_ratios, color=colors, alpha=0.7, edgecolor='black', linewidth=1.5)
ax1.axhline(y=20, color='green', linestyle='--', linewidth=2, alpha=0.5, label='P/E = 20 (Typical)')
ax1.axhline(y=30, color='orange', linestyle=':', linewidth=2, alpha=0.5, label='P/E = 30 (High)')
ax1.set_ylabel('P/E Ratio', fontsize=11, fontweight='bold')
ax1.set_title('P/E Ratios: Different Stocks', fontsize=12, fontweight='bold')
ax1.grid(True, alpha=0.3, linestyle='--', axis='y')
ax1.legend(loc='upper right', fontsize=9)
for bar, pe, price, eps in zip(bars, pe_ratios, prices, eps_values):
    height = bar.get_height()
    ax1.text(bar.get_x() + bar.get_width()/2., height + 1,
             f'P/E: {pe:.1f}\nPrice: ${price}\nEPS: ${eps:.2f}',
             ha='center', va='bottom', fontsize=9, fontweight='bold')

# Plot 2: P/E Sensitivity to Earnings
ax2 = axes[1]
ax2.plot(eps_range, pe_range, 'b-', linewidth=3, alpha=0.8, label=f'Stock Price: ${price_fixed}')
ax2.axhline(y=25, color='red', linestyle='--', linewidth=2, alpha=0.7, label='P/E = 25')
ax2.axvline(x=2.0, color='red', linestyle='--', linewidth=2, alpha=0.7)
ax2.plot(2.0, 25, 'ro', markersize=12, markeredgewidth=2, markeredgecolor='white', zorder=5)
ax2.set_xlabel('Earnings Per Share ($)', fontsize=11, fontweight='bold')
ax2.set_ylabel('P/E Ratio', fontsize=11, fontweight='bold')
ax2.set_title('P/E Ratio: How Earnings Affect Valuation', fontsize=12, fontweight='bold')
ax2.grid(True, alpha=0.3, linestyle='--')
ax2.legend(loc='upper right', fontsize=9)
ax2.annotate('Higher EPS → Lower P/E\n(More valuable earnings)', 
             xy=(4, 12.5), xytext=(6, 30),
             arrowprops=dict(arrowstyle='->', color='green', lw=2),
             fontsize=10, fontweight='bold',
             bbox=dict(boxstyle='round,pad=0.5', facecolor='lightgreen', edgecolor='green', linewidth=2))

plt.tight_layout()
display(fig)
plt.close(fig)

Price-to-Book (P/B) Ratio: Compares stock price to book value per share.

P/B=StockPriceBookValuePerShareP/B = \frac{Stock Price}{Book Value Per Share}

Python exercise

#| label: pb-ratio-visualization
#| fig-cap: "P/B Ratio: Book Value Valuation"
#| fig-width: 14
#| fig-height: 6
#| echo: false
#| warning: false

# Sandbox metadata (auto-generated from lesson.ts)
# libraries: numpy, matplotlib, pandas

import numpy as np
import matplotlib.pyplot as plt
from IPython.display import display

# Example stocks
stocks = ['Undervalued', 'Fair Value', 'Growth Stock', 'Overvalued']
prices = [40, 50, 75, 60]
book_values = [50, 50, 30, 30]
pb_ratios = [p / bv for p, bv in zip(prices, book_values)]

# P/B sensitivity
book_range = np.linspace(20, 80, 100)
price_fixed = 50
pb_range = price_fixed / book_range

fig, axes = plt.subplots(1, 2, figsize=(16, 6))
fig.suptitle('P/B Ratio: Book Value Valuation', fontsize=14, fontweight='bold')

# Plot 1: P/B Ratio Comparison
ax1 = axes[0]
colors = ['green' if pb < 1.0 else 'orange' if pb < 2.0 else 'red' for pb in pb_ratios]
bars = ax1.bar(stocks, pb_ratios, color=colors, alpha=0.7, edgecolor='black', linewidth=1.5)
ax1.axhline(y=1.0, color='green', linestyle='--', linewidth=2, alpha=0.5, label='P/B = 1.0 (Book Value)')
ax1.axhline(y=2.0, color='orange', linestyle=':', linewidth=2, alpha=0.5, label='P/B = 2.0 (High)')
ax1.set_ylabel('P/B Ratio', fontsize=11, fontweight='bold')
ax1.set_title('P/B Ratios: Different Stocks', fontsize=12, fontweight='bold')
ax1.grid(True, alpha=0.3, linestyle='--', axis='y')
ax1.legend(loc='upper right', fontsize=9)
for bar, pb, price, bv in zip(bars, pb_ratios, prices, book_values):
    height = bar.get_height()
    ax1.text(bar.get_x() + bar.get_width()/2., height + 0.1,
             f'P/B: {pb:.2f}\nPrice: ${price}\nBook: ${bv}',
             ha='center', va='bottom', fontsize=9, fontweight='bold')

# Plot 2: P/B vs Book Value
ax2 = axes[1]
ax2.plot(book_range, pb_range, 'b-', linewidth=3, alpha=0.8, label=f'Stock Price: ${price_fixed}')
ax2.axhline(y=1.0, color='green', linestyle='--', linewidth=2, alpha=0.7, label='P/B = 1.0')
ax2.fill_between(book_range, 0, pb_range, where=(pb_range < 1.0), alpha=0.3, color='green', label='Undervalued (P/B < 1)')
ax2.fill_between(book_range, 0, pb_range, where=(pb_range > 2.0), alpha=0.3, color='red', label='Overvalued (P/B > 2)')
ax2.set_xlabel('Book Value Per Share ($)', fontsize=11, fontweight='bold')
ax2.set_ylabel('P/B Ratio', fontsize=11, fontweight='bold')
ax2.set_title('P/B Ratio: Book Value Impact', fontsize=12, fontweight='bold')
ax2.grid(True, alpha=0.3, linestyle='--')
ax2.legend(loc='upper right', fontsize=9)

plt.tight_layout()
display(fig)
plt.close(fig)

Price-to-Sales (P/S) Ratio: Compares stock price to revenue per share.

P/S=StockPriceSalesPerShareP/S = \frac{Stock Price}{Sales Per Share}

Python exercise

#| label: ps-ratio-visualization
#| fig-cap: "P/S Ratio: Revenue-Based Valuation"
#| fig-width: 14
#| fig-height: 6
#| echo: false
#| warning: false

# Sandbox metadata (auto-generated from lesson.ts)
# libraries: numpy, matplotlib, pandas

import numpy as np
import matplotlib.pyplot as plt
from IPython.display import display

# Example companies
companies = ['Tech Co', 'Retail Co', 'Manufacturing Co', 'Service Co']
prices = [100, 50, 30, 80]
revenue_per_share = [25, 10, 15, 40]
ps_ratios = [p / r for p, r in zip(prices, revenue_per_share)]

# P/S sensitivity
revenue_range = np.linspace(5, 50, 100)
price_fixed = 50
ps_range = price_fixed / revenue_range

fig, axes = plt.subplots(1, 2, figsize=(16, 6))
fig.suptitle('P/S Ratio: Revenue-Based Valuation', fontsize=14, fontweight='bold')

# Plot 1: P/S Comparison
ax1 = axes[0]
colors = ['green' if ps < 2 else 'orange' if ps < 4 else 'red' for ps in ps_ratios]
bars = ax1.bar(companies, ps_ratios, color=colors, alpha=0.7, edgecolor='black', linewidth=1.5)
ax1.axhline(y=2, color='green', linestyle='--', linewidth=2, alpha=0.5, label='P/S = 2 (Typical)')
ax1.axhline(y=4, color='orange', linestyle=':', linewidth=2, alpha=0.5, label='P/S = 4 (High)')
ax1.set_ylabel('P/S Ratio', fontsize=11, fontweight='bold')
ax1.set_title('P/S Ratios: Different Industries', fontsize=12, fontweight='bold')
ax1.grid(True, alpha=0.3, linestyle='--', axis='y')
ax1.legend(loc='upper right', fontsize=9)
for bar, ps, price, rev in zip(bars, ps_ratios, prices, revenue_per_share):
    height = bar.get_height()
    ax1.text(bar.get_x() + bar.get_width()/2., height + 0.2,
             f'P/S: {ps:.1f}\nPrice: ${price}\nRev/Share: ${rev}',
             ha='center', va='bottom', fontsize=9, fontweight='bold')

# Plot 2: P/S vs Revenue Relationship
ax2 = axes[1]
ax2.plot(revenue_range, ps_range, 'b-', linewidth=3, alpha=0.8, label=f'Stock Price: ${price_fixed}')
ax2.axhline(y=2.5, color='red', linestyle='--', linewidth=2, alpha=0.7, label='P/S = 2.5')
ax2.fill_between(revenue_range, 0, ps_range, where=(ps_range <= 2), alpha=0.3, color='green', label='Low P/S (Value)')
ax2.fill_between(revenue_range, 0, ps_range, where=(ps_range > 4), alpha=0.3, color='red', label='High P/S (Growth)')
ax2.set_xlabel('Revenue Per Share ($)', fontsize=11, fontweight='bold')
ax2.set_ylabel('P/S Ratio', fontsize=11, fontweight='bold')
ax2.set_title('P/S Ratio: Revenue Impact on Valuation', fontsize=12, fontweight='bold')
ax2.grid(True, alpha=0.3, linestyle='--')
ax2.legend(loc='upper right', fontsize=9)

plt.tight_layout()
display(fig)
plt.close(fig)

Enterprise Value to EBITDA (EV/EBITDA): Measures company value relative to earnings.

EV/EBITDA=EnterpriseValueEBITDAEV/EBITDA = \frac{Enterprise Value}{EBITDA}

Python exercise

#| label: ev-ebitda-visualization
#| fig-cap: "EV/EBITDA: Enterprise Valuation Metric"
#| fig-width: 14
#| fig-height: 6
#| echo: false
#| warning: false

# Sandbox metadata (auto-generated from lesson.ts)
# libraries: numpy, matplotlib, pandas

import numpy as np
import matplotlib.pyplot as plt
from IPython.display import display

# Example companies
companies = ['Company A', 'Company B', 'Company C']
market_cap = [1000, 500, 1500]
debt = [200, 100, 300]
cash = [50, 25, 75]
enterprise_value = [m + d - c for m, d, c in zip(market_cap, debt, cash)]
ebitda = [150, 80, 250]
ev_ebitda = [ev / e for ev, e in zip(enterprise_value, ebitda)]

# EV/EBITDA sensitivity
ebitda_range = np.linspace(50, 300, 100)
ev_fixed = 1000
ev_ebitda_range = ev_fixed / ebitda_range

fig, axes = plt.subplots(1, 2, figsize=(16, 6))
fig.suptitle('EV/EBITDA: Enterprise Valuation Metric', fontsize=14, fontweight='bold')

# Plot 1: EV/EBITDA Comparison
ax1 = axes[0]
colors = ['green' if ev < 8 else 'orange' if ev < 12 else 'red' for ev in ev_ebitda]
bars = ax1.bar(companies, ev_ebitda, color=colors, alpha=0.7, edgecolor='black', linewidth=1.5)
ax1.axhline(y=8, color='green', linestyle='--', linewidth=2, alpha=0.5, label='EV/EBITDA = 8 (Typical)')
ax1.axhline(y=12, color='orange', linestyle=':', linewidth=2, alpha=0.5, label='EV/EBITDA = 12 (High)')
ax1.set_ylabel('EV/EBITDA Ratio', fontsize=11, fontweight='bold')
ax1.set_title('EV/EBITDA: Enterprise Value Comparison', fontsize=12, fontweight='bold')
ax1.grid(True, alpha=0.3, linestyle='--', axis='y')
ax1.legend(loc='upper right', fontsize=9)
for bar, ratio, ev, e in zip(bars, ev_ebitda, enterprise_value, ebitda):
    height = bar.get_height()
    ax1.text(bar.get_x() + bar.get_width()/2., height + 0.3,
             f'EV/EBITDA: {ratio:.1f}\nEV: ${ev}M\nEBITDA: ${e}M',
             ha='center', va='bottom', fontsize=9, fontweight='bold')

# Plot 2: EV/EBITDA vs EBITDA
ax2 = axes[1]
ax2.plot(ebitda_range, ev_ebitda_range, 'b-', linewidth=3, alpha=0.8, label=f'Enterprise Value: ${ev_fixed}M')
ax2.axhline(y=10, color='red', linestyle='--', linewidth=2, alpha=0.7, label='EV/EBITDA = 10')
ax2.fill_between(ebitda_range, 0, ev_ebitda_range, where=(ev_ebitda_range <= 8), alpha=0.3, color='green', label='Low (Value)')
ax2.fill_between(ebitda_range, 0, ev_ebitda_range, where=(ev_ebitda_range > 12), alpha=0.3, color='red', label='High (Expensive)')
ax2.set_xlabel('EBITDA ($ Millions)', fontsize=11, fontweight='bold')
ax2.set_ylabel('EV/EBITDA Ratio', fontsize=11, fontweight='bold')
ax2.set_title('EV/EBITDA: How EBITDA Affects Valuation', fontsize=12, fontweight='bold')
ax2.grid(True, alpha=0.3, linestyle='--')
ax2.legend(loc='upper right', fontsize=9)

plt.tight_layout()
display(fig)
plt.close(fig)

Efficiency Ratios

Efficiency ratios measure how efficiently a company uses its assets:

Asset Turnover: Measures how efficiently assets generate revenue.

AssetTurnover=RevenueTotalAssetsAsset Turnover = \frac{Revenue}{Total Assets}

Python exercise

#| label: asset-turnover-visualization
#| fig-cap: "Asset Turnover: Efficiency in Asset Utilization"
#| fig-width: 14
#| fig-height: 6
#| echo: false
#| warning: false

# Sandbox metadata (auto-generated from lesson.ts)
# libraries: numpy, matplotlib, pandas

import numpy as np
import matplotlib.pyplot as plt
from IPython.display import display

# Example companies
companies = ['Retail Co', 'Tech Co', 'Manufacturing Co', 'Bank Co']
revenues = [1000, 500, 800, 600]
assets = [800, 2000, 1200, 5000]
asset_turnover = [r / a for r, a in zip(revenues, assets)]

# Asset turnover over time (example)
years = np.arange(1, 6, 1)
revenue_growth = 1000 * (1.05 ** years)
assets_growth = 800 * (1.03 ** years)
turnover_trend = revenue_growth / assets_growth

fig, axes = plt.subplots(1, 2, figsize=(16, 6))
fig.suptitle('Asset Turnover: Efficiency in Asset Utilization', fontsize=14, fontweight='bold')

# Plot 1: Asset Turnover Comparison
ax1 = axes[0]
colors = ['green' if at > 1.0 else 'orange' if at > 0.5 else 'red' for at in asset_turnover]
bars = ax1.bar(companies, asset_turnover, color=colors, alpha=0.7, edgecolor='black', linewidth=1.5)
ax1.axhline(y=1.0, color='green', linestyle='--', linewidth=2, alpha=0.5, label='Turnover = 1.0 (Good)')
ax1.axhline(y=0.5, color='orange', linestyle=':', linewidth=2, alpha=0.5, label='Turnover = 0.5 (Low)')
ax1.set_ylabel('Asset Turnover Ratio', fontsize=11, fontweight='bold')
ax1.set_title('Asset Turnover: Industry Comparison', fontsize=12, fontweight='bold')
ax1.grid(True, alpha=0.3, linestyle='--', axis='y')
ax1.legend(loc='upper right', fontsize=9)
for bar, at, rev, ast in zip(bars, asset_turnover, revenues, assets):
    height = bar.get_height()
    ax1.text(bar.get_x() + bar.get_width()/2., height + 0.05,
             f'{at:.2f}x\nRev: ${rev}M\nAssets: ${ast}M',
             ha='center', va='bottom', fontsize=9, fontweight='bold')

# Plot 2: Asset Turnover Trend
ax2 = axes[1]
ax2.plot(years, turnover_trend, 'b-', linewidth=3, marker='o', markersize=8, alpha=0.8, label='Asset Turnover')
ax2.axhline(y=1.0, color='green', linestyle='--', linewidth=2, alpha=0.5, label='Turnover = 1.0')
ax2.fill_between(years, 1.0, turnover_trend, where=(turnover_trend >= 1.0), alpha=0.3, color='green', label='Above 1.0')
ax2.set_xlabel('Year', fontsize=11, fontweight='bold')
ax2.set_ylabel('Asset Turnover Ratio', fontsize=11, fontweight='bold')
ax2.set_title('Asset Turnover: Improving Efficiency Over Time', fontsize=12, fontweight='bold')
ax2.grid(True, alpha=0.3, linestyle='--')
ax2.legend(loc='upper left', fontsize=9)
ax2.set_xticks(years)

plt.tight_layout()
display(fig)
plt.close(fig)

Inventory Turnover: Measures how quickly inventory is sold.

InventoryTurnover=CostofGoodsSoldAverageInventoryInventory Turnover = \frac{Cost of Goods Sold}{Average Inventory}

Python exercise

#| label: inventory-turnover-visualization
#| fig-cap: "Inventory Turnover: Supply Chain Efficiency"
#| fig-width: 14
#| fig-height: 6
#| echo: false
#| warning: false

# Sandbox metadata (auto-generated from lesson.ts)
# libraries: numpy, matplotlib, pandas

import numpy as np
import matplotlib.pyplot as plt
from IPython.display import display

# Example companies
companies = ['Fast Retail', 'Slow Retail', 'Manufacturing', 'Tech Products']
cogs = [800, 400, 600, 200]
inventory = [100, 200, 150, 50]
inventory_turnover = [c / i for c, i in zip(cogs, inventory)]
days_inventory = [365 / it for it in inventory_turnover]

fig, axes = plt.subplots(1, 2, figsize=(16, 6))
fig.suptitle('Inventory Turnover: Supply Chain Efficiency', fontsize=14, fontweight='bold')

# Plot 1: Inventory Turnover Comparison
ax1 = axes[0]
colors = ['green' if it > 6 else 'orange' if it > 3 else 'red' for it in inventory_turnover]
bars = ax1.bar(companies, inventory_turnover, color=colors, alpha=0.7, edgecolor='black', linewidth=1.5)
ax1.axhline(y=6, color='green', linestyle='--', linewidth=2, alpha=0.5, label='Turnover = 6 (Good)')
ax1.axhline(y=3, color='orange', linestyle=':', linewidth=2, alpha=0.5, label='Turnover = 3 (Low)')
ax1.set_ylabel('Inventory Turnover (times per year)', fontsize=11, fontweight='bold')
ax1.set_title('Inventory Turnover: Industry Comparison', fontsize=12, fontweight='bold')
ax1.grid(True, alpha=0.3, linestyle='--', axis='y')
ax1.legend(loc='upper right', fontsize=9)
for bar, it, cogs_val, inv in zip(bars, inventory_turnover, cogs, inventory):
    height = bar.get_height()
    ax1.text(bar.get_x() + bar.get_width()/2., height + 0.3,
             f'{it:.1f}x\nCOGS: ${cogs_val}M\nInv: ${inv}M',
             ha='center', va='bottom', fontsize=9, fontweight='bold')

# Plot 2: Days of Inventory
ax2 = axes[1]
bars2 = ax2.bar(companies, days_inventory, color=['green', 'red', 'orange', 'blue'], 
                alpha=0.7, edgecolor='black', linewidth=1.5)
ax2.axhline(y=60, color='green', linestyle='--', linewidth=2, alpha=0.5, label='60 days (Good)')
ax2.axhline(y=120, color='orange', linestyle=':', linewidth=2, alpha=0.5, label='120 days (High)')
ax2.set_ylabel('Days of Inventory', fontsize=11, fontweight='bold')
ax2.set_title('Days of Inventory on Hand', fontsize=12, fontweight='bold')
ax2.grid(True, alpha=0.3, linestyle='--', axis='y')
ax2.legend(loc='upper right', fontsize=9)
for bar, days in zip(bars2, days_inventory):
    height = bar.get_height()
    ax2.text(bar.get_x() + bar.get_width()/2., height + 5,
             f'{days:.0f} days', ha='center', va='bottom', fontsize=9, fontweight='bold')

plt.tight_layout()
display(fig)
plt.close(fig)

Receivables Turnover: Measures how quickly receivables are collected.

ReceivablesTurnover=RevenueAverageAccountsReceivableReceivables Turnover = \frac{Revenue}{Average Accounts Receivable}

Python exercise

#| label: receivables-turnover-visualization
#| fig-cap: "Receivables Turnover: Collection Efficiency"
#| fig-width: 14
#| fig-height: 6
#| echo: false
#| warning: false

# Sandbox metadata (auto-generated from lesson.ts)
# libraries: numpy, matplotlib, pandas

import numpy as np
import matplotlib.pyplot as plt
from IPython.display import display

# Example companies
companies = ['Company A', 'Company B', 'Company C', 'Company D']
revenues = [1000, 800, 600, 1200]
receivables = [100, 200, 150, 120]
receivables_turnover = [r / rec for r, rec in zip(revenues, receivables)]
days_receivables = [365 / rt for rt in receivables_turnover]

fig, axes = plt.subplots(1, 2, figsize=(16, 6))
fig.suptitle('Receivables Turnover: Collection Efficiency', fontsize=14, fontweight='bold')

# Plot 1: Receivables Turnover
ax1 = axes[0]
colors = ['green' if rt > 8 else 'orange' if rt > 5 else 'red' for rt in receivables_turnover]
bars = ax1.bar(companies, receivables_turnover, color=colors, alpha=0.7, edgecolor='black', linewidth=1.5)
ax1.axhline(y=8, color='green', linestyle='--', linewidth=2, alpha=0.5, label='Turnover = 8 (Good)')
ax1.axhline(y=5, color='orange', linestyle=':', linewidth=2, alpha=0.5, label='Turnover = 5 (Low)')
ax1.set_ylabel('Receivables Turnover (times per year)', fontsize=11, fontweight='bold')
ax1.set_title('Receivables Turnover: Collection Speed', fontsize=12, fontweight='bold')
ax1.grid(True, alpha=0.3, linestyle='--', axis='y')
ax1.legend(loc='upper right', fontsize=9)
for bar, rt, rev, rec in zip(bars, receivables_turnover, revenues, receivables):
    height = bar.get_height()
    ax1.text(bar.get_x() + bar.get_width()/2., height + 0.5,
             f'{rt:.1f}x\nRev: ${rev}M\nAR: ${rec}M',
             ha='center', va='bottom', fontsize=9, fontweight='bold')

# Plot 2: Days Sales Outstanding (DSO)
ax2 = axes[1]
bars2 = ax2.bar(companies, days_receivables, color=['green', 'orange', 'red', 'green'], 
                alpha=0.7, edgecolor='black', linewidth=1.5)
ax2.axhline(y=45, color='green', linestyle='--', linewidth=2, alpha=0.5, label='45 days (Good)')
ax2.axhline(y=60, color='orange', linestyle=':', linewidth=2, alpha=0.5, label='60 days (Slow)')
ax2.set_ylabel('Days Sales Outstanding (DSO)', fontsize=11, fontweight='bold')
ax2.set_title('Days Sales Outstanding: Collection Period', fontsize=12, fontweight='bold')
ax2.grid(True, alpha=0.3, linestyle='--', axis='y')
ax2.legend(loc='upper right', fontsize=9)
for bar, days in zip(bars2, days_receivables):
    height = bar.get_height()
    ax2.text(bar.get_x() + bar.get_width()/2., height + 2,
             f'{days:.0f} days', ha='center', va='bottom', fontsize=9, fontweight='bold')

plt.tight_layout()
display(fig)
plt.close(fig)

Leverage Ratios

Leverage ratios measure a company's use of debt:

Debt-to-Equity Ratio: Measures the proportion of debt to equity.

Debt/Equity=TotalDebtShareholders′EquityDebt/Equity = \frac{Total Debt}{Shareholders' Equity}

Python exercise

#| label: debt-equity-visualization
#| fig-cap: "Debt-to-Equity Ratio: Financial Leverage Analysis"
#| fig-width: 14
#| fig-height: 6
#| echo: false
#| warning: false

# Sandbox metadata (auto-generated from lesson.ts)
# libraries: numpy, matplotlib, pandas

import numpy as np
import matplotlib.pyplot as plt
from IPython.display import display

# Example companies
companies = ['Conservative', 'Moderate', 'Aggressive', 'Highly Leveraged']
debt = [200, 500, 800, 1500]
equity = [800, 500, 400, 300]
debt_equity = [d / e for d, e in zip(debt, equity)]
total_capital = [d + e for d, e in zip(debt, equity)]

fig, axes = plt.subplots(1, 2, figsize=(16, 6))
fig.suptitle('Debt-to-Equity Ratio: Financial Leverage Analysis', fontsize=14, fontweight='bold')

# Plot 1: Debt-to-Equity Comparison
ax1 = axes[0]
colors = ['green' if de < 0.5 else 'orange' if de < 1.0 else 'red' for de in debt_equity]
bars = ax1.bar(companies, debt_equity, color=colors, alpha=0.7, edgecolor='black', linewidth=1.5)
ax1.axhline(y=0.5, color='green', linestyle='--', linewidth=2, alpha=0.5, label='D/E = 0.5 (Conservative)')
ax1.axhline(y=1.0, color='orange', linestyle=':', linewidth=2, alpha=0.5, label='D/E = 1.0 (Moderate)')
ax1.set_ylabel('Debt-to-Equity Ratio', fontsize=11, fontweight='bold')
ax1.set_title('Debt-to-Equity: Leverage Comparison', fontsize=12, fontweight='bold')
ax1.grid(True, alpha=0.3, linestyle='--', axis='y')
ax1.legend(loc='upper left', fontsize=9)
for bar, de, d, e in zip(bars, debt_equity, debt, equity):
    height = bar.get_height()
    ax1.text(bar.get_x() + bar.get_width()/2., height + 0.1,
             f'{de:.2f}\nDebt: ${d}M\nEquity: ${e}M',
             ha='center', va='bottom', fontsize=9, fontweight='bold')

# Plot 2: Capital Structure Breakdown
ax2 = axes[1]
x = np.arange(len(companies))
width = 0.6
bars1 = ax2.bar(x, debt, width, label='Debt', color='red', alpha=0.7, edgecolor='black')
bars2 = ax2.bar(x, equity, width, bottom=debt, label='Equity', color='green', alpha=0.7, edgecolor='black')
ax2.set_ylabel('Amount ($ Millions)', fontsize=11, fontweight='bold')
ax2.set_title('Capital Structure: Debt vs Equity', fontsize=12, fontweight='bold')
ax2.set_xticks(x)
ax2.set_xticklabels(companies)
ax2.legend(loc='upper left', fontsize=9)
ax2.grid(True, alpha=0.3, linestyle='--', axis='y')
for i, (d, e, de) in enumerate(zip(debt, equity, debt_equity)):
    ax2.text(i, d + e + 50, f'D/E: {de:.2f}', ha='center', va='bottom', 
             fontsize=9, fontweight='bold')

plt.tight_layout()
display(fig)
plt.close(fig)

Debt-to-Assets Ratio: Measures the proportion of assets financed by debt.

Debt/Assets=TotalDebtTotalAssetsDebt/Assets = \frac{Total Debt}{Total Assets}

Python exercise

#| label: debt-assets-visualization
#| fig-cap: "Debt-to-Assets Ratio: Asset Financing Structure"
#| fig-width: 14
#| fig-height: 6
#| echo: false
#| warning: false

# Sandbox metadata (auto-generated from lesson.ts)
# libraries: numpy, matplotlib, pandas

import numpy as np
import matplotlib.pyplot as plt
from IPython.display import display

# Example companies
companies = ['Low Debt', 'Moderate', 'High Debt', 'Very High']
debt = [200, 500, 800, 1200]
assets = [1000, 1000, 1000, 1000]
debt_assets = [d / a for d, a in zip(debt, assets)]
equity = [a - d for a, d in zip(assets, debt)]

fig, axes = plt.subplots(1, 2, figsize=(16, 6))
fig.suptitle('Debt-to-Assets Ratio: Asset Financing Structure', fontsize=14, fontweight='bold')

# Plot 1: Debt-to-Assets Comparison
ax1 = axes[0]
colors = ['green' if da < 0.3 else 'orange' if da < 0.6 else 'red' for da in debt_assets]
bars = ax1.bar(companies, debt_assets, color=colors, alpha=0.7, edgecolor='black', linewidth=1.5)
ax1.axhline(y=0.3, color='green', linestyle='--', linewidth=2, alpha=0.5, label='D/A = 30% (Low)')
ax1.axhline(y=0.6, color='orange', linestyle=':', linewidth=2, alpha=0.5, label='D/A = 60% (High)')
ax1.set_ylabel('Debt-to-Assets Ratio', fontsize=11, fontweight='bold')
ax1.set_title('Debt-to-Assets: Financing Structure', fontsize=12, fontweight='bold')
ax1.grid(True, alpha=0.3, linestyle='--', axis='y')
ax1.legend(loc='upper left', fontsize=9)
for bar, da, d, a in zip(bars, debt_assets, debt, assets):
    height = bar.get_height()
    ax1.text(bar.get_x() + bar.get_width()/2., height + 0.02,
             f'{da*100:.0f}%\nDebt: ${d}M\nAssets: ${a}M',
             ha='center', va='bottom', fontsize=9, fontweight='bold')

# Plot 2: Asset Financing Breakdown
ax2 = axes[1]
x = np.arange(len(companies))
width = 0.6
bars1 = ax2.bar(x, debt, width, label='Debt', color='red', alpha=0.7, edgecolor='black')
bars2 = ax2.bar(x, equity, width, bottom=debt, label='Equity', color='green', alpha=0.7, edgecolor='black')
ax2.set_ylabel('Amount ($ Millions)', fontsize=11, fontweight='bold')
ax2.set_title('Asset Financing: Debt vs Equity', fontsize=12, fontweight='bold')
ax2.set_xticks(x)
ax2.set_xticklabels(companies)
ax2.legend(loc='upper left', fontsize=9)
ax2.grid(True, alpha=0.3, linestyle='--', axis='y')
for i, (d, e, da) in enumerate(zip(debt, equity, debt_assets)):
    ax2.text(i, d + e + 30, f'{da*100:.0f}% Debt', ha='center', va='bottom', 
             fontsize=9, fontweight='bold')

plt.tight_layout()
display(fig)
plt.close(fig)

Interest Coverage Ratio: Measures ability to pay interest expenses.

InterestCoverage=EBITInterestExpenseInterest Coverage = \frac{EBIT}{Interest Expense}

Python exercise

#| label: interest-coverage-visualization
#| fig-cap: "Interest Coverage Ratio: Debt Servicing Capacity"
#| fig-width: 14
#| fig-height: 6
#| echo: false
#| warning: false

# Sandbox metadata (auto-generated from lesson.ts)
# libraries: numpy, matplotlib, pandas

import numpy as np
import matplotlib.pyplot as plt
from IPython.display import display

# Example companies
companies = ['Strong Co', 'Moderate Co', 'Weak Co', 'At Risk']
ebit = [500, 200, 150, 80]
interest_expense = [50, 50, 75, 60]
interest_coverage = [e / i for e, i in zip(ebit, interest_expense)]

# Coverage over time scenario
years = np.arange(1, 6, 1)
ebit_growth = 200 * (1.08 ** years)
interest_fixed = 50
coverage_trend = ebit_growth / interest_fixed

fig, axes = plt.subplots(1, 2, figsize=(16, 6))
fig.suptitle('Interest Coverage Ratio: Debt Servicing Capacity', fontsize=14, fontweight='bold')

# Plot 1: Interest Coverage Comparison
ax1 = axes[0]
colors = ['green' if ic > 5 else 'orange' if ic > 2 else 'red' for ic in interest_coverage]
bars = ax1.bar(companies, interest_coverage, color=colors, alpha=0.7, edgecolor='black', linewidth=1.5)
ax1.axhline(y=5, color='green', linestyle='--', linewidth=2, alpha=0.5, label='Coverage = 5x (Strong)')
ax1.axhline(y=2, color='orange', linestyle=':', linewidth=2, alpha=0.5, label='Coverage = 2x (Minimum)')
ax1.axhline(y=1, color='red', linestyle='-', linewidth=2, alpha=0.7, label='Coverage = 1x (Danger)')
ax1.set_ylabel('Interest Coverage (times)', fontsize=11, fontweight='bold')
ax1.set_title('Interest Coverage: Debt Servicing Ability', fontsize=12, fontweight='bold')
ax1.grid(True, alpha=0.3, linestyle='--', axis='y')
ax1.legend(loc='upper right', fontsize=9)
for bar, ic, e, i in zip(bars, interest_coverage, ebit, interest_expense):
    height = bar.get_height()
    ax1.text(bar.get_x() + bar.get_width()/2., height + 0.3,
             f'{ic:.1f}x\nEBIT: ${e}M\nInterest: ${i}M',
             ha='center', va='bottom', fontsize=9, fontweight='bold')

# Plot 2: Interest Coverage Trend
ax2 = axes[1]
ax2.plot(years, coverage_trend, 'b-', linewidth=3, marker='o', markersize=8, alpha=0.8, label='Interest Coverage')
ax2.axhline(y=5, color='green', linestyle='--', linewidth=2, alpha=0.5, label='5x (Strong)')
ax2.axhline(y=2, color='orange', linestyle=':', linewidth=2, alpha=0.5, label='2x (Minimum)')
ax2.fill_between(years, 5, coverage_trend, where=(coverage_trend >= 5), alpha=0.3, color='green', label='Strong Zone')
ax2.fill_between(years, 2, 5, where=(coverage_trend >= 2) & (coverage_trend < 5), alpha=0.3, color='orange', label='Moderate Zone')
ax2.set_xlabel('Year', fontsize=11, fontweight='bold')
ax2.set_ylabel('Interest Coverage (times)', fontsize=11, fontweight='bold')
ax2.set_title('Interest Coverage: Improving Over Time', fontsize=12, fontweight='bold')
ax2.grid(True, alpha=0.3, linestyle='--')
ax2.legend(loc='upper left', fontsize=9)
ax2.set_xticks(years)

plt.tight_layout()
display(fig)
plt.close(fig)

Liquidity Ratios

Liquidity ratios measure a company's ability to meet short-term obligations:

Current Ratio: Measures short-term liquidity.

CurrentRatio=CurrentAssetsCurrentLiabilitiesCurrent Ratio = \frac{Current Assets}{Current Liabilities}

Python exercise

#| label: current-ratio-visualization
#| fig-cap: "Current Ratio: Short-Term Liquidity Analysis"
#| fig-width: 14
#| fig-height: 6
#| echo: false
#| warning: false

# Sandbox metadata (auto-generated from lesson.ts)
# libraries: numpy, matplotlib, pandas

import numpy as np
import matplotlib.pyplot as plt
from IPython.display import display

# Example companies
companies = ['Strong', 'Adequate', 'Tight', 'Weak']
current_assets = [800, 500, 300, 150]
current_liabilities = [200, 250, 250, 200]
current_ratio = [ca / cl for ca, cl in zip(current_assets, current_liabilities)]

# Current ratio over time
years = np.arange(1, 6, 1)
ca_growth = 400 * (1.06 ** years)
cl_growth = 200 * (1.04 ** years)
ratio_trend = ca_growth / cl_growth

fig, axes = plt.subplots(1, 2, figsize=(16, 6))
fig.suptitle('Current Ratio: Short-Term Liquidity Analysis', fontsize=14, fontweight='bold')

# Plot 1: Current Ratio Comparison
ax1 = axes[0]
colors = ['green' if cr > 2.0 else 'orange' if cr > 1.0 else 'red' for cr in current_ratio]
bars = ax1.bar(companies, current_ratio, color=colors, alpha=0.7, edgecolor='black', linewidth=1.5)
ax1.axhline(y=2.0, color='green', linestyle='--', linewidth=2, alpha=0.5, label='Ratio = 2.0 (Strong)')
ax1.axhline(y=1.0, color='red', linestyle='-', linewidth=2, alpha=0.7, label='Ratio = 1.0 (Minimum)')
ax1.set_ylabel('Current Ratio', fontsize=11, fontweight='bold')
ax1.set_title('Current Ratio: Liquidity Comparison', fontsize=12, fontweight='bold')
ax1.grid(True, alpha=0.3, linestyle='--', axis='y')
ax1.legend(loc='upper right', fontsize=9)
for bar, cr, ca, cl in zip(bars, current_ratio, current_assets, current_liabilities):
    height = bar.get_height()
    ax1.text(bar.get_x() + bar.get_width()/2., height + 0.1,
             f'{cr:.2f}\nCA: ${ca}M\nCL: ${cl}M',
             ha='center', va='bottom', fontsize=9, fontweight='bold')

# Plot 2: Current Ratio Trend
ax2 = axes[1]
ax2.plot(years, ratio_trend, 'b-', linewidth=3, marker='o', markersize=8, alpha=0.8, label='Current Ratio')
ax2.axhline(y=2.0, color='green', linestyle='--', linewidth=2, alpha=0.5, label='2.0 (Strong)')
ax2.axhline(y=1.0, color='red', linestyle='-', linewidth=2, alpha=0.7, label='1.0 (Minimum)')
ax2.fill_between(years, 2.0, ratio_trend, where=(ratio_trend >= 2.0), alpha=0.3, color='green', label='Strong Zone')
ax2.fill_between(years, 1.0, 2.0, where=(ratio_trend >= 1.0) & (ratio_trend < 2.0), alpha=0.3, color='orange', label='Adequate Zone')
ax2.set_xlabel('Year', fontsize=11, fontweight='bold')
ax2.set_ylabel('Current Ratio', fontsize=11, fontweight='bold')
ax2.set_title('Current Ratio: Improving Liquidity Over Time', fontsize=12, fontweight='bold')
ax2.grid(True, alpha=0.3, linestyle='--')
ax2.legend(loc='upper left', fontsize=9)
ax2.set_xticks(years)

plt.tight_layout()
display(fig)
plt.close(fig)

Quick Ratio (Acid Test): Measures immediate liquidity (excludes inventory).

QuickRatio=CurrentAssets−InventoryCurrentLiabilitiesQuick Ratio = \frac{Current Assets - Inventory}{Current Liabilities}

Python exercise

#| label: quick-ratio-visualization
#| fig-cap: "Quick Ratio: Immediate Liquidity (Acid Test)"
#| fig-width: 14
#| fig-height: 6
#| echo: false
#| warning: false

# Sandbox metadata (auto-generated from lesson.ts)
# libraries: numpy, matplotlib, pandas

import numpy as np
import matplotlib.pyplot as plt
from IPython.display import display

# Example companies
companies = ['Liquid Co', 'Moderate', 'Tight Cash', 'Illiquid']
current_assets = [800, 500, 300, 200]
inventory = [200, 150, 150, 80]
quick_assets = [ca - inv for ca, inv in zip(current_assets, inventory)]
current_liabilities = [200, 200, 200, 200]
quick_ratio = [qa / cl for qa, cl in zip(quick_assets, current_liabilities)]
current_ratio = [ca / cl for ca, cl in zip(current_assets, current_liabilities)]

fig, axes = plt.subplots(1, 2, figsize=(16, 6))
fig.suptitle('Quick Ratio: Immediate Liquidity (Acid Test)', fontsize=14, fontweight='bold')

# Plot 1: Quick Ratio Comparison
ax1 = axes[0]
colors = ['green' if qr > 1.0 else 'orange' if qr > 0.5 else 'red' for qr in quick_ratio]
bars = ax1.bar(companies, quick_ratio, color=colors, alpha=0.7, edgecolor='black', linewidth=1.5)
ax1.axhline(y=1.0, color='green', linestyle='--', linewidth=2, alpha=0.5, label='Quick Ratio = 1.0 (Strong)')
ax1.axhline(y=0.5, color='orange', linestyle=':', linewidth=2, alpha=0.5, label='Quick Ratio = 0.5 (Low)')
ax1.set_ylabel('Quick Ratio', fontsize=11, fontweight='bold')
ax1.set_title('Quick Ratio: Immediate Liquidity', fontsize=12, fontweight='bold')
ax1.grid(True, alpha=0.3, linestyle='--', axis='y')
ax1.legend(loc='upper right', fontsize=9)
for bar, qr, qa, cl, inv in zip(bars, quick_ratio, quick_assets, current_liabilities, inventory):
    height = bar.get_height()
    ax1.text(bar.get_x() + bar.get_width()/2., height + 0.05,
             f'{qr:.2f}\nQuick Assets: ${qa}M\n(Excludes ${inv}M inv)',
             ha='center', va='bottom', fontsize=9, fontweight='bold')

# Plot 2: Current vs Quick Ratio
ax2 = axes[1]
x = np.arange(len(companies))
width = 0.35
bars1 = ax2.bar(x - width/2, current_ratio, width, label='Current Ratio', color='blue', alpha=0.7, edgecolor='black')
bars2 = ax2.bar(x + width/2, quick_ratio, width, label='Quick Ratio', color='green', alpha=0.7, edgecolor='black')
ax2.axhline(y=1.0, color='red', linestyle='--', linewidth=2, alpha=0.5, label='Ratio = 1.0')
ax2.set_ylabel('Ratio Value', fontsize=11, fontweight='bold')
ax2.set_title('Current vs Quick Ratio: Liquidity Comparison', fontsize=12, fontweight='bold')
ax2.set_xticks(x)
ax2.set_xticklabels(companies)
ax2.legend(loc='upper right', fontsize=9)
ax2.grid(True, alpha=0.3, linestyle='--', axis='y')
for bars in [bars1, bars2]:
    for bar in bars:
        height = bar.get_height()
        ax2.text(bar.get_x() + bar.get_width()/2., height + 0.05,
                 f'{height:.2f}', ha='center', va='bottom', fontsize=9, fontweight='bold')
ax2.text(0.5, 0.95, 'Quick Ratio excludes inventory\n(More conservative measure)',
         transform=ax2.transAxes, ha='center', va='top', fontsize=10, fontweight='bold',
         bbox=dict(boxstyle='round,pad=0.5', facecolor='yellow', edgecolor='black', linewidth=1.5))

plt.tight_layout()
display(fig)
plt.close(fig)

Cash Ratio: Measures the most immediate liquidity.

CashRatio=CashandCashEquivalentsCurrentLiabilitiesCash Ratio = \frac{Cash and Cash Equivalents}{Current Liabilities}

Python exercise

#| label: cash-ratio-visualization
#| fig-cap: "Cash Ratio: Ultimate Liquidity Measure"
#| fig-width: 14
#| fig-height: 6
#| echo: false
#| warning: false

# Sandbox metadata (auto-generated from lesson.ts)
# libraries: numpy, matplotlib, pandas

import numpy as np
import matplotlib.pyplot as plt
from IPython.display import display

# Example companies
companies = ['Cash Rich', 'Adequate', 'Tight', 'Critical']
cash = [500, 200, 80, 30]
current_liabilities = [200, 200, 200, 200]
cash_ratio = [c / cl for c, cl in zip(cash, current_liabilities)]

# Liquidity comparison
current_assets = [800, 500, 300, 150]
inventory = [100, 150, 100, 50]
quick_assets = [ca - inv for ca, inv in zip(current_assets, inventory)]
current_ratio = [ca / cl for ca, cl in zip(current_assets, current_liabilities)]
quick_ratio = [qa / cl for qa, cl in zip(quick_assets, current_liabilities)]

fig, axes = plt.subplots(1, 2, figsize=(16, 6))
fig.suptitle('Cash Ratio: Ultimate Liquidity Measure', fontsize=14, fontweight='bold')

# Plot 1: Cash Ratio Comparison
ax1 = axes[0]
colors = ['green' if cr > 1.0 else 'orange' if cr > 0.5 else 'red' for cr in cash_ratio]
bars = ax1.bar(companies, cash_ratio, color=colors, alpha=0.7, edgecolor='black', linewidth=1.5)
ax1.axhline(y=1.0, color='green', linestyle='--', linewidth=2, alpha=0.5, label='Cash Ratio = 1.0 (Strong)')
ax1.axhline(y=0.5, color='orange', linestyle=':', linewidth=2, alpha=0.5, label='Cash Ratio = 0.5 (Adequate)')
ax1.set_ylabel('Cash Ratio', fontsize=11, fontweight='bold')
ax1.set_title('Cash Ratio: Immediate Liquidity', fontsize=12, fontweight='bold')
ax1.grid(True, alpha=0.3, linestyle='--', axis='y')
ax1.legend(loc='upper right', fontsize=9)
for bar, cr, c, cl in zip(bars, cash_ratio, cash, current_liabilities):
    height = bar.get_height()
    ax1.text(bar.get_x() + bar.get_width()/2., height + 0.05,
             f'{cr:.2f}\nCash: ${c}M\nLiab: ${cl}M',
             ha='center', va='bottom', fontsize=9, fontweight='bold')

# Plot 2: Liquidity Ratios Comparison
ax2 = axes[1]
x = np.arange(len(companies))
width = 0.25
bars1 = ax2.bar(x - width, current_ratio, width, label='Current Ratio', color='blue', alpha=0.7, edgecolor='black')
bars2 = ax2.bar(x, quick_ratio, width, label='Quick Ratio', color='orange', alpha=0.7, edgecolor='black')
bars3 = ax2.bar(x + width, cash_ratio, width, label='Cash Ratio', color='green', alpha=0.7, edgecolor='black')
ax2.axhline(y=1.0, color='red', linestyle='--', linewidth=2, alpha=0.5, label='Ratio = 1.0')
ax2.set_ylabel('Ratio Value', fontsize=11, fontweight='bold')
ax2.set_title('Liquidity Ratios: Complete Picture', fontsize=12, fontweight='bold')
ax2.set_xticks(x)
ax2.set_xticklabels(companies)
ax2.legend(loc='upper left', fontsize=9)
ax2.grid(True, alpha=0.3, linestyle='--', axis='y')

plt.tight_layout()
display(fig)
plt.close(fig)

Market Ratios

Market ratios reflect market perceptions:

Earnings Yield: The inverse of P/E ratio.

EarningsYield=EarningsPerShareStockPrice=1P/EEarnings Yield = \frac{Earnings Per Share}{Stock Price} = \frac{1}{P/E}

Python exercise

#| label: earnings-yield-visualization
#| fig-cap: "Earnings Yield: Return from Earnings"
#| fig-width: 14
#| fig-height: 6
#| echo: false
#| warning: false

# Sandbox metadata (auto-generated from lesson.ts)
# libraries: numpy, matplotlib, pandas

import numpy as np
import matplotlib.pyplot as plt
from IPython.display import display

# Example stocks
stocks = ['Stock A', 'Stock B', 'Stock C', 'Stock D']
eps_values = [2.00, 3.00, 1.50, 5.00]
prices = [50, 75, 30, 100]
earnings_yield = [eps / p * 100 for eps, p in zip(eps_values, prices)]
pe_ratios = [p / eps for p, eps in zip(prices, eps_values)]

# Yield vs P/E relationship
pe_range = np.linspace(5, 50, 100)
yield_range = (1 / pe_range) * 100

fig, axes = plt.subplots(1, 2, figsize=(16, 6))
fig.suptitle('Earnings Yield: Return from Earnings', fontsize=14, fontweight='bold')

# Plot 1: Earnings Yield Comparison
ax1 = axes[0]
colors = ['green' if ey > 5 else 'orange' if ey > 3 else 'red' for ey in earnings_yield]
bars = ax1.bar(stocks, earnings_yield, color=colors, alpha=0.7, edgecolor='black', linewidth=1.5)
ax1.axhline(y=5, color='green', linestyle='--', linewidth=2, alpha=0.5, label='Yield = 5% (Good)')
ax1.axhline(y=3, color='orange', linestyle=':', linewidth=2, alpha=0.5, label='Yield = 3% (Low)')
ax1.set_ylabel('Earnings Yield (%)', fontsize=11, fontweight='bold')
ax1.set_title('Earnings Yield: Stock Comparison', fontsize=12, fontweight='bold')
ax1.grid(True, alpha=0.3, linestyle='--', axis='y')
ax1.legend(loc='upper right', fontsize=9)
for bar, ey, eps, price in zip(bars, earnings_yield, eps_values, prices):
    height = bar.get_height()
    ax1.text(bar.get_x() + bar.get_width()/2., height + 0.2,
             f'{ey:.1f}%\nEPS: ${eps}\nPrice: ${price}',
             ha='center', va='bottom', fontsize=9, fontweight='bold')

# Plot 2: Earnings Yield vs P/E (Inverse Relationship)
ax2 = axes[1]
ax2.plot(pe_range, yield_range, 'b-', linewidth=3, alpha=0.8, label='Earnings Yield = 1/P/E')
ax2.scatter(pe_ratios, earnings_yield, s=150, color='red', alpha=0.7, edgecolor='black', 
            linewidth=2, zorder=5, label='Example Stocks')
ax2.set_xlabel('P/E Ratio', fontsize=11, fontweight='bold')
ax2.set_ylabel('Earnings Yield (%)', fontsize=11, fontweight='bold')
ax2.set_title('Earnings Yield vs P/E: Inverse Relationship', fontsize=12, fontweight='bold')
ax2.grid(True, alpha=0.3, linestyle='--')
ax2.legend(loc='upper right', fontsize=9)
ax2.annotate('Higher P/E → Lower Yield\nLower P/E → Higher Yield',
             xy=(25, 4), xytext=(35, 8),
             arrowprops=dict(arrowstyle='->', color='green', lw=2),
             fontsize=10, fontweight='bold',
             bbox=dict(boxstyle='round,pad=0.5', facecolor='lightgreen', edgecolor='green', linewidth=2))

plt.tight_layout()
display(fig)
plt.close(fig)

Dividend Yield: Measures return from dividends.

DividendYield=AnnualDividendsPerShareStockPriceDividend Yield = \frac{Annual Dividends Per Share}{Stock Price}

Python exercise

#| label: dividend-yield-visualization
#| fig-cap: "Dividend Yield: Income Return from Stocks"
#| fig-width: 14
#| fig-height: 6
#| echo: false
#| warning: false

# Sandbox metadata (auto-generated from lesson.ts)
# libraries: numpy, matplotlib, pandas

import numpy as np
import matplotlib.pyplot as plt
from IPython.display import display

# Example dividend stocks
stocks = ['Utility Co', 'REIT', 'Blue Chip', 'Growth Stock']
dividends = [3.00, 4.00, 2.50, 0.50]
prices = [50, 80, 100, 75]
dividend_yield = [d / p * 100 for d, p in zip(dividends, prices)]

# Dividend yield over time
years = np.arange(1, 6, 1)
dividend_growth = 2.0 * (1.05 ** years)
price_appreciation = 50 * (1.08 ** years)
yield_declining = (dividend_growth / price_appreciation) * 100

fig, axes = plt.subplots(1, 2, figsize=(16, 6))
fig.suptitle('Dividend Yield: Income Return from Stocks', fontsize=14, fontweight='bold')

# Plot 1: Dividend Yield Comparison
ax1 = axes[0]
colors = ['green' if dy > 4 else 'orange' if dy > 2 else 'red' for dy in dividend_yield]
bars = ax1.bar(stocks, dividend_yield, color=colors, alpha=0.7, edgecolor='black', linewidth=1.5)
ax1.axhline(y=4, color='green', linestyle='--', linewidth=2, alpha=0.5, label='Yield = 4% (High)')
ax1.axhline(y=2, color='orange', linestyle=':', linewidth=2, alpha=0.5, label='Yield = 2% (Typical)')
ax1.set_ylabel('Dividend Yield (%)', fontsize=11, fontweight='bold')
ax1.set_title('Dividend Yield: Stock Comparison', fontsize=12, fontweight='bold')
ax1.grid(True, alpha=0.3, linestyle='--', axis='y')
ax1.legend(loc='upper right', fontsize=9)
for bar, dy, div, price in zip(bars, dividend_yield, dividends, prices):
    height = bar.get_height()
    ax1.text(bar.get_x() + bar.get_width()/2., height + 0.2,
             f'{dy:.1f}%\nDiv: ${div}\nPrice: ${price}',
             ha='center', va='bottom', fontsize=9, fontweight='bold')

# Plot 2: Dividend Yield Trend (Price Appreciation Effect)
ax2 = axes[1]
ax2_twin = ax2.twinx()
line1 = ax2.plot(years, yield_declining, 'b-', linewidth=3, marker='o', markersize=8, 
                 label='Dividend Yield', alpha=0.8)
line2 = ax2_twin.plot(years, price_appreciation, 'r--', linewidth=3, marker='s', markersize=8,
                     label='Stock Price', alpha=0.8)
ax2.set_xlabel('Year', fontsize=11, fontweight='bold')
ax2.set_ylabel('Dividend Yield (%)', fontsize=11, fontweight='bold', color='blue')
ax2_twin.set_ylabel('Stock Price ($)', fontsize=11, fontweight='bold', color='red')
ax2.set_title('Dividend Yield: Impact of Price Appreciation', fontsize=12, fontweight='bold')
ax2.grid(True, alpha=0.3, linestyle='--')
ax2.tick_params(axis='y', labelcolor='blue')
ax2_twin.tick_params(axis='y', labelcolor='red')
lines = line1 + line2
labels = [l.get_label() for l in lines]
ax2.legend(lines, labels, loc='upper left', fontsize=9)
ax2.set_xticks(years)

plt.tight_layout()
display(fig)
plt.close(fig)

PEG Ratio: P/E ratio adjusted for growth.

PEG=P/ERatioAnnualEarningsGrowthRatePEG = \frac{P/E Ratio}{Annual Earnings Growth Rate}

Python exercise

#| label: peg-ratio-visualization
#| fig-cap: "PEG Ratio: Growth-Adjusted Valuation"
#| fig-width: 14
#| fig-height: 6
#| echo: false
#| warning: false

# Sandbox metadata (auto-generated from lesson.ts)
# libraries: numpy, matplotlib, pandas

import numpy as np
import matplotlib.pyplot as plt
from IPython.display import display

# Example stocks
stocks = ['Value Stock', 'Growth Stock', 'High Growth', 'Overvalued']
pe_ratios = [15, 30, 40, 50]
growth_rates = [15, 20, 25, 10]
peg_ratios = [pe / gr for pe, gr in zip(pe_ratios, growth_rates)]

# PEG sensitivity to growth
growth_range = np.linspace(5, 30, 100)
pe_fixed = 30
peg_range = pe_fixed / growth_range

fig, axes = plt.subplots(1, 2, figsize=(16, 6))
fig.suptitle('PEG Ratio: Growth-Adjusted Valuation', fontsize=14, fontweight='bold')

# Plot 1: PEG Ratio Comparison
ax1 = axes[0]
colors = ['green' if peg < 1.0 else 'orange' if peg < 2.0 else 'red' for peg in peg_ratios]
bars = ax1.bar(stocks, peg_ratios, color=colors, alpha=0.7, edgecolor='black', linewidth=1.5)
ax1.axhline(y=1.0, color='green', linestyle='--', linewidth=2, alpha=0.5, label='PEG = 1.0 (Fair Value)')
ax1.axhline(y=2.0, color='orange', linestyle=':', linewidth=2, alpha=0.5, label='PEG = 2.0 (Expensive)')
ax1.set_ylabel('PEG Ratio', fontsize=11, fontweight='bold')
ax1.set_title('PEG Ratio: Growth-Adjusted Valuation', fontsize=12, fontweight='bold')
ax1.grid(True, alpha=0.3, linestyle='--', axis='y')
ax1.legend(loc='upper right', fontsize=9)
for bar, peg, pe, gr in zip(bars, peg_ratios, pe_ratios, growth_rates):
    height = bar.get_height()
    ax1.text(bar.get_x() + bar.get_width()/2., height + 0.1,
             f'PEG: {peg:.2f}\nP/E: {pe}\nGrowth: {gr}%',
             ha='center', va='bottom', fontsize=9, fontweight='bold')

# Plot 2: PEG vs Growth Rate
ax2 = axes[1]
ax2.plot(growth_range, peg_range, 'b-', linewidth=3, alpha=0.8, label=f'P/E = {pe_fixed}')
ax2.axhline(y=1.0, color='green', linestyle='--', linewidth=2, alpha=0.7, label='PEG = 1.0 (Fair)')
ax2.axhline(y=2.0, color='orange', linestyle=':', linewidth=2, alpha=0.7, label='PEG = 2.0 (Expensive)')
ax2.fill_between(growth_range, 0, peg_range, where=(peg_range <= 1.0), alpha=0.3, color='green', label='Undervalued (PEG < 1)')
ax2.fill_between(growth_range, 0, peg_range, where=(peg_range > 2.0), alpha=0.3, color='red', label='Overvalued (PEG > 2)')
ax2.scatter(growth_rates, peg_ratios, s=150, color='red', alpha=0.7, edgecolor='black', 
            linewidth=2, zorder=5, label='Example Stocks')
ax2.set_xlabel('Earnings Growth Rate (%)', fontsize=11, fontweight='bold')
ax2.set_ylabel('PEG Ratio', fontsize=11, fontweight='bold')
ax2.set_title('PEG Ratio: How Growth Affects Valuation', fontsize=12, fontweight='bold')
ax2.grid(True, alpha=0.3, linestyle='--')
ax2.legend(loc='upper right', fontsize=9)

plt.tight_layout()
display(fig)
plt.close(fig)

Using Financial Ratios

Financial ratios are most useful when used in context:

Time Series Analysis: Compare ratios over time to identify trends.

Python exercise

#| label: time-series-analysis-visualization
#| fig-cap: "Time Series Analysis: Ratio Trends Over Time"
#| fig-width: 14
#| fig-height: 6
#| echo: false
#| warning: false

# Sandbox metadata (auto-generated from lesson.ts)
# libraries: numpy, matplotlib, pandas

import numpy as np
import matplotlib.pyplot as plt
from IPython.display import display

# Example: Company ROE over 5 years
years = np.arange(2019, 2024, 1)
roe_company = [10, 12, 11, 14, 16]
roe_industry = [8, 9, 10, 11, 12]
roe_improving = [6, 8, 10, 12, 15]

fig, axes = plt.subplots(1, 2, figsize=(16, 6))
fig.suptitle('Time Series Analysis: Ratio Trends Over Time', fontsize=14, fontweight='bold')

# Plot 1: Single Company Trend
ax1 = axes[0]
ax1.plot(years, roe_company, 'b-', linewidth=3, marker='o', markersize=10, label='Company ROE', alpha=0.8)
ax1.axhline(y=np.mean(roe_company), color='blue', linestyle='--', linewidth=2, alpha=0.5, 
            label=f'Average: {np.mean(roe_company):.1f}%')
ax1.fill_between(years, 0, roe_company, alpha=0.3, color='blue')
ax1.set_xlabel('Year', fontsize=11, fontweight='bold')
ax1.set_ylabel('ROE (%)', fontsize=11, fontweight='bold')
ax1.set_title('ROE Trend: Identifying Patterns', fontsize=12, fontweight='bold')
ax1.grid(True, alpha=0.3, linestyle='--')
ax1.legend(loc='upper left', fontsize=9)
ax1.set_xticks(years)

# Plot 2: Company vs Industry
ax2 = axes[1]
ax2.plot(years, roe_company, 'b-', linewidth=3, marker='o', markersize=10, label='Company ROE', alpha=0.8)
ax2.plot(years, roe_industry, 'r--', linewidth=3, marker='s', markersize=10, label='Industry Average', alpha=0.8)
ax2.fill_between(years, roe_industry, roe_company, where=(np.array(roe_company) >= np.array(roe_industry)),
                 alpha=0.3, color='green', label='Outperforming')
ax2.fill_between(years, roe_industry, roe_company, where=(np.array(roe_company) < np.array(roe_industry)),
                 alpha=0.3, color='red', label='Underperforming')
ax2.set_xlabel('Year', fontsize=11, fontweight='bold')
ax2.set_ylabel('ROE (%)', fontsize=11, fontweight='bold')
ax2.set_title('Company vs Industry: Benchmarking', fontsize=12, fontweight='bold')
ax2.grid(True, alpha=0.3, linestyle='--')
ax2.legend(loc='upper left', fontsize=9)
ax2.set_xticks(years)

plt.tight_layout()
display(fig)
plt.close(fig)

Cross-Sectional Analysis: Compare ratios across companies in the same industry.

Python exercise

#| label: cross-sectional-analysis-visualization
#| fig-cap: "Cross-Sectional Analysis: Industry Comparison"
#| fig-width: 14
#| fig-height: 6
#| echo: false
#| warning: false

# Sandbox metadata (auto-generated from lesson.ts)
# libraries: numpy, matplotlib, pandas

import numpy as np
import matplotlib.pyplot as plt
from IPython.display import display

# Example: Tech companies in same industry
companies = ['Tech A', 'Tech B', 'Tech C', 'Tech D', 'Tech E']
pe_ratios = [25, 30, 22, 35, 28]
roe_values = [15, 18, 12, 20, 16]

# Industry averages
industry_pe = 28
industry_roe = 16

fig, axes = plt.subplots(1, 2, figsize=(16, 6))
fig.suptitle('Cross-Sectional Analysis: Industry Comparison', fontsize=14, fontweight='bold')

# Plot 1: P/E Ratio Comparison
ax1 = axes[0]
colors = ['green' if pe < industry_pe else 'red' for pe in pe_ratios]
bars = ax1.bar(companies, pe_ratios, color=colors, alpha=0.7, edgecolor='black', linewidth=1.5)
ax1.axhline(y=industry_pe, color='orange', linestyle='--', linewidth=2, alpha=0.7, 
            label=f'Industry Avg: {industry_pe}')
ax1.set_ylabel('P/E Ratio', fontsize=11, fontweight='bold')
ax1.set_title('P/E Ratios: Cross-Company Comparison', fontsize=12, fontweight='bold')
ax1.grid(True, alpha=0.3, linestyle='--', axis='y')
ax1.legend(loc='upper right', fontsize=9)
for bar, pe in zip(bars, pe_ratios):
    height = bar.get_height()
    ax1.text(bar.get_x() + bar.get_width()/2., height + 0.5,
             f'{pe:.0f}', ha='center', va='bottom', fontsize=9, fontweight='bold')

# Plot 2: ROE Comparison
ax2 = axes[1]
colors = ['green' if roe > industry_roe else 'red' for roe in roe_values]
bars2 = ax2.bar(companies, roe_values, color=colors, alpha=0.7, edgecolor='black', linewidth=1.5)
ax2.axhline(y=industry_roe, color='orange', linestyle='--', linewidth=2, alpha=0.7, 
            label=f'Industry Avg: {industry_roe}%')
ax2.set_ylabel('ROE (%)', fontsize=11, fontweight='bold')
ax2.set_title('ROE: Cross-Company Comparison', fontsize=12, fontweight='bold')
ax2.grid(True, alpha=0.3, linestyle='--', axis='y')
ax2.legend(loc='upper right', fontsize=9)
for bar, roe in zip(bars2, roe_values):
    height = bar.get_height()
    ax2.text(bar.get_x() + bar.get_width()/2., height + 0.3,
             f'{roe:.0f}%', ha='center', va='bottom', fontsize=9, fontweight='bold')

plt.tight_layout()
display(fig)
plt.close(fig)

Benchmarking: Compare ratios to industry averages or market averages.

Python exercise

#| label: benchmarking-visualization
#| fig-cap: "Benchmarking: Company vs Industry and Market"
#| fig-width: 14
#| fig-height: 6
#| echo: false
#| warning: false

# Sandbox metadata (auto-generated from lesson.ts)
# libraries: numpy, matplotlib, pandas

import numpy as np
import matplotlib.pyplot as plt
from IPython.display import display

# Example: Company ratios vs benchmarks
ratios = ['P/E', 'ROE', 'Current\nRatio', 'Debt/\nEquity']
company_values = [28, 16, 2.2, 0.8]
industry_avg = [25, 14, 1.8, 0.6]
market_avg = [20, 12, 1.5, 0.5]

fig, axes = plt.subplots(1, 2, figsize=(16, 6))
fig.suptitle('Benchmarking: Company vs Industry and Market', fontsize=14, fontweight='bold')

# Plot 1: Company vs Industry
ax1 = axes[0]
x = np.arange(len(ratios))
width = 0.35
bars1 = ax1.bar(x - width/2, company_values, width, label='Company', color='blue', alpha=0.7, edgecolor='black')
bars2 = ax1.bar(x + width/2, industry_avg, width, label='Industry Avg', color='orange', alpha=0.7, edgecolor='black')
ax1.set_ylabel('Ratio Value', fontsize=11, fontweight='bold')
ax1.set_title('Company vs Industry Average', fontsize=12, fontweight='bold')
ax1.set_xticks(x)
ax1.set_xticklabels(ratios)
ax1.legend(loc='upper left', fontsize=9)
ax1.grid(True, alpha=0.3, linestyle='--', axis='y')
for bars in [bars1, bars2]:
    for bar in bars:
        height = bar.get_height()
        ax1.text(bar.get_x() + bar.get_width()/2., height + height*0.02,
                 f'{height:.1f}', ha='center', va='bottom', fontsize=9, fontweight='bold')

# Plot 2: All Three Comparisons
ax2 = axes[1]
x2 = np.arange(len(ratios))
width2 = 0.25
bars1_2 = ax2.bar(x2 - width2, company_values, width2, label='Company', color='blue', alpha=0.7, edgecolor='black')
bars2_2 = ax2.bar(x2, industry_avg, width2, label='Industry', color='orange', alpha=0.7, edgecolor='black')
bars3_2 = ax2.bar(x2 + width2, market_avg, width2, label='Market', color='green', alpha=0.7, edgecolor='black')
ax2.set_ylabel('Ratio Value', fontsize=11, fontweight='bold')
ax2.set_title('Company vs Industry vs Market', fontsize=12, fontweight='bold')
ax2.set_xticks(x2)
ax2.set_xticklabels(ratios)
ax2.legend(loc='upper left', fontsize=9)
ax2.grid(True, alpha=0.3, linestyle='--', axis='y')

plt.tight_layout()
display(fig)
plt.close(fig)

Limitations: Ratios can be manipulated, may not reflect economic reality, and must be interpreted in context. They're tools, not answers.

Combination: No single ratio tells the whole story. Use multiple ratios together for a complete picture.

Understanding financial ratios is essential for fundamental analysis, company valuation, and investment decision-making. They provide a standardized way to compare companies and assess financial health.


In Module 4: Mathematics for Finance

  1. Introduction
  2. Time Value of Money: The Foundation of Finance
  3. Compound Interest: The Power of Exponential Growth
  4. Present Value and Future Value: Valuing Money Across Time
  5. Annuities and Perpetuities
  6. Basic Statistics and Probability: Understanding Uncertainty
  7. Financial Ratios and Percentages: Tools for Analysis
  8. Advanced Financial Mathematics
  9. Mathematical Modeling in Finance
  10. End-of-Module Assessment