claude.ai/public/artifacts/321e55e7-acfa-464f-af55-745d7db60661
import React, { useState, useMemo } from ‘react’;
import { LineChart, Line, XAxis, YAxis, CartesianGrid, Tooltip, Legend, ResponsiveContainer, BarChart, Bar, Area, AreaChart } from ‘recharts’;
import { DollarSign, TrendingUp, Calendar, Target, Building2, Shield, ArrowRightLeft } from ‘lucide-react’;
const IncomeReplacementCalculator = () => {
const [activeTab, setActiveTab] = useState(‘overview’);
const [showPortfolioTheory, setShowPortfolioTheory] = useState(false);
const [inputs, setInputs] = useState({
currentAge: 36,
targetAge: 50,
currentSalary: 75000,
currentPortfolio: 100000,
annualContribution: 20000,
targetAnnualReturn: 8,
dividendYield: 4,
inflationRate: 3,
// Exit Strategy Inputs
realEstateValue: 250000,
realEstateAppreciation: 4,
rentalYield: 6,
exchange1031Age: 42,
// Trust & Tax Inputs
useTrust: true,
trustType: ‘revocable’,
capitalGainsTaxRate: 15,
estateTaxExemption: 13610000,
// Options Strategy
useOptionsStrategy: false,
coveredCallPremium: 2,
optionsFrequency: 12,
// Portfolio Theory Inputs
securitiesVolatility: 15,
realEstateVolatility: 10,
correlationCoefficient: 0.3
});
const handleInputChange = (field, value) => {
setInputs(prev => ({
…prev,
[field]: typeof value === ‘boolean’ ? value : (parseFloat(value) || 0)
}));
};
const calculations = useMemo(() => {
const years = inputs.targetAge – inputs.currentAge;
const yearlyData = [];
const exitStrategyData = [];
const portfolioTheoryData = [];
“`
let portfolio = inputs.currentPortfolio;
let realEstate = inputs.realEstateValue;
let adjustedSalary = inputs.currentSalary;
let exchangedProperty = 0;
let totalTaxDeferred = 0;
// Calculate optimal portfolio weights using Modern Portfolio Theory
const R1 = inputs.targetAnnualReturn; // Securities return
const R2 = inputs.realEstateAppreciation + inputs.rentalYield; // Real estate total return
const sigma1 = inputs.securitiesVolatility; // Securities volatility
const sigma2 = inputs.realEstateVolatility; // Real estate volatility
const rho = inputs.correlationCoefficient; // Correlation
// Generate efficient frontier data points
for (let w1 = 0; w1 <= 1; w1 += 0.05) {
const w2 = 1 - w1;
// Portfolio return: Rp = w1*R1 + w2*R2
const Rp = w1 * R1 + w2 * R2;
// Portfolio variance: σp² = w1²σ1² + w2²σ2² + 2w1w2ρσ1σ2
const varianceP = Math.pow(w1, 2) * Math.pow(sigma1, 2) +
Math.pow(w2, 2) * Math.pow(sigma2, 2) +
2 * w1 * w2 * rho * sigma1 * sigma2;
const sigmaP = Math.sqrt(varianceP);
// Sharpe ratio (assuming risk-free rate of 4%)
const riskFreeRate = 4;
const sharpeRatio = (Rp - riskFreeRate) / sigmaP;
portfolioTheoryData.push({
w1: Math.round(w1 * 100),
w2: Math.round(w2 * 100),
expectedReturn: Math.round(Rp * 100) / 100,
portfolioVolatility: Math.round(sigmaP * 100) / 100,
sharpeRatio: Math.round(sharpeRatio * 100) / 100
});
}
// Find optimal portfolio (max Sharpe ratio)
const optimalPortfolio = portfolioTheoryData.reduce((max, curr) =>
curr.sharpeRatio > max.sharpeRatio ? curr : max
);
for (let year = 0; year <= years; year++) {
const age = inputs.currentAge + year;
// Salary adjustment
adjustedSalary = inputs.currentSalary * Math.pow(1 + inputs.inflationRate / 100, year);
// Portfolio growth with contributions
if (year > 0) {
portfolio = portfolio * (1 + inputs.targetAnnualReturn / 100) + inputs.annualContribution;
}
// Real estate appreciation
if (year > 0) {
realEstate = realEstate * (1 + inputs.realEstateAppreciation / 100);
}
// 1031 Exchange at specified age
let exchange1031Executed = false;
if (age === inputs.exchange1031Age && exchangedProperty === 0) {
exchange1031Executed = true;
const capitalGain = realEstate – inputs.realEstateValue;
totalTaxDeferred = capitalGain * (inputs.capitalGainsTaxRate / 100);
exchangedProperty = realEstate;
// Assume reinvestment into higher-yielding property
realEstate = realEstate * 1.1; // 10% upgrade
}
// Income calculations
const annualDividendIncome = portfolio * (inputs.dividendYield / 100);
const annualRentalIncome = realEstate * (inputs.rentalYield / 100);
// Options premium if strategy enabled
const optionsPremium = inputs.useOptionsStrategy ?
(portfolio * (inputs.coveredCallPremium / 100)) : 0;
const totalInvestmentIncome = annualDividendIncome + annualRentalIncome + optionsPremium;
// Quarterly and daily breakdowns
const quarterlyIncome = totalInvestmentIncome / 4;
const dailyIncome = totalInvestmentIncome / 252;
// Income replacement percentage
const incomeReplacementPct = (totalInvestmentIncome / adjustedSalary) * 100;
// Required portfolio for full replacement
const requiredPortfolio = adjustedSalary / (inputs.dividendYield / 100);
// Trust considerations
const trustProtectedAssets = inputs.useTrust ? (portfolio + realEstate) : 0;
const estateTaxLiability = Math.max(0, (portfolio + realEstate – inputs.estateTaxExemption) * 0.4);
yearlyData.push({
age,
year,
portfolio: Math.round(portfolio),
realEstate: Math.round(realEstate),
totalAssets: Math.round(portfolio + realEstate),
salary: Math.round(adjustedSalary),
dividendIncome: Math.round(annualDividendIncome),
rentalIncome: Math.round(annualRentalIncome),
optionsPremium: Math.round(optionsPremium),
totalInvestmentIncome: Math.round(totalInvestmentIncome),
incomeReplacementPct: Math.round(incomeReplacementPct * 10) / 10,
requiredPortfolio: Math.round(requiredPortfolio),
gap: Math.round(requiredPortfolio – portfolio),
dailyIncome: Math.round(dailyIncome),
quarterlyIncome: Math.round(quarterlyIncome),
trustProtectedAssets: Math.round(trustProtectedAssets),
estateTaxLiability: Math.round(estateTaxLiability),
exchange1031Executed,
taxDeferred: Math.round(totalTaxDeferred)
});
// Exit strategy milestones
if (incomeReplacementPct >= 50 || incomeReplacementPct >= 75 || incomeReplacementPct >= 100) {
exitStrategyData.push({
age,
milestone: incomeReplacementPct >= 100 ? ‘Full Independence’ :
incomeReplacementPct >= 75 ? ‘Partial Retirement’ :
‘Reduced Hours’,
incomeReplacement: Math.round(incomeReplacementPct),
portfolioValue: Math.round(portfolio + realEstate)
});
}
}
return { yearlyData, exitStrategyData, portfolioTheoryData, optimalPortfolio };
“`
}, [inputs]);
const finalYear = calculations.yearlyData[calculations.yearlyData.length – 1];
const currentYear = calculations.yearlyData[0];
return (
Comprehensive Income Replacement & Exit Strategy
Multi-asset income modeling with 1031 exchanges, trust structures, and options strategies
“`
{/* Tab Navigation */}
))}
{/* OVERVIEW TAB */}
{activeTab === ‘overview’ && (
<>
{/* Key Metrics */}
Current (Age {inputs.currentAge})
Target (Age {inputs.targetAge})
Total Assets
Annual Income
{/* Multi-Asset Growth Chart */}
Multi-Asset Portfolio Growth
contentStyle={{ backgroundColor: ‘#ffffff’, border: ‘1px solid #cbd5e1’, borderRadius: ‘8px’ }}
/>
{/* Income Sources Breakdown */}
Income Sources Over Time
contentStyle={{ backgroundColor: ‘#ffffff’, border: ‘1px solid #cbd5e1’, borderRadius: ‘8px’ }}
/>
{inputs.useOptionsStrategy && (
)}
>
)}
{/* INPUTS TAB */}
{activeTab === ‘inputs’ && (
Basic Parameters
handleInputChange(‘currentAge’, e.target.value)}
className=”w-full px-3 py-2 border border-slate-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent”
/>
handleInputChange(‘targetAge’, e.target.value)}
className=”w-full px-3 py-2 border border-slate-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent”
/>
handleInputChange(‘currentSalary’, e.target.value)}
className=”w-full px-3 py-2 border border-slate-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent”
/>
handleInputChange(‘currentPortfolio’, e.target.value)}
className=”w-full px-3 py-2 border border-slate-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent”
/>
handleInputChange(‘annualContribution’, e.target.value)}
className=”w-full px-3 py-2 border border-slate-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent”
/>
handleInputChange(‘targetAnnualReturn’, e.target.value)}
className=”w-full px-3 py-2 border border-slate-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent”
/>
handleInputChange(‘dividendYield’, e.target.value)}
className=”w-full px-3 py-2 border border-slate-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent”
/>
handleInputChange(‘inflationRate’, e.target.value)}
className=”w-full px-3 py-2 border border-slate-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent”
/>
{/* Real Estate & 1031 */}
Real Estate & 1031 Exchange
handleInputChange(‘realEstateValue’, e.target.value)}
className=”w-full px-3 py-2 border border-slate-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent”
/>
handleInputChange(‘realEstateAppreciation’, e.target.value)}
className=”w-full px-3 py-2 border border-slate-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent”
/>
handleInputChange(‘rentalYield’, e.target.value)}
className=”w-full px-3 py-2 border border-slate-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent”
/>
handleInputChange(‘exchange1031Age’, e.target.value)}
className=”w-full px-3 py-2 border border-slate-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent”
/>
{/* Options Strategy */}
Options Enhancement Strategy
{inputs.useOptionsStrategy && (
handleInputChange(‘coveredCallPremium’, e.target.value)}
className=”w-full px-3 py-2 border border-slate-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent”
/>
handleInputChange(‘optionsFrequency’, e.target.value)}
className=”w-full px-3 py-2 border border-slate-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent”
/>
)}
{/* Trust & Tax Settings */}
Trust & Tax Configuration
handleInputChange(‘capitalGainsTaxRate’, e.target.value)}
className=”w-full px-3 py-2 border border-slate-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent”
/>
handleInputChange(‘estateTaxExemption’, e.target.value)}
className=”w-full px-3 py-2 border border-slate-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent”
/>
{/* Portfolio Theory Parameters */}
Modern Portfolio Theory Parameters
handleInputChange(‘securitiesVolatility’, e.target.value)}
className=”w-full px-3 py-2 border border-slate-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent”
/>
handleInputChange(‘realEstateVolatility’, e.target.value)}
className=”w-full px-3 py-2 border border-slate-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent”
/>
handleInputChange(‘correlationCoefficient’, e.target.value)}
className=”w-full px-3 py-2 border border-slate-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent”
/>
Note on Volatility & Correlation:
Volatility (σ) measures risk/uncertainty. Correlation (ρ) ranges from -1 (perfect negative) to +1 (perfect positive). Lower correlation between assets provides better diversification benefits.
)}
{/* PORTFOLIO THEORY TAB */}
{activeTab === ‘portfolio-theory’ && (
Modern Portfolio Theory – Two Asset Model
Mathematical Framework
Asset 1 (Securities): return R₁, volatility σ₁, weight w₁
Asset 2 (Real Estate): return R₂, volatility σ₂, weight w₂
Constraint: w₁ + w₂ = 1
Portfolio Return:
Rₚ = w₁R₁ + w₂R₂
Portfolio Variance:
σₚ² = w₁²σ₁² + w₂²σ₂² + 2w₁w₂ρσ₁σ₂
where ρ is the correlation coefficient between asset returns
{/* Optimal Portfolio Display */}
Optimal Portfolio (Max Sharpe Ratio)
Securities Weight: {calculations.optimalPortfolio.w1}%
Real Estate Weight: {calculations.optimalPortfolio.w2}%
Expected Return: {calculations.optimalPortfolio.expectedReturn}%
Portfolio Risk (σₚ): {calculations.optimalPortfolio.portfolioVolatility}%
Sharpe Ratio: {calculations.optimalPortfolio.sharpeRatio}
Current Portfolio Allocation
Securities: {Math.round((inputs.currentPortfolio / (inputs.currentPortfolio + inputs.realEstateValue)) * 100)}%
Real Estate: {Math.round((inputs.realEstateValue / (inputs.currentPortfolio + inputs.realEstateValue)) * 100)}%
Securities: ${inputs.currentPortfolio.toLocaleString()}
Real Estate: ${inputs.realEstateValue.toLocaleString()}
Total: ${(inputs.currentPortfolio + inputs.realEstateValue).toLocaleString()}
{/* Efficient Frontier Chart */}
Efficient Frontier
if (active && payload && payload.length) {
const data = payload[0].payload;
return (
Allocation:
Securities: {data.w1}% | Real Estate: {data.w2}%
Results:
Expected Return: {data.expectedReturn}%
Risk (σₚ): {data.portfolioVolatility}%
Sharpe Ratio: {data.sharpeRatio}
);
}
return null;
}}
/>
Each point represents a different allocation between securities and real estate. The curve shows risk-return tradeoffs.
{/* Allocation Table */}
Portfolio Allocation Analysis
| Securities % | Real Estate % | Expected Return | Portfolio Risk (σₚ) | Sharpe Ratio |
|---|---|---|---|---|
| {row.w1}% | {row.w2}% | {row.expectedReturn}% | {row.portfolioVolatility}% | {row.sharpeRatio} |
Green row indicates optimal allocation with highest Sharpe ratio
{/* Diversification Benefits */}
Diversification Analysis
100% Securities
Return: {inputs.targetAnnualReturn}%
Risk: {inputs.securitiesVolatility}%
Optimal Mix
Return: {calculations.optimalPortfolio.expectedReturn}%
Risk: {calculations.optimalPortfolio.portfolioVolatility}%
Best Risk-Adjusted Return
100% Real Estate
Return: {inputs.realEstateAppreciation + inputs.rentalYield}%
Risk: {inputs.realEstateVolatility}%
Key Insight:
With correlation of {inputs.correlationCoefficient}, diversifying between securities and real estate can reduce overall portfolio risk while maintaining competitive returns. The optimal allocation maximizes the Sharpe ratio, providing the best risk-adjusted return.
)}
{/* EXIT STRATEGY TAB */}
{activeTab === ‘exit-strategy’ && (
Exit Strategy Milestones
if (year.incomeReplacementPct >= 50 && (idx === 0 || calculations.yearlyData[idx – 1].incomeReplacementPct < 50)) { return (
50% Income Replacement – Age {year.age}
Consider: Part-time work, sabbatical, or reduced hours
Annual Income: ${year.totalInvestmentIncome.toLocaleString()} | Assets: ${year.totalAssets.toLocaleString()}
);
}
if (year.incomeReplacementPct >= 75 && (idx === 0 || calculations.yearlyData[idx – 1].incomeReplacementPct < 75)) {
return (
75% Income Replacement – Age {year.age}
Consider: Semi-retirement, consulting, or passion projects
Annual Income: ${year.totalInvestmentIncome.toLocaleString()} | Assets: ${year.totalAssets.toLocaleString()}
);
}
if (year.incomeReplacementPct >= 100 && (idx === 0 || calculations.yearlyData[idx – 1].incomeReplacementPct < 100)) {
return (
100% Income Replacement – Age {year.age}
Achievement: Full financial independence reached
Annual Income: ${year.totalInvestmentIncome.toLocaleString()} | Assets: ${year.totalAssets.toLocaleString()}
);
}
return null;
})}
{/* 1031 Exchange Timeline */}
1031 Exchange Strategy
{calculations.yearlyData.find(y => y.exchange1031Executed) ? (
Exchange Executed at Age {inputs.exchange1031Age}
Original Property Value: ${inputs.realEstateValue.toLocaleString()}
Exchanged Property Value: ${calculations.yearlyData.find(y => y.exchange1031Executed).realEstate.toLocaleString()}
Tax Deferred: ${calculations.yearlyData.find(y => y.exchange1031Executed).taxDeferred.toLocaleString()}
Strategy: Reinvest into higher-yielding property
Benefits of 1031 Exchange:
By deferring capital gains taxes through a 1031 exchange, you preserve capital that would otherwise be lost to taxation. This allows for continued compounding growth on the full property value. The exchange enables upgrading to properties with better cash flow characteristics while maintaining tax efficiency throughout your wealth building phase.
) : (
1031 Exchange scheduled for Age {inputs.exchange1031Age}
)}
{/* Income Replacement Progress */}
Income Replacement Progression
contentStyle={{ backgroundColor: ‘#ffffff’, border: ‘1px solid #cbd5e1’, borderRadius: ‘8px’ }}
/>
)}
{/* TAX & TRUST TAB */}
{activeTab === ‘tax-trust’ && (
Trust Structure & Asset Protection
Trust Type
{inputs.trustType.replace(‘-‘, ‘ ‘)}
Protected Assets (Age {inputs.targetAge})
${(finalYear.trustProtectedAssets / 1000000).toFixed(2)}M
Potential Estate Tax
${(finalYear.estateTaxLiability / 1000).toFixed(0)}K
Trust Benefits by Type:
{inputs.trustType === ‘revocable’ && (
A revocable living trust provides probate avoidance, privacy, and management continuity. Assets remain under your control during your lifetime with full flexibility to modify or revoke. This structure facilitates seamless asset transfer while maintaining control and avoiding the public probate process.
)}
{inputs.trustType === ‘irrevocable’ && (
An irrevocable trust removes assets from your taxable estate, providing estate tax reduction and creditor protection. Once established, the trust terms generally cannot be modified, but this permanence creates powerful tax advantages and asset protection benefits for wealth preservation strategies.
)}
{inputs.trustType === ‘qprt’ && (
A Qualified Personal Residence Trust (QPRT) allows transfer of your primary residence to beneficiaries at a reduced gift tax value. You retain the right to live in the residence for a specified term, after which ownership transfers, providing estate tax savings while maintaining your living arrangements during the term.
)}
{inputs.trustType === ‘grat’ && (
A Grantor Retained Annuity Trust (GRAT) allows you to transfer appreciating assets to beneficiaries while receiving annuity payments for a term. Any appreciation above the IRS assumed rate passes tax-free to beneficiaries, making this an efficient vehicle for transferring wealth from appreciating assets.
)}
{/* Tax Efficiency Analysis */}
Tax Efficiency Over Time
contentStyle={{ backgroundColor: ‘#ffffff’, border: ‘1px solid #cbd5e1’, borderRadius: ‘8px’ }}
/>
{/* Tax Savings from 1031 */}
1031 Exchange Tax Benefits
Tax Deferred Through 1031
${calculations.yearlyData[calculations.yearlyData.length – 1].taxDeferred.toLocaleString()}
Capital gains tax deferred by executing 1031 exchange at age {inputs.exchange1031Age}. This capital remains invested and continues generating returns.
Compounding Benefit
By deferring taxes and keeping the full capital invested, you benefit from compound growth on funds that would otherwise have been paid in taxes.
Additional Growth Potential: Significant long-term wealth preservation through tax-deferred compounding.
{/* Estate Planning Considerations */}
Estate Planning Summary
Current Estate Tax Exemption: ${(inputs.estateTaxExemption / 1000000).toFixed(2)}M
Your projected total assets at age {inputs.targetAge} are ${(finalYear.totalAssets / 1000000).toFixed(2)}M. {finalYear.totalAssets > inputs.estateTaxExemption ? `This exceeds the exemption by ${((finalYear.totalAssets – inputs.estateTaxExemption) / 1000000).toFixed(2)}M, resulting in potential estate tax liability of ${(finalYear.estateTaxLiability / 1000).toFixed(0)}K.` : ‘This remains below the exemption threshold, minimizing estate tax exposure.’}
Trust Strategy Benefits
Utilizing a trust structure provides multiple advantages including probate avoidance, privacy protection, continuity of asset management, and potential estate tax reduction depending on trust type. Trust structures also facilitate smooth succession planning and can provide creditor protection benefits.
Recommendations for Consultation
Given the complexity of estate planning, trust structures, and tax optimization strategies, consultation with qualified professionals is essential. Consider engaging an estate planning attorney, tax advisor, and financial planner to develop a comprehensive strategy tailored to your specific circumstances and goals.
)}
{/* Detailed Year-by-Year Table (All Tabs) */}
Comprehensive Year-by-Year Analysis
| Age | Portfolio | Real Estate | Total Assets | Adj. Salary | Total Income | Replace % | Daily | Quarterly |
|---|---|---|---|---|---|---|---|---|
|
{row.age} {row.exchange1031Executed && 1031} |
${(row.portfolio / 1000).toFixed(0)}K | ${(row.realEstate / 1000).toFixed(0)}K | ${(row.totalAssets / 1000).toFixed(0)}K | ${(row.salary / 1000).toFixed(0)}K | ${(row.totalInvestmentIncome / 1000).toFixed(1)}K |
= 100 ? ‘text-green-600’ : row.incomeReplacementPct >= 75 ? ‘text-orange-600’ : row.incomeReplacementPct >= 50 ? ‘text-yellow-600’ : ‘text-red-600’}`}> {row.incomeReplacementPct}% |
${row.dailyIncome.toLocaleString()} | ${(row.quarterlyIncome / 1000).toFixed(1)}K |
“`
);
};
export default IncomeReplacementCalculator;

Leave a Reply