Coder Social home page Coder Social logo

investment-calculator's Introduction

Investment Calculator

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.

Features

  • 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.

Installation

To run this project locally, follow these steps:

  1. Clone the repository:

    git clone https://github.com/SmitParekh84/Investment-Calculator.git
    cd investment-calculator
  2. Install the dependencies:

    npm install
  3. Start the development server:

    npm start

The application will be available at http://localhost:3000.

Usage

  1. Open the application in your web browser.
  2. Fill in the input fields with your initial investment, annual investment, expected return, and duration.
  3. Select the currency (USD or INR) from the dropdown.
  4. The results table will automatically update, displaying the investment value, interest earned, total interest, and invested capital for each year.

Project Structure

  • 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.

Code Overview

investment.js

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,
  });
}

investment-calculator's People

Contributors

smitparekh84 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.