Skip to content

mountEvarus/sp-500-allocator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

S&P 500 Portfolio Allocator

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.

Features

  • 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

Prerequisites

  • Rust (tested on 1.70+)
  • An API key from API Ninjas (free tier available)

Usage

  1. Clone the repository:

    git clone https://github.com/mountEvarus/sp-500-allocator.git
    cd sp-500-allocator
  2. Create a .env file in the project root with your API Ninjas key:

    NINJA_API_KEY=your_api_key_here
  3. Create an input/values.json file 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)
  4. Run the application:

    cargo run
  5. Find your allocation recommendations in output/allocation-{timestamp}.csv

License

MIT

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages