β οΈ AI-Generated Code Disclaimer: This project was largely written by AI (Claude) and contains significant amounts of AI-generated code and documentation. While functional and tested, much of the content may be considered "AI slop" - use at your own discretion and verify calculations independently for any financial decisions.
A comprehensive RSU (Restricted Stock Unit) calculator providing three distinct applications from a single codebase: CLI tool, macOS app, and iOS app. Calculate vesting scenarios and determine required sale prices to achieve target net income.
This project transformed from a CLI-only tool into a complete ecosystem with three separate applications:
- π§ CLI Tool - Command-line interface for power users and automation
- π» macOS App - Native desktop experience with SwiftUI
- π± iOS App - Mobile calculations on-the-go
All applications share the same proven calculation engine while providing the optimal interface for each use case.
rsucalc/ # π Project Root Directory
βββ π§ Swift Package (CLI + Core Logic)
β βββ Package.swift # Swift Package configuration
β βββ Sources/RSUCalculatorCore/ # Shared business logic
β β βββ RSUCalculator.swift
β βββ Sources/rsucalc-cli/ # CLI executable
β β βββ main.swift
β βββ Tests/rsucalcTests/ # Comprehensive test suite
β βββ RSUCalculatorTests.swift
β
βββ π― Xcode Project (GUI Apps)
β βββ RSUCalculatorUnified.xcodeproj/ # Multi-platform GUI project
β
βββ π± SwiftUI Source Code
βββ RSUCalculatorGUI/ # GUI components (separate from package)
βββ Shared/ # Cross-platform SwiftUI application
β βββ RSUCalculatorApp.swift # App entry point
β βββ ContentView.swift # Platform-adaptive main view
β βββ RSUCalculatorViewModel.swift # Observable state management
β βββ RSUInputView.swift # Input form interface
β βββ RSUResultsView.swift # Results display interface
β βββ Assets.xcassets/ # App assets
βββ macOS/ # Platform-specific resources
βββ RSU_Calculator_macOS.entitlements
- β DRY Principle: Single calculation engine shared across all apps
- β Build System Isolation: Swift Package (CLI) and Xcode (GUI) are completely separate
- β Clear Boundaries: Package manages CLI/core, Xcode references GUI source externally
- β Independent Development: Work on CLI without affecting GUI project structure
- β Maintainability: Core logic changes automatically benefit all apps
# Clone repository
git clone <repository-url>
cd rsucalc
# Quick development usage
swift run rsucalc-cli --help
# Build for production
swift build -c release
# Executable will be at: .build/release/rsucalc-cli# Open the unified Xcode project
open RSUCalculatorUnified.xcodeprojIn Xcode:
- Select "RSU Calculator (macOS)" scheme β Run macOS app βR
- Select "RSU Calculator (iOS)" scheme β Run iOS app βR
Quick Help:
swift run rsucalc-cli --helpDevelopment Usage:
swift run rsucalc-cli [OPTIONS]Production Usage:
./.build/release/rsucalc-cli [OPTIONS]- Side-by-side layout for easy input and results viewing
- Native macOS interface with proper keyboard navigation
- Real-time validation and calculation updates
- Copy/paste support for easy data entry
- Tabbed interface optimized for mobile screens
- Touch-friendly controls with large input areas
- Automatic layout adaptation for different screen sizes
- On-the-go calculations when away from your computer
When you open RSUCalculatorUnified.xcodeproj, you'll see several schemes:
RSU Calculator (macOS)- Your macOS SwiftUI appRSU Calculator (iOS)- Your iOS SwiftUI app
rsucalc-cli- CLI scheme (not properly configured for Xcode)rsucalc-Package- Entire Swift Package buildRSUCalculatorCore- Core library only
Recommendation: Use the first two schemes for GUI development, and swift run rsucalc-cli in terminal for CLI usage.
--vcd-price, -v: VCD (Vesting Commencement Date) price per share--vesting-shares, -s: Number of shares vesting--vest-day-price, -p: Share price on vest day--medicare-rate, -m: Medicare tax rate (as decimal, e.g., 0.0145 for 1.45%)--social-security-rate, -o: Social Security tax rate (as decimal, e.g., 0.062 for 6.2%)--federal-rate, -r: Federal tax rate (as decimal, e.g., 0.22 for 22%)--salt-rate, -t: SALT (State and Local Tax) rate (as decimal, e.g., 0.05 for 5%)--shares-sold-for-taxes, -x: Number of shares sold for tax withholding--tax-sale-price, -a: Price per share when sold for taxes
--include-capital-gains, -c: Include short-term capital gains tax calculation (uses federal + SALT rates)--include-net-investment-tax, -n: Include 3.8% Net Investment Income Tax (NIIT) on capital gains for high-income earners
Development:
swift run rsucalc-cli \
--vcd-price 100.00 \
--vesting-shares 100 \
--vest-day-price 120.00 \
--medicare-rate 0.0145 \
--social-security-rate 0.062 \
--federal-rate 0.22 \
--salt-rate 0.05 \
--shares-sold-for-taxes 25 \
--tax-sale-price 120.00 \
--include-capital-gains \
--include-net-investment-taxProduction:
./.build/release/rsucalc-cli \
--vcd-price 100.00 \
--vesting-shares 100 \
--vest-day-price 120.00 \
--medicare-rate 0.0145 \
--social-security-rate 0.062 \
--federal-rate 0.22 \
--salt-rate 0.05 \
--shares-sold-for-taxes 25 \
--tax-sale-price 120.00 \
--include-capital-gains \
--include-net-investment-taxShort options:
swift run rsucalc-cli -v 100.00 -s 100 -p 120.00 -m 0.0145 -o 0.062 -r 0.22 -t 0.05 -x 25 -a 120.00 -c -nThe calculator performs the following steps:
- Baseline Calculation: Calculates what your net income would be if vest day price = VCD price
- Actual Scenario: Calculates your actual gross income using the vest day price
- Tax Calculation: Determines taxes based on the actual vest day price
- Tax Sale Impact: Accounts for shares sold for tax withholding and their proceeds
- Required Price: Calculates what price you need to sell remaining shares at to achieve your target net income
The tool provides detailed output including:
- Input parameters summary
- Calculation breakdown with individual tax components
- Tax sale proceeds and cash distribution
- Required sale price for remaining shares
- Capital gains analysis (when enabled)
- Comparison with vest day price (premium/discount analysis)
Common tax rates (enter as decimals):
- Medicare: 1.45% = 0.0145
- Social Security: 6.2% = 0.062
- Federal: 22% = 0.22, 24% = 0.24, 32% = 0.32
- SALT: 5% = 0.05, 9.3% = 0.093
- Capital Gains: Uses your federal + SALT rates for short-term capital gains (marginal federal income tax rate + SALT rate)
The calculator can account for short-term capital gains tax when the required sale price is higher than the vest day price. This is important because:
- Cost basis: Vest day price (not VCD price)
- Capital gain: Sale price - Vest day price
- Tax rate: Uses your marginal federal income tax rate + SALT rate
- Tax impact: Can significantly increase the required sale price
Use the --include-capital-gains flag when you expect to sell above the vest day price.
High-income earners may be subject to an additional 3.8% Net Investment Income Tax (NIIT) on capital gains. The calculator can include this tax:
- When it applies: Only when capital gains are present (sale price > vest day price)
- Tax rate: Additional 3.8% on top of federal + SALT capital gains rates
- Total rate: Federal rate + SALT rate + 3.8% NIIT
- Example: 22% federal + 5% SALT + 3.8% NIIT = 30.8% total capital gains rate
Use the --include-net-investment-tax flag along with --include-capital-gains for high-income earners.
- Planning: Determine if you need to wait for a higher price to achieve your target net income
- Decision Making: Compare different vesting scenarios
- Tax Planning: Understand the impact of tax withholding on your net proceeds
The project includes comprehensive unit tests:
# Run all tests
swift test
# Run specific test
swift test --filter testRealWorldScenario
# Build and test together
swift build -c release && swift testThe test suite ensures calculation accuracy across:
- β Basic calculation scenarios - Core RSU calculations
- β Real-world RSU scenarios - 4 different case studies
- β Edge cases - Zero taxes, all shares sold, etc.
- β Large numbers - Precision handling with big datasets
- β Input validation - Detailed error messages
- β Mathematical consistency - Cross-validation of calculations
- β Performance benchmarks - Speed tests with large datasets
- β Capital gains tax - Federal + SALT rate calculations
- β Capital gains edge cases - No profit, losses, zero SALT
- β Net Investment Income Tax (NIIT) - High-income scenarios
- β NIIT combinations - Various tax rate scenarios
Before using any application, verify everything works:
# Verify CLI builds and tests pass
swift build -c release
swift test
# Verify CLI works
swift run rsucalc-cli --help
# Verify macOS app builds (in Xcode)
# Select "RSU Calculator (macOS)" scheme β Product β Build (βB)Platform-agnostic business logic shared across all applications:
RSUCalculator- Main calculation engine with all RSU logicRSUCalculationResult- Comprehensive result data structure- Input validation - Detailed error handling and validation
- Currency precision - Proper rounding and financial calculations
Built with Swift ArgumentParser for robust command-line interface:
- Comprehensive CLI - All features accessible via command-line flags
- Detailed output - Formatted results with clear breakdowns
- Production ready - Suitable for scripts and automation
- Development friendly - Quick iteration with
swift run
Cross-platform SwiftUI with platform-adaptive design:
RSUCalculatorViewModel- Observable state management with@StateObjectRSUInputView- Form-based input with real-time validationRSUResultsView- Comprehensive results displayContentView- Platform-adaptive layout (HStack for macOS, TabView for iOS)- Shared codebase - Single SwiftUI implementation for both platforms
# Build CLI tool
swift build --product rsucalc-cli
# Run tests
swift test
# Build for release
swift build -c release
# Quick development
swift run rsucalc-cli --help# Open unified project
open RSUCalculatorUnified.xcodeproj
# In Xcode:
# - Select target scheme (macOS or iOS)
# - Build with βB
# - Run with βR
# - Test with βUTo integrate this calculator into your own project:
- Add dependency: Include
RSUCalculatorCoreas a Swift Package dependency - Import:
import RSUCalculatorCore - Use calculator: Create
RSUCalculatorinstance for calculations - Optional UI: Copy SwiftUI views for ready-made interface
- macOS 13.0+ (for macOS app)
- iOS 16.0+ (for iOS app)
- Swift 5.9+ (for all components)
- Xcode 15.0+ (for GUI development)
You now have a complete RSU Calculator ecosystem:
- π§ CLI Tool -
swift run rsucalc-clifor power users and automation - π» macOS App - Native desktop experience with full GUI
- π± iOS App - Mobile calculations with touch-optimized interface
All three applications share the same proven calculation engine, ensuring consistency while providing the optimal interface for each use case. The modular architecture makes it easy to maintain and extend! π