A command-line program that processes equity vesting events from CSV files and calculates total shares vested for each employee-award combination as of a target date.
- Python 3.6 or higher (no external dependencies required - uses only Python standard library)
The program can be run directly using Python:
python vesting_program.py <filename> <target_date> [precision]Arguments:
filename(required): Path to CSV file containing vesting eventstarget_date(required): Date to calculate vesting up to, in YYYY-MM-DD formatprecision(optional): Number of decimal places (0-6). Default is 0 if not specified.
Examples:
# Stage 1: Basic vesting with default precision (0)
python vesting_program.py example1.csv 2020-04-01
# Stage 2: With cancellation events
python vesting_program.py example2.csv 2021-02-01
# Stage 3: With fractional shares and precision
python vesting_program.py example3.csv 2021-02-01 1On Unix-like systems (Linux, macOS), you can make the script directly executable:
chmod +x vesting_program.py
./vesting_program.py example1.csv 2020-04-01On Windows, you can create a batch file wrapper if needed, but running with python vesting_program.py works directly.
The code is organized into distinct classes with single responsibilities:
PrecisionHandler: Handles truncation logic for decimal precisionVestingEvent: Represents a single vesting or cancellation eventVestingCalculator: Core calculation logic for processing eventsCSVParser: Handles CSV file parsing and validationOutputFormatter: Formats and prints results in the required format
This separation makes the code maintainable, testable, and easy to extend.
To avoid floating-point arithmetic errors (especially with fractional shares), the implementation uses Python's Decimal type for all internal calculations. This ensures precise arithmetic when handling fractional shares and truncation.
The truncation logic:
- Truncates input quantities to the specified precision during parsing
- Uses
Decimal.quantize()withROUND_DOWNto ensure consistent truncation - Applies precision consistently throughout the calculation pipeline
Events are processed chronologically, with special handling for events on the same day:
- All VEST events on a given day are processed first
- Then all CANCEL events on that day are processed
- This ensures cancellation validation is done against the vested total that includes vesting events on the same day
The program validates that cancellations do not exceed vested shares:
- For each day, the sum of all cancellations must not exceed the total shares vested up to (and including) that day
- The validation is checked incrementally as cancellations are processed
- If validation fails, a descriptive error message is raised
The program includes all employee-award combinations in the output, even if 0 shares are vested by the target date. This ensures consistency and completeness of results.
Results are sorted by Employee ID (ascending), then by Award ID (ascending), as required by the specification.
-
CSV Format:
- CSV files have no header row
- All rows contain exactly 6 columns
- Empty rows are skipped
-
Date Format:
- All dates are in YYYY-MM-DD format
- Dates are valid calendar dates
-
Event Types:
- Only 'VEST' and 'CANCEL' event types are valid
- Event types are case-sensitive
-
Quantities:
- Quantity values are numeric (integer or decimal)
- Negative quantities are not explicitly handled (though they would be processed)
-
Data Consistency:
- Employee names and IDs are consistent across events for the same employee
- Award IDs are consistent across events for the same award
- Cancellations will not exceed vested shares (validation catches this)
-
Precision:
- Precision values are integers between 0 and 6 (inclusive)
- When precision is 0, all values are treated as integers
- Truncation happens at both input and output stages
-
Performance:
- The solution is designed to handle reasonably large datasets efficiently
- All events are loaded into memory, which should be acceptable for typical use cases
- ✅ Handles VEST events
- ✅ Calculates total shares vested up to target date
- ✅ Includes all employees/awards (even with 0 shares)
- ✅ Outputs in required format with correct ordering
- ✅ Handles CANCEL events that subtract from vested total
- ✅ Validates that cancellations do not exceed vested shares
- ✅ Processes cancellations after vesting events on the same day
- ✅ Supports fractional share quantities in input
- ✅ Accepts optional precision argument (0-6, default 0)
- ✅ Truncates inputs and outputs to specified precision
- ✅ Uses Decimal arithmetic for precise calculations
The program has been tested with the provided examples:
example1.csv: Basic vesting scenarioexample2.csv: Cancellation scenarioexample3.csv: Fractional shares with precision
All examples produce the expected output as specified in the requirements.
-
Performance Optimizations:
- For very large datasets, could implement streaming CSV parsing
- Could add progress indicators for large file processing
-
Error Handling:
- More detailed error messages with line numbers
- Graceful handling of edge cases (e.g., negative quantities, invalid dates)
-
Testing:
- Add unit tests for individual components
- Add integration tests for edge cases
- Add performance benchmarks
-
Code Organization:
- Could split into multiple modules for better organization
- Add type hints more comprehensively
-
Documentation:
- Add inline documentation for complex algorithms
- Create user documentation with more examples
-
Features:
- Support for additional event types if needed
- Command-line flags for verbose output, error handling modes
- Support for different date formats
This solution was developed based on the provided requirements specification. No additional LLM prompts were used beyond understanding and implementing the requirements as specified.