How to Calculate Depreciation on a Rental Property

How to Calculate Depreciation on a Rental Property | Free Calculator :root { –primary-color: #004a99; –success-color: #28a745; –background-color: #f8f9fa; –text-color: #333; –border-color: #ccc; –input-bg: #fff; –result-bg: #e9ecef; } 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: 20px; display: flex; flex-direction: column; align-items: center; } .main-container { width: 100%; max-width: 980px; background-color: #fff; padding: 30px; border-radius: 8px; box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08); margin-bottom: 40px; } h1, h2, h3 { color: var(–primary-color); text-align: center; margin-bottom: 20px; } h1 { font-size: 2.5em; margin-bottom: 30px; } h2 { font-size: 2em; margin-top: 40px; border-bottom: 2px solid var(–primary-color); padding-bottom: 10px; } h3 { font-size: 1.5em; margin-top: 30px; } .calculator-section { background-color: var(–background-color); padding: 30px; border-radius: 8px; margin-bottom: 30px; } .loan-calc-container { display: flex; flex-direction: column; gap: 20px; } .input-group { display: flex; flex-direction: column; gap: 8px; } .input-group label { font-weight: bold; color: var(–primary-color); } .input-group input, .input-group select { padding: 12px; border: 1px solid var(–border-color); border-radius: 4px; font-size: 1em; background-color: var(–input-bg); color: var(–text-color); box-sizing: border-box; } .input-group input:focus, .input-group select:focus { border-color: var(–primary-color); outline: none; box-shadow: 0 0 0 3px rgba(0, 74, 153, 0.2); } .helper-text { font-size: 0.85em; color: #6c757d; } .error-message { color: #dc3545; font-size: 0.85em; margin-top: 5px; display: none; } .button-group { display: flex; justify-content: space-between; margin-top: 25px; gap: 10px; } button { padding: 12px 20px; border: none; border-radius: 4px; font-size: 1em; font-weight: bold; cursor: pointer; transition: background-color 0.3s ease, transform 0.2s ease; background-color: var(–primary-color); color: #fff; flex: 1; } button:hover { background-color: #003366; transform: translateY(-1px); } button.reset-button { background-color: #6c757d; } button.reset-button:hover { background-color: #5a6268; } button.copy-button { background-color: var(–success-color); } button.copy-button:hover { background-color: #218838; } #results { margin-top: 30px; padding: 25px; background-color: var(–result-bg); border-radius: 8px; border: 1px solid #dee2e6; } #results h3 { margin-top: 0; color: var(–primary-color); } .main-result { font-size: 2em; font-weight: bold; color: var(–primary-color); text-align: center; margin-bottom: 15px; padding: 15px; background-color: #e9f7ff; border-radius: 6px; border: 1px dashed var(–primary-color); } .intermediate-results div, .formula-explanation { margin-bottom: 10px; font-size: 0.95em; } .intermediate-results span, .formula-explanation span { font-weight: bold; color: var(–primary-color); } .formula-explanation { background-color: #f0f0f0; padding: 10px; border-left: 4px solid var(–primary-color); margin-top: 20px; border-radius: 4px; } table { width: 100%; border-collapse: collapse; margin-top: 25px; margin-bottom: 25px; box-shadow: 0 2px 5px rgba(0,0,0,0.05); } th, td { padding: 12px 15px; text-align: left; border-bottom: 1px solid #ddd; } th { background-color: var(–primary-color); color: #fff; font-weight: bold; } tr:nth-child(even) { background-color: #f2f2f2; } tr:hover { background-color: #e9ecef; } caption { font-size: 1.1em; font-weight: bold; color: var(–primary-color); margin-bottom: 10px; text-align: left; } .chart-container { width: 100%; max-width: 700px; margin: 30px auto; text-align: center; background-color: var(–input-bg); padding: 20px; border-radius: 8px; box-shadow: 0 2px 8px rgba(0,0,0,0.05); } .chart-container canvas { max-width: 100%; height: auto; } .chart-legend { margin-top: 15px; font-size: 0.9em; color: #6c757d; } .chart-legend span { margin: 0 10px; } .chart-legend .legend-item { display: inline-block; margin: 0 5px; padding: 3px 8px; border-radius: 4px; } .chart-legend .legend-item.depreciated-value { background-color: #007bff; color: white; } .chart-legend .legend-item.remaining-value { background-color: #6c757d; color: white; } .article-section { margin-top: 40px; padding: 30px; background-color: #fff; border-radius: 8px; box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08); } .article-section p { margin-bottom: 15px; } .article-section ul, .article-section ol { margin-left: 20px; margin-bottom: 15px; } .article-section li { margin-bottom: 8px; } .article-section a { color: var(–primary-color); text-decoration: none; font-weight: bold; } .article-section a:hover { text-decoration: underline; } footer { text-align: center; margin-top: 40px; padding-top: 20px; border-top: 1px solid #eee; font-size: 0.9em; color: #6c757d; } #copy-success { display: none; color: var(–success-color); font-weight: bold; margin-top: 10px; text-align: center; } /* Responsive Adjustments */ @media (min-width: 768px) { .button-group { justify-content: flex-start; } .button-group button { width: auto; min-width: 150px; } }

How to Calculate Depreciation on a Rental Property

Unlock significant tax savings by accurately calculating depreciation on your rental property. Use our comprehensive tool and guide to understand the IRS rules and optimize your deductions.

Rental Property Depreciation Calculator

Enter the total cost to acquire the property (purchase price + certain closing costs). Do NOT include land value.
Estimate the portion of the cost basis attributable to the land, which is not depreciable.
Enter the cost of significant upgrades (new roof, HVAC, etc.) made after purchase.
Residential Rental Property Non-Residential (Commercial) Property Select the type of property for the correct recovery period.

Calculation Results

$0.00 / year
Depreciable Basis: $0.00
IRS Recovery Period: 0 years
Total Estimated Depreciation (over recovery period): $0.00
Formula Used:

Depreciable Basis = (Original Cost Basis + Capital Improvements) – Land Value. Annual Depreciation = Depreciable Basis / IRS Recovery Period. The IRS recovery periods are 27.5 years for residential rental property and 39 years for non-residential real property.

Results copied successfully!

Depreciation Over Time

Depreciated Value Remaining Value

Chart showing the decrease in the property's depreciated value and the remaining book value over its recovery period.

What is Rental Property Depreciation?

Rental property depreciation is a tax deduction that allows property owners to recover the cost of their investment in a rental property over time. It's not an actual cash expense, but rather an accounting method that reflects the wear and tear, deterioration, or obsolescence of the property. By claiming depreciation, you can reduce your taxable rental income, thereby lowering your overall tax liability. This is a crucial concept for real estate investors looking to maximize their returns. Understanding how to calculate depreciation on a rental property is fundamental to effective tax planning.

Who should use it? Any individual or entity that owns and rents out real estate (residential or commercial) can claim depreciation. This includes landlords, real estate investment trusts (REITs), and businesses that own rental properties. Even if the property is generating a loss, depreciation can help offset other income, depending on passive activity loss rules. It's essential to consult with a tax professional to ensure compliance and maximize benefits.

Common Misconceptions:

  • Depreciation is a cash expense: This is incorrect. It's a non-cash deduction used for tax purposes.
  • You depreciate the land: Land cannot be depreciated. Only the building and certain improvements are eligible.
  • Depreciation stops when the property is fully depreciated: While you can't take further depreciation deductions once the book value reaches zero, the property's tax basis continues to be tracked for capital gains calculations upon sale.
  • Depreciation always reduces cash flow: While it reduces taxable income, it doesn't impact immediate cash in hand. It's a tax benefit, not an operating expense.

Mastering how to calculate depreciation on a rental property correctly is key to leveraging this powerful tax advantage.

Rental Property Depreciation Formula and Mathematical Explanation

The core principle behind calculating depreciation for tax purposes is the Straight-Line Depreciation method, which is the most common for real estate. This method spreads the cost of the asset evenly over its useful life (its recovery period). Here's the breakdown of how to calculate depreciation on a rental property:

Step 1: Determine the Depreciable Basis

The depreciable basis is the portion of your property's cost that you can actually depreciate. It excludes the value of the land, as land is not considered to have a determinable useful life and therefore is not depreciable.

Formula:

Depreciable Basis = (Original Cost Basis + Cost of Capital Improvements) - Estimated Land Value

Step 2: Determine the IRS Recovery Period

The IRS assigns specific recovery periods (useful lives) for different types of property. For rental properties:

  • Residential Rental Property: 27.5 years
  • Non-Residential (Commercial) Real Property: 39 years

Step 3: Calculate Annual Depreciation

Once you have the depreciable basis and the recovery period, you can calculate the annual depreciation deduction.

Formula:

Annual Depreciation = Depreciable Basis / IRS Recovery Period

Variables Explained:

Let's break down the components involved in how to calculate depreciation on a rental property:

Variable Definitions for Depreciation Calculation
Variable Meaning Unit Typical Range
Original Cost Basis The total cost incurred to acquire the property. This includes the purchase price plus certain non-deductible closing costs (e.g., title fees, legal fees, surveys, title insurance). It excludes costs related to land acquisition. Currency ($) Varies widely based on location and property size. Can be hundreds of thousands to millions.
Estimated Land Value The portion of the total acquisition cost that is attributable to the land only. This is often determined by comparing assessed property values or obtaining a professional appraisal. Currency ($) Typically 10-30% of the total property value, but highly variable.
Cost of Capital Improvements Expenses that add value to the property, prolong its life, or adapt it to new uses. Examples include new roofs, HVAC systems, major renovations, or additions. Routine repairs and maintenance are expensed, not capitalized. Currency ($) $0 to potentially tens or hundreds of thousands, depending on the scope of work.
IRS Recovery Period The IRS-mandated number of years over which the property can be depreciated. Based on property type. Years 27.5 years (Residential) or 39 years (Non-Residential).
Depreciable Basis The net cost of the property eligible for depreciation after subtracting land value and adding improvements. Currency ($) Can range from a fraction of the original cost to significantly more if substantial improvements are added.
Annual Depreciation The amount of depreciation expense that can be deducted each year for tax purposes. Currency ($) per year Depends on Depreciable Basis and Recovery Period. Typically a few thousand dollars annually for average properties.

Properly calculating the depreciable basis is crucial for accurate how to calculate depreciation on a rental property.

Practical Examples (Real-World Use Cases)

Example 1: Residential Rental Property Purchase

Sarah buys a small apartment building for $400,000. Her closing costs associated with the building itself (excluding land survey and legal fees related to land title) were $10,000. An appraisal indicates the land is worth $80,000. She made $15,000 in immediate upgrades (new paint and flooring).

Inputs:

  • Original Cost Basis: $400,000
  • Associated Closing Costs: $10,000
  • Estimated Land Value: $80,000
  • Capital Improvements: $15,000
  • Property Type: Residential Rental Property

Calculation:

  • Total Acquisition Cost = $400,000 + $10,000 = $410,000
  • Depreciable Basis = $410,000 – $80,000 (Land) + $15,000 (Improvements) = $345,000
  • IRS Recovery Period = 27.5 years (Residential)
  • Annual Depreciation = $345,000 / 27.5 = $12,545.45

Result: Sarah can deduct $12,545.45 annually for depreciation for this property over 27.5 years. This significantly reduces her taxable rental income.

Example 2: Commercial Property with Major Renovation

John owns a commercial warehouse purchased 5 years ago for $1,000,000, with land valued at $200,000. Last year, he invested $100,000 in a new roof and an upgraded sprinkler system (capital improvements).

Inputs:

  • Original Cost Basis: $1,000,000
  • Estimated Land Value: $200,000
  • Capital Improvements: $100,000
  • Property Type: Non-Residential (Commercial) Property

Calculation:

  • Depreciable Basis = $1,000,000 – $200,000 (Land) + $100,000 (Improvements) = $900,000
  • IRS Recovery Period = 39 years (Non-Residential)
  • Annual Depreciation = $900,000 / 39 = $23,076.92

Result: John can deduct approximately $23,076.92 annually for depreciation on his commercial property. If he had claimed depreciation previously on the original structure, the remaining basis and recovery period would need adjustment (this calculator assumes starting fresh or adding improvements to a basis already adjusted for prior depreciation).

These examples illustrate the practical application of how to calculate depreciation on a rental property and its impact on potential tax savings.

How to Use This Rental Property Depreciation Calculator

Our free online calculator simplifies the process of determining your potential annual depreciation deduction. Follow these simple steps:

  1. Enter Property Cost Basis: Input the total amount you paid for the property, including relevant closing costs. Ensure you exclude the value of the land itself.
  2. Input Land Value: Provide your best estimate of the land's worth. If unsure, consult property tax records or a local real estate agent. Remember, land is not depreciable.
  3. Add Capital Improvements: If you've made significant upgrades (like a new roof, HVAC system, or major renovations) that add value or extend the property's life, enter their total cost here. For routine maintenance or repairs, do not include them. If none, leave as 0.
  4. Select Property Type: Choose 'Residential Rental Property' (27.5-year recovery period) or 'Non-Residential (Commercial) Property' (39-year recovery period).
  5. View Results: The calculator will instantly display:
    • Depreciable Basis: The total cost eligible for depreciation.
    • IRS Recovery Period: The set number of years for depreciation.
    • Annual Depreciation: Your estimated yearly tax deduction.
    • Total Estimated Depreciation: The cumulative deduction over the full recovery period.

Reading Your Results: The main highlighted result shows your estimated annual depreciation deduction. The intermediate values provide the crucial components leading to this figure. The formula explanation clarifies the calculation method.

Decision-Making Guidance: Use these figures to estimate your net rental income and potential tax savings. Remember, this is a deduction that reduces your taxable income, not a cash outflow. Accurate depreciation can significantly improve your real estate investment's profitability. Always consult a tax professional for personalized advice, especially regarding specific IRS rules and your unique financial situation. For more insights, explore our rental income tax guide.

Key Factors That Affect Depreciation Results

Several factors influence the depreciation amount you can claim. Understanding these is vital for accurate how to calculate depreciation on a rental property:

  1. Original Purchase Price & Acquisition Costs: The higher your initial investment (purchase price plus capitalizable closing costs), the larger the potential depreciable basis, assuming land value is accounted for correctly.
  2. Land Value Allocation: This is critical. An overestimation of land value directly reduces your depreciable basis. Conversely, underestimating it could lead to claiming deductions you're not entitled to. Professional appraisals or local market data are essential.
  3. Capital Improvements vs. Repairs: Capital improvements (e.g., adding a room, replacing the entire electrical system) increase the depreciable basis and are depreciated over their own lifespan or added to the property's basis. Routine repairs (e.g., fixing a leaky faucet, painting a single room) are expensed in the year incurred and do not affect the basis for depreciation. Properly categorizing these costs is paramount.
  4. Property Type: As detailed, residential rental properties have a 27.5-year recovery period, while non-residential properties have a 39-year period. This directly impacts the annual deduction amount – a shorter period yields a larger annual deduction.
  5. Depreciation Method (Mid-Month Convention): For properties placed in service (rented out) or disposed of during the year, the IRS often requires the mid-month convention. This means you only deduct depreciation for the portion of the year the property was in service, using a method that treats the property as if it was placed in service or disposed of in the middle of the month. This slightly reduces the first and last year's depreciation deduction.
  6. Tax Law Changes: Depreciation rules can be modified by tax legislation. For instance, bonus depreciation or Section 179 deductions might apply to certain improvements, allowing for faster write-offs, though these have specific limitations and eligibility requirements. Staying informed or working with a tax advisor is crucial. For more detailed strategies, consider our guide to maximizing real estate tax deductions.
  7. Prior Depreciation Already Taken: If you've owned the property for some time, you've already claimed depreciation. Your current depreciable basis is the original depreciable basis minus the total depreciation previously claimed. This calculator assumes a fresh calculation or addition of new improvements, but in reality, you must track cumulative depreciation. This is a key aspect of understanding rental property tax basis.

Frequently Asked Questions (FAQ)

Q1: Can I claim depreciation on a property I live in?

No, you can only claim depreciation on properties that are used to produce rental income. Personal residences do not qualify.

Q2: What if I convert my primary residence into a rental property?

When you convert your home to a rental, the cost basis for depreciation becomes the *lesser* of its fair market value on the date of conversion or its original cost basis (plus any capital improvements made before the conversion). You start depreciating from the date it's converted and available for rent.

Q3: Do I need to depreciate the land?

Absolutely not. The IRS explicitly prohibits the depreciation of land because it is considered to have an unlimited useful life. Only the structures and improvements on the land are depreciable.

Q4: What counts as a "capital improvement" versus a "repair"?

Capital improvements add value, significantly extend the property's life, or adapt it to a new use (e.g., adding a bathroom, replacing the entire roof). Repairs maintain the property's current condition (e.g., fixing a broken window, patching drywall, repainting). Improvements are depreciated; repairs are expensed in the year incurred.

Q5: What happens to depreciation when I sell the property?

When you sell the rental property, you must "recapture" all the depreciation you claimed (or were entitled to claim) during the time you owned it. This recaptured depreciation is typically taxed at a rate of 25% (up to the amount of your gain), rather than your potentially lower long-term capital gains rate. Understanding your property's adjusted cost basis is crucial for calculating capital gains tax.

Q6: Can I claim depreciation if I didn't make any profit last year?

Yes, you can often still claim depreciation even if the property had a net loss for the year. However, passive activity loss (PAL) rules may limit your ability to deduct these losses against other types of income (like W-2 wages). Unused losses are typically carried forward to future years or the year of sale. Consult a tax professional about PAL rules.

Q7: Is straight-line depreciation the only method?

For most rental properties, straight-line depreciation is the required method mandated by the IRS. Accelerated depreciation methods were historically available for certain types of property but are generally not applicable to standard real estate rentals today. For specific improvements, other rules might apply, but the property itself uses straight-line.

Q8: How do I track depreciation year over year?

Maintain meticulous records of your property's acquisition costs, land value, all capital improvements, and the annual depreciation claimed. This information is essential for calculating your adjusted cost basis and the depreciation recapture tax upon sale. Real estate accounting software or a good spreadsheet system is highly recommended. Referencing our guide on real estate record-keeping can be beneficial.

Related Tools and Internal Resources

© 2023 Your Financial Website. All rights reserved. The information provided is for educational purposes only and does not constitute tax or legal advice. Consult with a qualified professional for advice tailored to your specific situation.

function validateInput(id, errorId, minValue = null, maxValue = null) { var input = document.getElementById(id); var errorElement = document.getElementById(errorId); var value = parseFloat(input.value); if (isNaN(value)) { errorElement.textContent = "Please enter a valid number."; errorElement.style.display = "block"; input.style.borderColor = "#dc3545"; return false; } if (minValue !== null && value maxValue) { errorElement.textContent = "Value cannot be greater than " + maxValue.toLocaleString() + "."; errorElement.style.display = "block"; input.style.borderColor = "#dc3545"; return false; } errorElement.textContent = ""; errorElement.style.display = "none"; input.style.borderColor = "#ced4da"; return true; } function calculateDepreciation() { var propertyCost = parseFloat(document.getElementById("propertyCost").value) || 0; var landValue = parseFloat(document.getElementById("landValue").value) || 0; var improvementCost = parseFloat(document.getElementById("improvementCost").value) || 0; var propertyType = document.getElementById("propertyType").value; var validPropertyCost = validateInput("propertyCost", "propertyCostError", 0); var validLandValue = validateInput("landValue", "landValueError", 0); var validImprovementCost = validateInput("improvementCost", "improvementCostError", 0); if (!validPropertyCost || !validLandValue || !validImprovementCost) { resetResults(); return; } var totalAcquisitionCost = propertyCost; // Assuming propertyCost includes direct purchase + associated closing costs for simplicity as per prompt's need to remove '$' from inputs unless they are costs. If separate closing costs input was needed, it would be added here. if (totalAcquisitionCost 0) { annualDepreciation = depreciableBasis / recoveryPeriod; } var totalDepreciation = annualDepreciation * recoveryPeriod; // Simplified for full period document.getElementById("annualDepreciationResult").textContent = "$" + annualDepreciation.toFixed(2) + " / year"; document.getElementById("depreciableBasis").innerHTML = "Depreciable Basis: $" + depreciableBasis.toFixed(2); document.getElementById("recoveryPeriod").innerHTML = "IRS Recovery Period: " + recoveryPeriodLabel; document.getElementById("totalDepreciation").innerHTML = "Total Estimated Depreciation (over recovery period): $" + totalDepreciation.toFixed(2); updateChart(depreciableBasis, recoveryPeriod, annualDepreciation); } function resetResults() { document.getElementById("annualDepreciationResult").textContent = "$0.00 / year"; document.getElementById("depreciableBasis").innerHTML = "Depreciable Basis: $0.00″; document.getElementById("recoveryPeriod").innerHTML = "IRS Recovery Period: 0 years"; document.getElementById("totalDepreciation").innerHTML = "Total Estimated Depreciation (over recovery period): $0.00″; } function resetCalculator() { document.getElementById("propertyCost").value = ""; document.getElementById("landValue").value = ""; document.getElementById("improvementCost").value = 0; document.getElementById("propertyType").value = "residential"; document.getElementById("propertyCostError").textContent = ""; document.getElementById("propertyCostError").style.display = "none"; document.getElementById("landValueError").textContent = ""; document.getElementById("landValueError").style.display = "none"; document.getElementById("improvementCostError").textContent = ""; document.getElementById("improvementCostError").style.display = "none"; document.getElementById("propertyCost").style.borderColor = "#ced4da"; document.getElementById("landValue").style.borderColor = "#ced4da"; document.getElementById("improvementCost").style.borderColor = "#ced4da"; resetResults(); // Clear chart var ctx = document.getElementById('depreciationChart').getContext('2d'); ctx.clearRect(0, 0, ctx.canvas.width, ctx.canvas.height); document.getElementById('chart-caption').textContent = "Chart showing the decrease in the property's depreciated value and the remaining book value over its recovery period."; } function copyResults() { var annualResult = document.getElementById("annualDepreciationResult").textContent; var depreciableBasis = document.getElementById("depreciableBasis").innerText; var recoveryPeriod = document.getElementById("recoveryPeriod").innerText; var totalDepreciation = document.getElementById("totalDepreciation").innerText; var propertyCostInput = document.getElementById("propertyCost").value; var landValueInput = document.getElementById("landValue").value; var improvementCostInput = document.getElementById("improvementCost").value; var propertyTypeSelect = document.getElementById("propertyType"); var propertyType = propertyTypeSelect.options[propertyTypeSelect.selectedIndex].text; var assumptions = "Key Assumptions:\n"; assumptions += "- Original Cost Basis: $" + (propertyCostInput || 'N/A') + "\n"; assumptions += "- Estimated Land Value: $" + (landValueInput || 'N/A') + "\n"; assumptions += "- Capital Improvements: $" + (improvementCostInput || '0') + "\n"; assumptions += "- Property Type: " + propertyType + "\n\n"; var textToCopy = "Rental Property Depreciation Calculation Results:\n\n" + annualResult + "\n" + depreciableBasis + "\n" + recoveryPeriod + "\n" + totalDepreciation + "\n\n" + assumptions + "Formula: Annual Depreciation = (Cost Basis + Improvements – Land Value) / Recovery Period"; navigator.clipboard.writeText(textToCopy).then(function() { var successMessage = document.getElementById("copy-success"); successMessage.style.display = "block"; setTimeout(function() { successMessage.style.display = "none"; }, 3000); }).catch(function(err) { console.error("Failed to copy results: ", err); alert("Could not copy results. Please copy manually."); }); } function updateChart(depreciableBasis, recoveryPeriod, annualDepreciation) { var canvas = document.getElementById('depreciationChart'); var ctx = canvas.getContext('2d'); // Clear previous chart ctx.clearRect(0, 0, canvas.width, canvas.height); if (depreciableBasis <= 0 || recoveryPeriod <= 0 || annualDepreciation <= 0) { document.getElementById('chart-caption').textContent = "Enter valid property details to see the depreciation chart."; return; } document.getElementById('chart-caption').textContent = "Chart showing the decrease in the property's depreciated value and the remaining book value over its recovery period."; var chartWidth = canvas.width; var chartHeight = canvas.height; var margin = 40; // Space for labels var plotWidth = chartWidth – 2 * margin; var plotHeight = chartHeight – 2 * margin; var years = []; var depreciatedValues = []; var remainingValues = []; var currentRemaining = depreciableBasis; for (var i = 0; i depreciableBasis) { currentDepreciation = depreciableBasis; } depreciatedValues.push(currentDepreciation); remainingValues.push(depreciableBasis – currentDepreciation); } // Draw Axes ctx.strokeStyle = '#aaa'; ctx.lineWidth = 1; // X-axis (Year) ctx.beginPath(); ctx.moveTo(margin, chartHeight – margin); ctx.lineTo(chartWidth – margin, chartHeight – margin); ctx.stroke(); // Y-axis (Value) ctx.beginPath(); ctx.moveTo(margin, margin); ctx.lineTo(margin, chartHeight – margin); ctx.stroke(); // Y-axis labels and ticks var yMax = depreciableBasis; var numYTicks = 5; for (var i = 0; i <= numYTicks; i++) { var yPos = chartHeight – margin – (i / numYTicks) * plotHeight; var yValue = Math.round((i / numYTicks) * yMax); ctx.fillStyle = '#6c757d'; ctx.textAlign = 'right'; ctx.fillText(yValue.toFixed(0), margin – 10, yPos); ctx.beginPath(); ctx.moveTo(margin – 5, yPos); ctx.lineTo(margin, yPos); ctx.stroke(); } // X-axis labels and ticks var numXTicks = Math.min(10, recoveryPeriod); // Max 10 ticks or actual recovery period for (var i = 0; i recoveryPeriod) xValue = recoveryPeriod; // Ensure last label is exactly recoveryPeriod ctx.fillStyle = '#6c757d'; ctx.textAlign = 'center'; ctx.fillText(xValue, xPos, chartHeight – margin + 15); ctx.beginPath(); ctx.moveTo(xPos, chartHeight – margin); ctx.lineTo(xPos, chartHeight – margin + 5); ctx.stroke(); } // Draw Lines // Depreciated Value Line ctx.strokeStyle = '#007bff'; // Blue for depreciated value ctx.lineWidth = 2; ctx.beginPath(); for (var i = 0; i < years.length; i++) { var xPos = margin + (years[i] / recoveryPeriod) * plotWidth; var yPos = chartHeight – margin – (depreciatedValues[i] / yMax) * plotHeight; if (i === 0) { ctx.moveTo(xPos, yPos); } else { ctx.lineTo(xPos, yPos); } } ctx.stroke(); // Remaining Value Line ctx.strokeStyle = '#6c757d'; // Gray for remaining value ctx.lineWidth = 2; ctx.beginPath(); for (var i = 0; i < years.length; i++) { var xPos = margin + (years[i] / recoveryPeriod) * plotWidth; var yPos = chartHeight – margin – (remainingValues[i] / yMax) * plotHeight; if (i === 0) { ctx.moveTo(xPos, yPos); } else { ctx.lineTo(xPos, yPos); } } ctx.stroke(); } // Initial calculation on load document.addEventListener('DOMContentLoaded', function() { // Set default values or run calculation immediately if defaults are set document.getElementById("improvementCost").value = 0; // Set default improvement cost to 0 calculateDepreciation(); // Ensure proper initial error states are reset if inputs are empty var inputs = document.querySelectorAll('.loan-calc-container input[type="number"]'); inputs.forEach(function(input) { if (input.value === "") { var errorId = input.id + "Error"; var errorElement = document.getElementById(errorId); if (errorElement) { errorElement.textContent = ""; errorElement.style.display = "none"; input.style.borderColor = "#ced4da"; } } }); });

Leave a Comment