An investment calculator built using React.js that helps users calculate the future value of their investments. The calculator allows users to input initial investment, annual investment, expected return rate, and investment duration. Additionally, users can choose between USD and INR as the currency for their calculations.
- Input fields for initial investment, annual investment, expected return, and duration.
- Currency selector to choose between USD and INR.
- Results table displaying the year-by-year investment value, interest earned, total interest, and invested capital.
To run this project locally, follow these steps:
-
Clone the repository:
git clone https://github.com/SmitParekh84/Investment-Calculator.git cd investment-calculator
-
Install the dependencies:
npm install
-
Start the development server:
npm start
The application will be available at http://localhost:3000
.
- Open the application in your web browser.
- Fill in the input fields with your initial investment, annual investment, expected return, and duration.
- Select the currency (USD or INR) from the dropdown.
- The results table will automatically update, displaying the investment value, interest earned, total interest, and invested capital for each year.
src/components/
Header.jsx
: The header component.UserInput.jsx
: The component for user inputs.Results.jsx
: The component for displaying the results.
src/util/
investment.js
: Contains the investment calculation logic and currency formatter function.
src/App.jsx
: The main app component.
Contains the calculateInvestmentResults
function to compute the investment results based on the user input and the getFormatter
function to format the numbers according to the selected currency.
export function calculateInvestmentResults({
initialInvestment,
annualInvestment,
expectedReturn,
duration,
}) {
const annualData = [];
let investmentValue = initialInvestment;
for (let i = 0; i < duration; i++) {
const interestEarnedInYear = investmentValue * (expectedReturn / 100);
investmentValue += interestEarnedInYear + annualInvestment;
annualData.push({
year: i + 1,
interest: interestEarnedInYear,
valueEndOfYear: investmentValue,
annualInvestment: annualInvestment,
});
}
return annualData;
}
export function getFormatter(currency) {
const locale = currency === 'USD' ? 'en-US' : 'en-IN';
return new Intl.NumberFormat(locale, {
style: 'currency',
currency: currency,
minimumFractionDigits: 0,
maximumFractionDigits: 0,
});
}