A command-line tool written in Rust that helps allocate investments across S&P 500 companies based on market capitalization weighting. It calculates how many shares to buy of each stock to mirror the index composition, taking into account your existing holdings.
- Fetches current S&P 500 constituents via API Ninjas
- Retrieves real-time stock prices and market caps from Yahoo Finance
- Supports multiple currencies (automatically converts to USD)
- Accounts for existing portfolio holdings
- Outputs allocation recommendations to CSV
- Rust (tested on 1.70+)
- An API key from API Ninjas (free tier available)
-
Clone the repository:
git clone https://github.com/mountEvarus/sp-500-allocator.git cd sp-500-allocator -
Create a
.envfile in the project root with your API Ninjas key:NINJA_API_KEY=your_api_key_here
-
Create an
input/values.jsonfile with your portfolio details:{ "amount": 50000.00, "currency": "USD", "portfolio": [ { "ticker": "AAPL", "share_count": 10 }, { "ticker": "MSFT", "share_count": 5 } ] }amount: Cash to allocate (in the specified currency)currency: Your currency code (e.g., "USD", "GBP", "EUR")portfolio: Your existing holdings (use an empty array[]if starting fresh)
-
Run the application:
cargo run
-
Find your allocation recommendations in
output/allocation-{timestamp}.csv
MIT