Calculating Weighted Average Shares

Weighted Average Shares Calculator & Guide | Calculate Diluted EPS :root { –primary-color: #004a99; –success-color: #28a745; –background-color: #f8f9fa; –text-color: #333; –border-color: #dee2e6; –card-background: #ffffff; –shadow-color: rgba(0, 0, 0, 0.1); } body { font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; background-color: var(–background-color); color: var(–text-color); line-height: 1.6; margin: 0; padding: 0; } .container { max-width: 980px; margin: 20px auto; padding: 20px; background-color: var(–card-background); border-radius: 8px; box-shadow: 0 4px 12px var(–shadow-color); } header { background-color: var(–primary-color); color: white; padding: 20px; text-align: center; border-radius: 8px 8px 0 0; margin-bottom: 20px; } header h1 { margin: 0; font-size: 2.2em; } h2, h3 { color: var(–primary-color); margin-top: 1.5em; margin-bottom: 0.5em; } .loan-calc-container { background-color: var(–card-background); padding: 25px; border-radius: 8px; box-shadow: 0 2px 8px var(–shadow-color); margin-bottom: 30px; } .input-group { margin-bottom: 20px; display: flex; flex-direction: column; } .input-group label { display: block; font-weight: bold; margin-bottom: 8px; color: var(–primary-color); } .input-group input[type="number"], .input-group input[type="text"], .input-group select { padding: 10px; border: 1px solid var(–border-color); border-radius: 4px; font-size: 1em; width: calc(100% – 20px); /* Account for padding */ } .input-group select { width: 100%; /* Select takes full width */ } .input-group small { display: block; margin-top: 8px; color: #6c757d; font-size: 0.85em; } .error-message { color: red; font-size: 0.8em; margin-top: 5px; min-height: 1.2em; /* Reserve space to prevent layout shifts */ } .button-group { display: flex; gap: 10px; margin-top: 25px; justify-content: center; flex-wrap: wrap; } .btn { padding: 12px 25px; border: none; border-radius: 5px; cursor: pointer; font-size: 1em; font-weight: bold; transition: background-color 0.3s ease; white-space: nowrap; } .btn-primary { background-color: var(–primary-color); color: white; } .btn-primary:hover { background-color: #003366; } .btn-secondary { background-color: #6c757d; color: white; } .btn-secondary:hover { background-color: #5a6268; } .btn-success { background-color: var(–success-color); color: white; } .btn-success:hover { background-color: #218838; } #results-container { margin-top: 30px; padding: 25px; background-color: #e9ecef; border-radius: 8px; border: 1px solid var(–border-color); text-align: center; } #results-container h3 { margin-top: 0; color: var(–primary-color); } #main-result { font-size: 2.5em; font-weight: bold; color: var(–success-color); margin: 10px 0 20px 0; display: block; background-color: #ffffff; padding: 15px; border-radius: 5px; box-shadow: inset 0 0 10px rgba(0,0,0,0.05); } .intermediate-results span, .assumption-item span { display: block; margin-bottom: 8px; font-weight: bold; color: var(–primary-color); } .intermediate-results .value, .assumption-item .value { font-size: 1.3em; color: var(–text-color); margin-left: 5px; } .formula-explanation { margin-top: 20px; font-style: italic; color: #555; font-size: 0.95em; text-align: left; } table { width: 100%; border-collapse: collapse; margin-top: 20px; margin-bottom: 30px; box-shadow: 0 2px 5px var(–shadow-color); } th, td { padding: 12px 15px; text-align: left; border-bottom: 1px solid var(–border-color); } thead { background-color: var(–primary-color); color: white; } tbody tr:nth-child(even) { background-color: #f2f2f2; } caption { font-weight: bold; margin-bottom: 10px; color: var(–primary-color); font-size: 1.1em; caption-side: top; text-align: left; } #chartContainer { text-align: center; margin-top: 30px; background-color: var(–card-background); padding: 20px; border-radius: 8px; box-shadow: 0 2px 8px var(–shadow-color); } #chartContainer h3 { margin-top: 0; } canvas { max-width: 100%; height: auto; border: 1px solid var(–border-color); border-radius: 4px; } .article-content { margin-top: 40px; padding: 30px; background-color: var(–card-background); border-radius: 8px; box-shadow: 0 2px 8px var(–shadow-color); } .article-content p, .article-content ul, .article-content ol { margin-bottom: 1.5em; } .article-content ul, .article-content ol { padding-left: 20px; } .article-content li { margin-bottom: 0.8em; } .article-content a { color: var(–primary-color); text-decoration: none; transition: color 0.3s ease; } .article-content a:hover { color: #003366; text-decoration: underline; } .faq-item { margin-bottom: 15px; border-left: 3px solid var(–primary-color); padding-left: 15px; } .faq-item strong { display: block; color: var(–primary-color); margin-bottom: 5px; } .related-links { margin-top: 30px; padding: 20px; background-color: #e9ecef; border-radius: 8px; border: 1px solid var(–border-color); } .related-links ul { list-style: none; padding: 0; } .related-links li { margin-bottom: 15px; } .related-links li a { font-weight: bold; } .related-links li p { font-size: 0.9em; color: #555; margin-top: 5px; } @media (max-width: 768px) { .container { margin: 10px; padding: 15px; } header h1 { font-size: 1.8em; } .btn { padding: 10px 20px; font-size: 0.95em; width: 100%; box-sizing: border-box; } .button-group { flex-direction: column; align-items: center; } .button-group .btn { width: 80%; } }

Weighted Average Shares Calculator

Accurately Calculate Diluted Earnings Per Share

Number of shares outstanding at the beginning of the reporting period.
Number of shares issued by the company during the reporting period (e.g., from stock options, secondary offerings).
The date when the new shares were issued. If no new shares were issued, this can be ignored or set to the period start date.
Number of shares repurchased by the company during the reporting period (e.g., stock buybacks).
The date when shares were repurchased. If no shares were repurchased, this can be ignored or set to the period start date.
Total number of days in the reporting period (e.g., 365 for a year, 90 for a quarter).

Calculation Results

0
Weighted New Shares Issued: 0 Weighted Shares Repurchased: 0 Weighted Average Shares Outstanding: 0

The weighted average shares outstanding formula accounts for the timing of share issuances and repurchases during the period.

Formula:
Weighted Avg Shares = (Shares at Start * Time Weight) + (New Shares Issued * Time Weight) – (Shares Repurchased * Time Weight)

*Time weight is the fraction of the period the shares were outstanding.

Key Assumptions

Share Activity Over Time

Share Issuance and Repurchase Activity
Activity Shares Date Days Outstanding in Period Time Weight Weighted Shares
Shares Outstanding (Start) 0 Start of Period 0 0.00% 0
New Shares Issued 0 N/A 0 0.00% 0
Shares Repurchased 0 N/A 0 0.00% 0
Total Weighted Average Shares 0

What is Weighted Average Shares Outstanding?

Weighted average shares outstanding is a crucial metric in financial accounting, representing the average number of a company's shares that have been issued and outstanding over a specific period, adjusted for the timing of when shares entered or exited circulation. This calculation is fundamental for determining a company's earnings per share (EPS), a key profitability indicator watched closely by investors and analysts. By weighting the shares based on how long they were outstanding during the reporting period, it provides a more accurate picture of the ownership structure and its impact on profitability than a simple count of shares at the end of the period.

Who Should Use It?

  • Publicly Traded Companies: Essential for statutory financial reporting and compliance with accounting standards like GAAP and IFRS.
  • Financial Analysts: To understand a company's true profitability on a per-share basis and to compare it with industry peers.
  • Investors: To gauge the health and performance of their investments and to make informed decisions about buying or selling stock.
  • Management: To assess the impact of equity financing decisions, stock-based compensation, and share buyback programs on shareholder value.

Common Misconceptions:

  • End-of-Period Shares: The most common misconception is that EPS is calculated using only the shares outstanding at the end of the reporting period. This ignores significant events like share issuances or buybacks that occurred mid-period, leading to an inaccurate EPS.
  • Ignoring Timing: Another mistake is not weighting the shares by the duration they were outstanding. A share issued on the first day of the period should have a greater impact than one issued on the last day.
  • Simple Average: While it's an "average," it's not a simple arithmetic mean of the beginning and end share counts. The weighting is based on the proportion of the reporting period each share count was effective.

Weighted Average Shares Outstanding Formula and Mathematical Explanation

The calculation of weighted average shares outstanding (WASO) is designed to provide a more accurate reflection of earnings dilution than simply using the number of shares at the end of a period. This is particularly important when there are significant changes in the number of shares outstanding throughout the reporting period.

The core concept is to multiply the number of shares outstanding during a specific sub-period by the fraction of the total reporting period those shares were outstanding.

The Formula:

Weighted Average Shares Outstanding = Σ (Number of Shares * Time Weight)

Where:

  • Number of Shares: The count of shares outstanding during a specific segment of the reporting period.
  • Time Weight: The fraction of the reporting period for which those shares were outstanding. This is calculated as (Number of Days Shares Were Outstanding) / (Total Days in Reporting Period).
  • Σ (Sigma): Represents the summation of the weighted shares for all such segments during the reporting period.

In practice, for a typical reporting period (quarterly or annually), we often simplify this to account for:

  1. Shares outstanding at the beginning of the period.
  2. Shares issued during the period.
  3. Shares repurchased during the period.

The calculation then becomes:

WASO = (Shares_Start * Days_Start / Total_Days) + (Shares_Issued * Days_Issued / Total_Days) - (Shares_Repurchased * Days_Repurchased / Total_Days)

Where:

  • Shares_Start: Number of shares at the beginning of the period.
  • Days_Start: Number of days from the start of the period until the next event (issuance/repurchase) or the end of the period. For the initial block of shares, this is usually the entire period unless there's an event. For simplicity in many calculators, we use the proportion of the period the initial shares were outstanding. If the initial shares are considered from day 1, their weight is 1 (or the full period days).
  • Shares_Issued: Number of new shares issued during the period.
  • Days_Issued: Number of days from the issuance date to the end of the reporting period.
  • Shares_Repurchased: Number of shares repurchased during the period.
  • Days_Repurchased: Number of days from the repurchase date to the end of the reporting period.
  • Total_Days: The total number of days in the reporting period (e.g., 90 for Q1, 365 for a year).

Variable Explanation Table:

Weighted Average Shares Variables
Variable Meaning Unit Typical Range
Shares_Start Number of shares outstanding at the beginning of the reporting period. Shares ≥ 0
Shares_Issued Number of shares issued or added during the reporting period. Shares ≥ 0
Shares_Repurchased Number of shares repurchased or retired during the reporting period. Shares ≥ 0
Issue/Repurchase Date The specific date shares were issued or repurchased. Date Within the reporting period
Total_Days Total number of days in the reporting period (e.g., 90, 91, 92, 365, 366). Days > 0
Days Outstanding Number of days shares were outstanding within the reporting period, from their issue/start date to the period end or next event. Days 0 to Total_Days
Time Weight The fraction of the reporting period shares were outstanding. (Days Outstanding / Total_Days) Ratio (0 to 1) 0.00 to 1.00
Weighted Shares Number of Shares * Time Weight. Represents the equivalent number of shares outstanding for the full period. Shares ≥ 0
WASO The final calculated weighted average shares outstanding for the period. Shares ≥ 0

Practical Examples (Real-World Use Cases)

Example 1: Simple Stock Issuance Mid-Quarter

A company, "TechGlow Inc.," has the following activity in Q1 2023 (90 days):

  • Shares outstanding on January 1, 2023: 1,000,000
  • On February 15, 2023 (Day 46 of the quarter), TechGlow issued 200,000 new shares to fund expansion.

Calculation:

  • Period: January 1 – March 31 (90 days)
  • Initial Shares (Jan 1): 1,000,000 shares. These are outstanding for 45 days (Jan 1 to Feb 14).
  • New Shares Issued (Feb 15): 200,000 shares. These are outstanding from Feb 15 to March 31, which is 45 days (90 total days – 45 days prior).

Weighted Avg Shares = (1,000,000 shares * 45 days / 90 days) + (200,000 shares * 45 days / 90 days)
Weighted Avg Shares = (1,000,000 * 0.5) + (200,000 * 0.5)
Weighted Avg Shares = 500,000 + 100,000
Weighted Average Shares Outstanding = 600,000

Interpretation: Although TechGlow ended the quarter with 1,200,000 shares (1,000,000 + 200,000), the weighted average is 600,000. This lower figure reflects that the additional 200,000 shares were only outstanding for half the quarter. If TechGlow reported $300,000 in net income, the diluted EPS would be $300,000 / 600,000 = $0.50 per share.

Example 2: Share Buyback and Stock Options

"FinCorp Ltd." operates on a calendar year (365 days).

  • Shares outstanding on January 1: 5,000,000
  • On April 1 (Day 90), FinCorp repurchased 500,000 shares.
  • On July 1 (Day 181), FinCorp issued 300,000 shares upon the exercise of stock options.

Calculation:

  • Period: January 1 – December 31 (365 days)
  • Initial Shares (Jan 1): 5,000,000 shares. Outstanding for 89 days (Jan 1 to March 31).
  • Repurchased Shares (Apr 1): 500,000 shares. Retired on April 1. These shares were outstanding for 89 days (Jan 1 to March 31). The remaining shares (4,500,000) are outstanding for the rest of the year (365 – 90 = 275 days).
  • Issued Shares (July 1): 300,000 shares. Outstanding from July 1 to December 31, which is 184 days (365 – 181).

This is more complex because the repurchase changes the base number of shares. A simpler approach is to track changes chronologically:

  • Block 1: 5,000,000 shares from Jan 1 to Mar 31 (89 days). Weight = 89/365. Weighted = 5,000,000 * (89/365)
  • Block 2: 4,500,000 shares (5,000,000 – 500,000) from Apr 1 to Jun 30 (92 days). Weight = 92/365. Weighted = 4,500,000 * (92/365)
  • Block 3: 4,800,000 shares (4,500,000 + 300,000) from Jul 1 to Dec 31 (184 days). Weight = 184/365. Weighted = 4,800,000 * (184/365)

Weighted Avg Shares = (5,000,000 * 89/365) + (4,500,000 * 92/365) + (4,800,000 * 184/365)
Weighted Avg Shares = (1,221,918) + (1,131,507) + (2,429,589)
Weighted Average Shares Outstanding = 4,782,014 (approximately)

Interpretation: FinCorp ended the year with 4,800,000 shares (5M – 0.5M + 0.3M). The weighted average is slightly lower at approximately 4.78 million shares due to the timing of the repurchase and issuance. This figure is used for calculating the base EPS. If FinCorp reports $9,564,028 in net income, the diluted EPS is $9,564,028 / 4,782,014 = $2.00 per share.

How to Use This Weighted Average Shares Calculator

Our calculator simplifies the complex process of determining the weighted average shares outstanding. Follow these steps for accurate results:

  1. Input Initial Shares: Enter the number of shares your company had outstanding at the very beginning of the reporting period (e.g., January 1st for an annual report, April 1st for Q2).
  2. Input New Shares Issued: If your company issued any new shares during the period (e.g., through stock options, new offerings, employee stock purchase plans), enter the total number of these new shares.
  3. Enter New Share Issue Date: Crucially, specify the exact date these new shares were issued. If no new shares were issued, leave this at the default or the period start date.
  4. Input Shares Repurchased: Enter the total number of shares your company bought back or retired during the period.
  5. Enter Repurchase Date: Specify the exact date these shares were repurchased. If no shares were repurchased, leave this at the default or the period start date.
  6. Specify Reporting Period (Days): Enter the total number of days in the reporting period. Use 365 for an annual report (or 366 for a leap year), 90 for Q1, 91 for Q2, etc. Ensure this matches the calendar days accurately.
  7. Click 'Calculate': The calculator will instantly process the inputs.

Reading the Results:

  • Main Result (Weighted Average Shares Outstanding): This is your primary output, displayed prominently. It's the average number of shares outstanding for the entire period, adjusted for timing.
  • Intermediate Weighted Values: You'll see the weighted impact of any shares issued or repurchased. These help clarify the calculation.
  • Table Breakdown: The table provides a detailed view of each transaction's contribution to the weighted average, including the time weight applied.
  • Chart Visualization: The chart visually represents the share activity over the period, showing the baseline and any changes.

Decision-Making Guidance:

  • A higher weighted average share count, especially due to new issuances, can potentially dilute Earnings Per Share (EPS).
  • A lower weighted average share count, often due to buybacks, can potentially increase EPS.
  • Use this figure as the denominator when calculating your company's basic and diluted EPS.
  • Ensure accuracy in your inputs, especially dates, as they significantly impact the weighting.

Key Factors That Affect Weighted Average Shares Results

Several factors significantly influence the calculation and the resulting weighted average shares outstanding, impacting financial reporting and key per-share metrics. Understanding these is vital for accurate financial analysis.

  • Timing of Share Issuances: Shares issued early in the reporting period will have a greater impact (higher weight) on the weighted average than those issued late in the period. A large issuance just before the period ends will have a minimal effect on the weighted average for that period but a significant effect on the next.
  • Timing of Share Repurchases: Conversely, shares repurchased early in the period reduce the weighted average more significantly than those repurchased later. The weighted average calculation effectively removes shares from circulation for the portion of the period they were not outstanding.
  • Total Number of Days in the Period: Whether the period is a short quarter (approx. 90 days) or a full year (365/366 days) directly affects the denominator in the time weight calculation. This changes the proportional impact of any share activity.
  • Frequency of Share Transactions: A company with multiple issuances and repurchases throughout a period will have a more complex calculation, requiring more granular sub-periods to determine the accurate weighted average. Each event necessitates recalculating the weighted average for subsequent periods.
  • Stock Splits and Reverse Splits: While not explicitly handled in this basic calculator, stock splits (issuing more shares proportionally) and reverse stock splits (consolidating shares) require retrospective adjustments to all prior periods' weighted average share counts. This ensures comparability of EPS across periods. This calculator assumes no splits occurred within the period being calculated.
  • Issuance of Convertible Securities and Options: For diluted EPS calculations (a subsequent step after calculating basic weighted average shares), the potential issuance of shares from convertible bonds, preferred stock, or stock options must also be considered. While this calculator focuses on the basic weighted average, these factors add complexity to fully diluted EPS.
  • Vesting Schedules for Equity Compensation: Employee stock options and restricted stock units (RSUs) often vest over time. The weighted average calculation needs to account for when these become actual shares outstanding and how they affect the total.

Frequently Asked Questions (FAQ)

Q1: What is the difference between basic and diluted EPS?

Basic EPS uses the weighted average number of common shares outstanding. Diluted EPS considers the potential dilution from all convertible securities, stock options, and warrants outstanding, effectively assuming they have been exercised or converted. The calculation of weighted average shares is the first step for both, but diluted EPS requires further adjustments.

Q2: Does the calculator handle stock splits?

This specific calculator is designed for basic weighted average shares and does not automatically account for stock splits or reverse stock splits. For accurate reporting, stock splits require retrospective adjustment of weighted average shares for all prior periods presented.

Q3: What if a share issuance/repurchase occurs on the first or last day of the period?

If shares are issued or repurchased on the first day of the period, they are typically considered outstanding (or not outstanding) for the entire period, meaning their time weight is 1 (or 0). If it occurs on the last day, it generally does not affect the weighted average for the current period but impacts the next. The calculator handles this by calculating the days remaining in the period.

Q4: How are shares issued for employee stock options treated?

When stock options are exercised and shares are issued, they are treated as new shares issued on the exercise date. Their contribution to the weighted average is calculated based on the number of days they were outstanding from the exercise date to the end of the period. For diluted EPS, unexercised options are also considered, but that's a more complex calculation (e.g., using the treasury stock method).

Q5: What if the reporting period is not a full quarter or year?

The calculator handles periods of any length (in days) by using the total days provided. Ensure you input the accurate number of days for the specific reporting period (e.g., 30 days for a specific 30-day window).

Q6: Do preferred stock dividends affect weighted average shares?

Preferred stock dividends affect the calculation of EPS by reducing the net income available to common shareholders, but they do not directly alter the calculation of the weighted average number of common shares outstanding.

Q7: Can I use this for past periods?

Yes, as long as you have the accurate share counts and transaction dates for that past period. Simply update the input fields with the historical data. Ensure the "Reporting Period (Days)" is correct for that specific historical period.

Q8: What is a "sensible default value" for reset?

The reset button restores the calculator to a typical starting scenario: beginning with a million shares, no issuances or repurchases, and a full year reporting period. These are common starting points for demonstration and initial calculations.

© 2023 Your Company Name. All rights reserved.
var ctx = null; var sharesChart = null; function getDaysInMonth(year, month) { return new Date(year, month + 1, 0).getDate(); } function dateToDays(dateString, periodStartDateString) { var periodStart = new Date(periodStartDateString); var eventDate = new Date(dateString); var diffTime = eventDate.getTime() – periodStart.getTime(); var diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24)); return Math.max(0, diffDays); // Ensure non-negative } function isValidDate(dateString) { var regEx = /^\d{4}-\d{2}-\d{2}$/; if(!dateString.match(regEx)) return false; var d = new Date(dateString); var dNum = d.getTime(); if(!dNum && dNum !== 0) return false; return d.toISOString().slice(0,10) === dateString; } function calculateWeightedAverageShares() { var sharesIssuedInitial = parseFloat(document.getElementById("sharesIssuedInitial").value); var sharesIssuedNew = parseFloat(document.getElementById("sharesIssuedNew").value); var sharesIssuedNewDate = document.getElementById("sharesIssuedNewDate").value; var sharesRepurchased = parseFloat(document.getElementById("sharesRepurchased").value); var sharesRepurchasedDate = document.getElementById("sharesRepurchasedDate").value; var reportingPeriodDays = parseInt(document.getElementById("reportingPeriod").value); var periodStartDateString = "2023-01-01"; // Defaulting for date calculation logic, actual period start is implicit // Clear previous errors document.getElementById("sharesIssuedInitialError").innerText = ""; document.getElementById("sharesIssuedNewError").innerText = ""; document.getElementById("sharesIssuedNewDateError").innerText = ""; document.getElementById("sharesRepurchasedError").innerText = ""; document.getElementById("sharesRepurchasedDateError").innerText = ""; document.getElementById("reportingPeriodError").innerText = ""; var errors = false; if (isNaN(sharesIssuedInitial) || sharesIssuedInitial < 0) { document.getElementById("sharesIssuedInitialError").innerText = "Please enter a valid number of shares (0 or more)."; errors = true; } if (isNaN(reportingPeriodDays) || reportingPeriodDays <= 0) { document.getElementById("reportingPeriodError").innerText = "Reporting period must be at least 1 day."; errors = true; } if (isNaN(sharesIssuedNew) || sharesIssuedNew 0 && !isValidDate(sharesIssuedNewDate)) { document.getElementById("sharesIssuedNewDateError").innerText = "Please enter a valid issue date."; errors = true; } if (isNaN(sharesRepurchased) || sharesRepurchased 0 && !isValidDate(sharesRepurchasedDate)) { document.getElementById("sharesRepurchasedDateError").innerText = "Please enter a valid repurchase date."; errors = true; } // Compare dates if both are valid and > 0 if (sharesIssuedNew > 0 && sharesRepurchased > 0 && isValidDate(sharesIssuedNewDate) && isValidDate(sharesRepurchasedDate)) { var issueDate = new Date(sharesIssuedNewDate); var repurchaseDate = new Date(sharesRepurchasedDate); if (issueDate.getTime() === repurchaseDate.getTime()) { // Decide how to handle same day: maybe error or process sequentially. // For simplicity, let's assume they happen at different times or one cancels other. // A more robust solution might require time of day or separate processing blocks. // For now, we'll allow it but it might be less realistic. } else if (issueDate.getTime() > repurchaseDate.getTime() && sharesIssuedNew > sharesRepurchased) { // Potentially problematic, but mathematically calculable. // Could add a warning if desired. } } if (errors) { document.getElementById("main-result").innerText = "Invalid Input"; updateTable(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); // Clear table updateChart([], []); // Clear chart return; } var weightedSharesIssued = 0; var weightedSharesRepurchased = 0; var timeWeightIssued = 0; var timeWeightRepurchased = 0; var weightedAverageShares = sharesIssuedInitial; // Start with initial shares var initialDaysOutstanding = reportingPeriodDays; // Assume initial shares are outstanding for the full period initially var issueDateObj = null; var repurchaseDateObj = null; if (sharesIssuedNew > 0 && isValidDate(sharesIssuedNewDate)) { issueDateObj = new Date(sharesIssuedNewDate); var daysFromIssue = dateToDays(sharesIssuedNewDate, periodStartDateString); timeWeightIssued = (reportingPeriodDays – daysFromIssue) / reportingPeriodDays; weightedSharesIssued = sharesIssuedNew * timeWeightIssued; } if (sharesRepurchased > 0 && isValidDate(sharesRepurchasedDate)) { repurchaseDateObj = new Date(sharesRepurchasedDate); var daysFromRepurchase = dateToDays(sharesRepurchasedDate, periodStartDateString); timeWeightRepurchased = (reportingPeriodDays – daysFromRepurchase) / reportingPeriodDays; weightedSharesRepurchased = sharesRepurchased * timeWeightRepurchased; } // More precise calculation considering event order var eventDates = []; if (issueDateObj) eventDates.push({date: issueDateObj, type: 'issue', shares: sharesIssuedNew, weightedValue: weightedSharesIssued, timeWeight: timeWeightIssued}); if (repurchaseDateObj) eventDates.push({date: repurchaseDateObj, type: 'repurchase', shares: sharesRepurchased, weightedValue: weightedSharesRepurchased, timeWeight: timeWeightRepurchased}); eventDates.sort(function(a, b) { return a.date.getTime() – b.date.getTime(); }); var finalWeightedAverageShares = 0; var lastEventDate = new Date(periodStartDateString); // Start of period var currentShares = sharesIssuedInitial; var totalWeightedShares = 0; for (var i = 0; i 0) { // Only add weight if there's a segment before this event var segmentDays = daysUntilEvent – dateToDays(lastEventDate.toISOString().slice(0,10), periodStartDateString); if (segmentDays > 0) { var segmentWeight = segmentDays / reportingPeriodDays; totalWeightedShares += currentShares * segmentWeight; } } // Update current shares based on event type if (event.type === 'issue') { currentShares += event.shares; } else if (event.type === 'repurchase') { currentShares -= event.shares; } lastEventDate = event.date; } // Add the final segment (from the last event to the end of the period) var remainingDays = reportingPeriodDays – dateToDays(lastEventDate.toISOString().slice(0,10), periodStartDateString); if (remainingDays > 0) { var finalSegmentWeight = remainingDays / reportingPeriodDays; totalWeightedShares += currentShares * finalSegmentWeight; } finalWeightedAverageShares = totalWeightedShares; // Update the table var initialPeriodDays = dateToDays(sharesIssuedNewDate 0 && isValidDate(sharesIssuedNewDate)) { var daysSinceIssue = dateToDays(sharesIssuedNewDate, periodStartDateString); daysForIssue = reportingPeriodDays – daysSinceIssue; issueWeight = daysForIssue / reportingPeriodDays; issueWeighted = sharesIssuedNew * issueWeight; } var repurchaseWeighted = 0; var repurchaseWeight = 0; var daysForRepurchase = 0; if (sharesRepurchased > 0 && isValidDate(sharesRepurchasedDate)) { var daysSinceRepurchase = dateToDays(sharesRepurchasedDate, periodStartDateString); daysForRepurchase = reportingPeriodDays – daysSinceRepurchase; repurchaseWeight = daysForRepurchase / reportingPeriodDays; repurchaseWeighted = sharesRepurchased * repurchaseWeight; } updateTable(sharesIssuedInitial, sharesIssuedNew, sharesRepurchased, reportingPeriodDays, daysForIssue, daysForRepurchase, issueWeight, repurchaseWeight, initialWeighted, issueWeighted, repurchaseWeighted, finalWeightedAverageShares); document.getElementById("main-result").innerText = finalWeightedAverageShares.toLocaleString(undefined, {maximumFractionDigits: 0}); document.getElementById("weightedSharesIssued").getElementsByClassName("value")[0].innerText = issueWeighted.toLocaleString(undefined, {maximumFractionDigits: 0}); document.getElementById("weightedSharesRepurchased").getElementsByClassName("value")[0].innerText = repurchaseWeighted.toLocaleString(undefined, {maximumFractionDigits: 0}); document.getElementById("weightedAverageShares").getElementsByClassName("value")[0].innerText = finalWeightedAverageShares.toLocaleString(undefined, {maximumFractionDigits: 0}); updateAssumptions(sharesIssuedInitial, sharesIssuedNew, sharesIssuedNewDate, sharesRepurchased, sharesRepurchasedDate, reportingPeriodDays); updateChartData(sharesIssuedInitial, sharesIssuedNew, sharesIssuedNewDate, sharesRepurchased, sharesRepurchasedDate, reportingPeriodDays); } function updateTable(initialShares, newIssued, repurchased, totalDays, daysIssued, daysRepurchased, weightIssued, weightRepurchased, weightedInitial, weightedIssued, weightedRepurchased, totalWeightedAvg) { document.getElementById("tableSharesStart").innerText = initialShares.toLocaleString(); document.getElementById("tableSharesIssued").innerText = newIssued.toLocaleString(); document.getElementById("tableSharesRepurchased").innerText = repurchased.toLocaleString(); document.getElementById("tableDateIssued").innerText = newIssued > 0 ? document.getElementById("sharesIssuedNewDate").value : "N/A"; document.getElementById("tableDateRepurchased").innerText = repurchased > 0 ? document.getElementById("sharesRepurchasedDate").value : "N/A"; // Calculate days for each segment based on dates and total days var periodStartDateString = "2023-01-01"; // Dummy start date for calculations var daysFromIssue = newIssued > 0 && isValidDate(document.getElementById("sharesIssuedNewDate").value) ? dateToDays(document.getElementById("sharesIssuedNewDate").value, periodStartDateString) : 0; var daysFromRepurchase = repurchased > 0 && isValidDate(document.getElementById("sharesRepurchasedDate").value) ? dateToDays(document.getElementById("sharesRepurchasedDate").value, periodStartDateString) : 0; var issueEventDate = newIssued > 0 && isValidDate(document.getElementById("sharesIssuedNewDate").value) ? new Date(document.getElementById("sharesIssuedNewDate").value) : null; var repurchaseEventDate = repurchased > 0 && isValidDate(document.getElementById("sharesRepurchasedDate").value) ? new Date(document.getElementById("sharesRepurchasedDate").value) : null; var firstEventDate = null; if (issueEventDate && repurchaseEventDate) { firstEventDate = issueEventDate.getTime() 0 && isValidDate(document.getElementById("sharesIssuedNewDate").value)) { var issueDateObj = new Date(document.getElementById("sharesIssuedNewDate").value); var daysSinceIssue = dateToDays(document.getElementById("sharesIssuedNewDate").value, periodStartDateString); daysForIssuedSegment = totalDays – daysSinceIssue; } daysForIssuedSegment = Math.max(0, daysForIssuedSegment); var daysForRepurchasedSegment = 0; if (repurchased > 0 && isValidDate(document.getElementById("sharesRepurchasedDate").value)) { var repurchaseDateObj = new Date(document.getElementById("sharesRepurchasedDate").value); var daysSinceRepurchase = dateToDays(document.getElementById("sharesRepurchasedDate").value, periodStartDateString); daysForRepurchasedSegment = totalDays – daysSinceRepurchase; } daysForRepurchasedSegment = Math.max(0, daysForRepurchasedSegment); // Update table display with calculated weighted values and weights document.getElementById("tableDaysStart").innerText = initialSegmentDays; document.getElementById("tableWeightStart").innerText = (initialSegmentDays / totalDays * 100).toFixed(2) + "%"; document.getElementById("tableWeightedStart").innerText = (initialShares * (initialSegmentDays / totalDays)).toLocaleString(undefined, {maximumFractionDigits: 0}); document.getElementById("tableDaysIssued").innerText = daysForIssuedSegment; document.getElementById("tableWeightIssued").innerText = (daysForIssuedSegment / totalDays * 100).toFixed(2) + "%"; document.getElementById("tableWeightedIssued").innerText = weightedIssued.toLocaleString(undefined, {maximumFractionDigits: 0}); document.getElementById("tableDaysRepurchased").innerText = daysForRepurchasedSegment; document.getElementById("tableWeightRepurchased").innerText = (daysForRepurchasedSegment / totalDays * 100).toFixed(2) + "%"; document.getElementById("tableWeightedRepurchased").innerText = weightedRepurchased.toLocaleString(undefined, {maximumFractionDigits: 0}); document.getElementById("tableTotalWeightedAvg").innerText = totalWeightedAvg.toLocaleString(undefined, {maximumFractionDigits: 0}); } function updateAssumptions(initialShares, newIssued, newIssueDate, repurchased, repurchaseDate, totalDays) { var assumptionsList = document.getElementById("assumptions-list"); assumptionsList.innerHTML = "; // Clear previous assumptionsList.innerHTML += '
Initial Shares: ' + initialShares.toLocaleString() + '
'; assumptionsList.innerHTML += '
Reporting Period: ' + totalDays + ' days
'; if (newIssued > 0) { assumptionsList.innerHTML += '
New Shares Issued: ' + newIssued.toLocaleString() + ' on ' + newIssueDate + '
'; } if (repurchased > 0) { assumptionsList.innerHTML += '
Shares Repurchased: ' + repurchased.toLocaleString() + ' on ' + repurchaseDate + '
'; } document.getElementById("assumptions-container").style.display = 'block'; } function updateChartData(initialShares, newIssued, newIssueDate, repurchased, repurchaseDate, totalDays) { var labels = ["Start"]; var baselineData = [initialShares]; var activityData = [initialShares]; // For weighted average line var eventDates = []; if (newIssued > 0 && isValidDate(newIssueDate)) { eventDates.push({date: new Date(newIssueDate), type: 'issue', shares: newIssued}); } if (repurchased > 0 && isValidDate(repurchaseDate)) { eventDates.push({date: new Date(repurchaseDate), type: 'repurchase', shares: repurchased}); } eventDates.sort(function(a, b) { return a.date.getTime() – b.date.getTime(); }); var currentSharesForChart = initialShares; var lastDate = new Date("2023-01-01"); // Dummy start date for (var i = 0; i < eventDates.length; i++) { var event = eventDates[i]; var daysSinceLastEvent = Math.round((event.date.getTime() – lastDate.getTime()) / (1000 * 60 * 60 * 24)); labels.push(event.date.toISOString().slice(0, 10)); // Add date label if (event.type === 'issue') { currentSharesForChart += event.shares; } else if (event.type === 'repurchase') { currentSharesForChart -= event.shares; } activityData.push(currentSharesForChart); baselineData.push(currentSharesForChart); // Simplified: this assumes the baseline changes immediately lastDate = event.date; } labels.push("End"); // Add end label activityData.push(currentSharesForChart); // End value baselineData.push(currentSharesForChart); // End value // Ensure chart data has same length as labels while(baselineData.length < labels.length) baselineData.push(baselineData[baselineData.length – 1]); while(activityData.length < labels.length) activityData.push(activityData[activityData.length – 1]); if (sharesChart) { sharesChart.destroy(); } ctx = document.getElementById('sharesChart').getContext('2d'); sharesChart = new Chart(ctx, { type: 'line', data: { labels: labels, datasets: [{ label: 'Shares Outstanding (Actual)', data: baselineData, // Use baselineData for actual outstanding shares borderColor: 'rgb(75, 192, 192)', tension: 0.1, fill: false, stepped: true // Use stepped line for clarity }, { label: 'Weighted Average Shares', data: Array(labels.length).fill(parseFloat(document.getElementById("main-result").innerText.replace(/,/g, ''))), // Constant weighted average for simplicity in this chart type borderColor: 'rgb(255, 99, 132)', tension: 0, // No tension for weighted average fill: false, pointStyle: 'line', // Show as line, not points borderDash: [5, 5] }] }, options: { responsive: true, maintainAspectRatio: false, scales: { y: { beginAtZero: true, title: { display: true, text: 'Number of Shares' } }, x: { title: { display: true, text: 'Date' } } }, plugins: { legend: { display: true, position: 'top', }, title: { display: true, text: 'Share Activity Over Time' } } } }); } function resetCalculator() { document.getElementById("sharesIssuedInitial").value = "1000000"; document.getElementById("sharesIssuedNew").value = "0"; document.getElementById("sharesIssuedNewDate").value = "2023-01-01"; document.getElementById("sharesRepurchased").value = "0"; document.getElementById("sharesRepurchasedDate").value = "2023-01-01"; document.getElementById("reportingPeriod").value = "365"; calculateWeightedAverageShares(); // Recalculate with default values } function copyResults() { var mainResult = document.getElementById("main-result").innerText; var weightedIssued = document.getElementById("weightedSharesIssued").getElementsByClassName("value")[0].innerText; var weightedRepurchased = document.getElementById("weightedSharesRepurchased").getElementsByClassName("value")[0].innerText; var weightedAvg = document.getElementById("weightedAverageShares").getElementsByClassName("value")[0].innerText; var assumptions = "Key Assumptions:\n"; var assumptionItems = document.getElementById("assumptions-list").children; for (var i = 0; i < assumptionItems.length; i++) { assumptions += "- " + assumptionItems[i].innerText.replace(":", ": ") + "\n"; } var textToCopy = "Weighted Average Shares Calculation Results:\n\n"; textToCopy += "Main Result: " + mainResult + "\n"; textToCopy += "Weighted New Shares Issued: " + weightedIssued + "\n"; textToCopy += "Weighted Shares Repurchased: " + weightedRepurchased + "\n"; textToCopy += "Weighted Average Shares Outstanding: " + weightedAvg + "\n\n"; textToCopy += assumptions; navigator.clipboard.writeText(textToCopy).then(function() { // Success feedback can be added here, e.g., change button text briefly var originalText = document.querySelector('.btn-success').innerText; document.querySelector('.btn-success').innerText = 'Copied!'; setTimeout(function() { document.querySelector('.btn-success').innerText = originalText; }, 2000); }, function(err) { console.error('Could not copy text: ', err); // Handle error feedback }); } // Initial calculation on page load document.addEventListener("DOMContentLoaded", function() { resetCalculator(); // Set defaults and calculate }); // Add event listeners for real-time updates (optional, but good UX) document.getElementById("sharesIssuedInitial").addEventListener("input", calculateWeightedAverageShares); document.getElementById("sharesIssuedNew").addEventListener("input", calculateWeightedAverageShares); document.getElementById("sharesIssuedNewDate").addEventListener("change", calculateWeightedAverageShares); document.getElementById("sharesRepurchased").addEventListener("input", calculateWeightedAverageShares); document.getElementById("sharesRepurchasedDate").addEventListener("change", calculateWeightedAverageShares); document.getElementById("reportingPeriod").addEventListener("input", calculateWeightedAverageShares); // Ensure Chart.js is loaded before trying to use it // In a real WP setup, you'd enqueue this script. For a single file, assume it's available. // You would typically include Chart.js via a CDN: // // For this self-contained example, we assume Chart.js is somehow available. // If it's not, the chart part will fail.

Leave a Comment