# Product Requirements Document: Simple SIP Calculator

## 1. Overview

The Simple SIP Calculator is a single-page web application that enables users to calculate the future value of their Systematic Investment Plan (SIP) investments. Users can input their monthly investment amount, expected annual return rate, investment duration, and instantly see projected returns, total investment, and wealth gained. The calculator provides a clear, intuitive interface for financial planning without requiring user authentication or data persistence.

## 2. User Roles

### Anonymous User (Default)
- Access the SIP calculator without login/registration
- Input investment parameters (monthly amount, rate of return, time period)
- View calculated results instantly
- Adjust parameters and recalculate unlimited times
- View visual representation of investment growth (optional chart)
- Reset calculator to default values

## 3. Core Entities

### CalculationInput
Represents the user-provided parameters for SIP calculation.
- **monthlyInvestment**: Decimal value representing the amount invested each month
- **annualReturnRate**: Percentage value representing expected yearly returns
- **investmentPeriod**: Integer representing the duration in months or years
- **periodUnit**: Enum indicating whether the period is in months or years

### CalculationResult
Represents the computed output of the SIP calculation.
- **totalInvestment**: Total amount invested over the period
- **estimatedReturns**: Wealth gained from the investment
- **futureValue**: Final maturity amount (total investment + returns)
- **calculationTimestamp**: When the calculation was performed

### ChartDataPoint (Optional)
Represents data points for visualization of investment growth.
- **period**: Time period (month/year number)
- **investedAmount**: Cumulative investment at this point
- **projectedValue**: Projected portfolio value at this point

## 4. Entity Relationships

```
CalculationInput (1) ──generates──> (1) CalculationResult
CalculationResult (1) ──contains──> (0..*) ChartDataPoint
```

**Relationship Details:**
- **CalculationInput to CalculationResult**: One-to-one relationship where each set of inputs generates one result (ephemeral, not persisted)
- **CalculationResult to ChartDataPoint**: One-to-many relationship where a single calculation can generate multiple data points for visualization purposes

## 5. Key Workflows

### Workflow 1: Calculate SIP Returns

**Actors**: Anonymous User

**Steps**:
1. User lands on the SIP calculator page
2. System displays default values in input fields:
   - Monthly Investment: $500 (or ₹5000)
   - Annual Return Rate: 12%
   - Investment Period: 10 years
3. User modifies one or more input parameters:
   - Enters monthly investment amount
   - Enters expected annual return rate
   - Enters investment duration
   - Selects period unit (months/years)
4. System validates inputs in real-time:
   - Checks for numeric values
   - Ensures positive numbers
   - Validates reasonable ranges
5. System automatically calculates results using SIP formula:
   - FV = P × ({[1 + i]^n – 1} / i) × (1 + i)
   - Where P = monthly investment, i = periodic rate of return, n = number of periods
6. System displays results:
   - Total Investment amount
   - Estimated Returns (wealth gained)
   - Future Value (maturity amount)
7. System optionally generates and displays growth chart
8. User can modify inputs to recalculate (returns to step 3)

### Workflow 2: Reset Calculator

**Actors**: Anonymous User

**Steps**:
1. User clicks "Reset" or "Clear" button
2. System restores all input fields to default values
3. System recalculates results based on default values
4. System updates display with default calculation results

### Workflow 3: View Investment Breakdown (Optional)

**Actors**: Anonymous User

**Steps**:
1. After calculation is complete, user views visual breakdown
2. System displays pie chart or bar chart showing:
   - Proportion of total investment vs. returns
3. System displays line chart showing investment growth over time
4. User can hover/interact with chart to see specific period values

## 6. Features & Requirements

### 6.1 Input Module

**FR-1.1**: Monthly Investment Input
- Provide numeric input field for monthly investment amount
- Support decimal values (up to 2 decimal places)
- Display currency symbol based on locale (default: $)
- Minimum value: 1
- Maximum value: 10,000,000
- Show validation error for invalid inputs

**FR-1.2**: Annual Return Rate Input
- Provide numeric input field for expected annual return percentage
- Support decimal values (up to 2 decimal places)
- Display percentage symbol (%)
- Minimum value: 0.1%
- Maximum value: 50%
- Show validation error for invalid inputs

**FR-1.3**: Investment Period Input
- Provide numeric input field for investment duration
- Support integer values only
- Provide toggle/dropdown to switch between months and years
- Minimum value: 1
- Maximum value: 40 years (or 480 months)
- Show validation error for invalid inputs

**FR-1.4**: Input Validation
- Validate inputs on blur and on change
- Display inline error messages for invalid inputs
- Disable calculation if any input is invalid
- Provide helpful error messages (e.g., "Please enter a value between 1 and 40")

### 6.2 Calculation Module

**FR-2.1**: SIP Calculation Engine
- Implement standard SIP formula: FV = P × ({[1 + i]^n – 1} / i) × (1 + i)
- Convert annual return rate to monthly rate: i = (annual rate / 12) / 100
- Convert years to months if period unit is years
- Calculate total investment: P × n
- Calculate estimated returns: FV - Total Investment
- Round all monetary values to 2 decimal places

**FR-2.2**: Real-time Calculation
- Trigger calculation automatically when any input changes
- Debounce calculation by 300ms to avoid excessive computations
- Show loading indicator during calculation (if needed)
- Update results immediately upon calculation completion

**FR-2.3**: Calculation Accuracy
- Use appropriate data types to prevent floating-point errors
- Ensure calculations are accurate to 2 decimal places
- Handle edge cases (zero returns, very large numbers)

### 6.3 Results Display Module

**FR-3.1**: Results Summary
- Display total investment amount with currency formatting
- Display estimated returns with currency formatting
- Display future value (maturity amount) with currency formatting
- Use clear labels for each result field
- Highlight future value as the primary result
- Use color coding (e.g., green for returns, blue for investment)

**FR-3.2**: Number Formatting
- Format large numbers with thousand separators (e.g., 1,000,000)
- Display currency symbol based on locale
- Show 2 decimal places for all monetary values
- Use appropriate font sizes for readability

**FR-3.3**: Results Breakdown
- Show percentage breakdown of investment vs. returns
- Display return on investment (ROI) percentage
- Show effective annual return rate

### 6.4 Visualization Module (Optional)

**FR-4.1**: Investment Growth Chart
- Display line chart showing portfolio value over time
- X-axis: Time period (months or years)
- Y-axis: Portfolio value
- Show two lines: Total invested amount and Projected value
- Use distinct colors for each line
- Include legend

**FR-4.2**: Investment Composition Chart
- Display pie chart or donut chart showing:
  - Total investment portion
  - Returns portion
- Use distinct colors with labels
- Show percentage and absolute values

**FR-4.3**: Chart Interactivity
- Allow hover to see specific values at any point
- Display tooltip with detailed information
- Support responsive design for mobile devices

### 6.5 User Interface Module

**FR-5.1**: Layout and Design
- Single-page layout with all elements visible without scrolling (on desktop)
- Responsive design supporting mobile, tablet, and desktop
- Clean, modern interface with intuitive controls
- Logical grouping of inputs and outputs
- Adequate white space for readability

**FR-5.2**: Reset Functionality
- Provide "Reset" button to restore default values
- Confirm action if user has modified inputs (optional)
- Clear all inputs and recalculate with defaults

**FR-5.3**: Help and Information
- Provide tooltip or info icon explaining SIP concept
- Show formula used for calculation (optional)
- Include brief explanation of each input field
- Provide example scenarios (optional)

**FR-5.4**: Accessibility
- Support keyboard navigation
- Provide appropriate ARIA labels
- Ensure sufficient color contrast
- Support screen readers

## 7. Business Rules

### BR-1: Input Validation Rules
- Monthly investment must be greater than 0 and less than or equal to 10,000,000
- Annual return rate must be between 0.1% and 50%
- Investment period must be between 1 and 40 years (or 1 to 480 months)
- All numeric inputs must be valid numbers (not text or special characters)

### BR-2: Calculation Rules
- SIP calculation uses compound interest formula with monthly compounding
- Annual return rate is divided by 12 to get monthly rate
- Investment period in years is converted to months (years × 12)
- All calculations assume end-of-month investments
- Returns are calculated assuming consistent monthly investments

### BR-3: Display Rules
- All monetary values must be displayed with 2 decimal places
- Negative values are not allowed in any calculation
- If calculation results in infinity or NaN, display error message
- Future value must always equal total investment + estimated returns

### BR-4: Default Values
- Default monthly investment: $500 (or ₹5,000 based on locale)
- Default annual return rate: 12%
- Default investment period: 10 years
- Default period unit: Years

### BR-5: Rounding Rules
- All intermediate calculations maintain full precision
- Final results are rounded to 2 decimal places
- Rounding uses standard mathematical rounding (0.5 rounds up)

### BR-6: Edge Cases
- If annual return rate is 0%, future value equals total investment
- Minimum calculation period is 1 month
- Maximum calculation period is 480 months (40 years)

## 8. Non-Functional Requirements

### NFR-1: Performance
- Page load time must be under 2 seconds on standard broadband
- Calculation must complete within 100ms for standard inputs
- Chart rendering must complete within 500ms
- Application must remain responsive during calculations
- Support debouncing to prevent excessive calculations during rapid input changes

### NFR-2: Security
- No sensitive data is collected or stored
- Implement input sanitization to prevent XSS attacks
- Use HTTPS for application delivery
- No authentication or authorization required
- Client-side only calculations (no data sent to server)

### NFR-3: Scalability
- Application must be stateless (no server-side sessions)
- Support concurrent usage by unlimited users
- Calculations performed client-side to minimize server load
- Static assets should be cacheable
- Support CDN deployment for global access

### NFR-4: Compatibility
- Support modern browsers: Chrome (last 2 versions), Firefox (last 2 versions), Safari (last 2 versions), Edge (last 2 versions)
- Support mobile browsers: iOS Safari, Chrome Mobile
- Responsive design supporting screen sizes from 320px to 4K
- Graceful degradation for older browsers

### NFR-5: Usability
- Interface must be intuitive without requiring instructions
- Results must update within 500ms of input change
- Error messages must be clear and actionable
- Support both mouse and keyboard interactions
- Maintain consistent visual design throughout

### NFR-6: Accessibility
- WCAG 2.1 Level AA compliance
- Support screen readers (NVDA, JAWS, VoiceOver)
- Keyboard navigation for all interactive elements
- Minimum color contrast ratio of 4.5:1 for text
- Provide text alternatives for visual information

### NFR-7: Maintainability
- Code must be modular and well-documented
- Use standard calculation formulas that can be easily verified
- Separate business logic from presentation logic
- Include unit tests for calculation engine
- Use version control for all code

### NFR-8: Localization (Future Enhancement)
- Support multiple currencies (USD, INR, EUR, GBP)
- Support multiple languages (English, Hindi, Spanish)
- Use locale-appropriate number formatting
- Allow currency selection without page reload

### NFR-9: Browser Storage
- Optionally persist user inputs in localStorage
- Restore previous inputs on page reload (optional)
- Clear stored data on reset
- No personal or sensitive data stored

### NFR-10: Analytics (Optional)
- Track page views
- Track calculation frequency
- Track common input ranges
- No personally identifiable information collected
- Comply with privacy regulations (GDPR, CCPA)

---

## Appendix: SIP Calculation Formula

**Future Value (FV) Formula:**
```
FV = P × ({[1 + i]^n – 1} / i) × (1 + i)

Where:
- P = Monthly investment amount
- i = Periodic (monthly) rate of return = (Annual Rate / 12) / 100
- n = Number of periods (months)
- FV = Future Value at maturity
```

**Derived Calculations:**
```
Total Investment = P × n
Estimated Returns = FV - Total Investment
ROI % = (Estimated Returns / Total Investment) × 100
```

---

**Document Version:** 1.0  
**Last Updated:** 2025  
**Status:** Ready for Development