27 Dec 2024

Advanced DCF Calculator

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Advanced DCF Calculator</title>
  <style>
    body {
      font-family: Arial, sans-serif;
      background-color: #f8f9fa;
      margin: 0;
      padding: 0;
    }
    .container {
      max-width: 800px;
      margin: 50px auto;
      background: #fff;
      padding: 20px;
      box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
      border-radius: 8px;
    }
    h1 {
      text-align: center;
      color: #333;
    }
    label {
      display: block;
      margin-top: 10px;
      font-weight: bold;
    }
    input, button {
      width: 100%;
      padding: 10px;
      margin-top: 5px;
      border: 1px solid #ddd;
      border-radius: 4px;
      font-size: 16px;
    }
    button {
      background-color: #007bff;
      color: white;
      cursor: pointer;
      border: none;
    }
    button:hover {
      background-color: #0056b3;
    }
    .result {
      margin-top: 20px;
      padding: 10px;
      background: #e9ecef;
      border-radius: 4px;
    }
    .error {
      color: red;
    }
  </style>
</head>
<body>
  <div class="container">
    <h1>Advanced DCF Calculator</h1>

    <label for="freeCashFlow">Free Cash Flow (In Crores):</label>
    <input type="number" id="freeCashFlow" placeholder="e.g., 100" />

    <label for="discountRate">Discount Rate (%):</label>
    <input type="number" id="discountRate" placeholder="e.g., 10" />

    <label for="growthRate1">Growth Rate (1 to 5 Year) (%):</label>
    <input type="number" id="growthRate1" placeholder="e.g., 5" />

    <label for="growthRate2">Growth Rate (6 to 10 Year) (%):</label>
    <input type="number" id="growthRate2" placeholder="e.g., 3" />

    <label for="cash">Cash (In Crores):</label>
    <input type="number" id="cash" placeholder="e.g., 50" />

    <label for="debt">Debt (In Crores):</label>
    <input type="number" id="debt" placeholder="e.g., 20" />

    <label for="marketCap">Market Cap Company (In Crores):</label>
    <input type="number" id="marketCap" placeholder="e.g., 200" />

    <label for="currentMarketPrice">Current Market Price (₹):</label>
    <input type="number" id="currentMarketPrice" placeholder="e.g., 500" />

    <label for="terminalGrowthRate">Terminal Growth Rate (GDP) (%):</label>
    <input type="number" id="terminalGrowthRate" placeholder="e.g., 2" />

    <label for="marginOfSafety">Margin of Safety (%):</label>
    <input type="number" id="marginOfSafety" placeholder="e.g., 20" />

    <button onclick="calculateAdvancedDCF()">Calculate DCF</button>

    <div class="result" id="result"></div>
  </div>

  <script>
    function calculateAdvancedDCF() {
      const freeCashFlow = parseFloat(document.getElementById('freeCashFlow').value);
      const discountRate = parseFloat(document.getElementById('discountRate').value) / 100;
      const growthRate1 = parseFloat(document.getElementById('growthRate1').value) / 100;
      const growthRate2 = parseFloat(document.getElementById('growthRate2').value) / 100;
      const cash = parseFloat(document.getElementById('cash').value);
      const debt = parseFloat(document.getElementById('debt').value);
      const terminalGrowthRate = parseFloat(document.getElementById('terminalGrowthRate').value) / 100;
      const marginOfSafety = parseFloat(document.getElementById('marginOfSafety').value) / 100;

      const resultDiv = document.getElementById('result');
      resultDiv.innerHTML = ""; // Clear previous results

      try {
        if (isNaN(freeCashFlow) || isNaN(discountRate) || isNaN(growthRate1) || isNaN(growthRate2) || isNaN(cash) || isNaN(debt) || isNaN(terminalGrowthRate) || isNaN(marginOfSafety)) {
          throw new Error('Please fill in all fields with valid values.');
        }

        // Calculate projected cash flows
        let dcf = 0;
        for (let year = 1; year <= 10; year++) {
          const growthRate = year <= 5 ? growthRate1 : growthRate2;
          const projectedCashFlow = freeCashFlow * Math.pow(1 + growthRate, year);
          dcf += projectedCashFlow / Math.pow(1 + discountRate, year);
        }

        // Add terminal value
        const terminalValue = (freeCashFlow * Math.pow(1 + growthRate2, 10) * (1 + terminalGrowthRate)) / (discountRate - terminalGrowthRate);
        dcf += terminalValue / Math.pow(1 + discountRate, 10);

        // Adjust for cash and debt
        dcf += cash - debt;

        // Apply margin of safety
        const intrinsicValue = dcf * (1 - marginOfSafety);

        // Display result
        resultDiv.innerHTML = `Intrinsic Value: <strong>₹${intrinsicValue.toFixed(2)}</strong>`;
      } catch (error) {
        resultDiv.innerHTML = `<p class='error'>${error.message}</p>`;
      }
    }
  </script>
</body>
</html>
Live Preview

You may also like

Creating a responsive calculator with HTML, CSS, and JavaScript

Create a responsive calculator with HTML, CSS, and JavaScript: follo...

Continue reading

Developing a Simple Calculator App with Python and PyQt

In this tutorial, we will guide you through the process of developin...

Continue reading

Building GUI Applications with Python and Tkinter

In this detailed blog post, we explore the process of building GUI a...

Continue reading