Skip to content

Odjokarl/sgCodingInterview

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SG CodingInterview — ETF Price Comparison (Streamlit)

Small demo app and library to simulate ETF prices built from synthetic bond data.

Project Overview

This repository contains a compact Streamlit application and supporting modules to:

  • generate synthetic bond data,
  • build a simple ETF from a subset of bonds with randomized weights,
  • compute ETF price (weighted sum of bond prices), and
  • visualize and compare ETF compositions between two dates.

The app is intended as a concise coding interview project illustrating basic data modeling, small domain objects, and a Streamlit UI for interactive exploration.

Features

  • Generate 2·N random Bond objects with configurable price ranges.
  • Build an ETF from a selected subset of bonds with random weights.
  • Compute ETF price and pool value.
  • Streamlit dashboard to run simulations and visualize:
    • ETF weights at two dates
    • Weight differences for common bonds
    • Bonds entering or exiting the ETF
    • Pool value comparison

Repository structure

  • app.py — Streamlit app (UI). Entry point for interactive simulations and visualizations.
  • main.py — Core helper functions: generate_bonds, generate_weights, build_etf, and a simple main() runner for quick testing.
  • assets.py — Domain dataclasses: Bond and ETF with price property and extract_data() helper.
  • images/ — UI assets (logo) referenced by app.py and the UML diagram generated with PlantUML.
  • tests/ — Unit tests for assets.py and main.py to ensure correct behaviour. All tests can be run with pytest -q when the virtual environment is activated.
  • requirements.txt — Python dependencies for running the app.

Quick start

  1. Recommended: create and activate a virtual environment.
python -m venv .venv
source .venv/bin/activate
  1. Install dependencies:
pip install -r requirements.txt
  1. Run the Streamlit app (from the project root):
streamlit run app.py

Open the URL printed by Streamlit (usually http://localhost:8501).

Usage notes

  • In the app UI you can choose the number of bonds (N) and a price range for generated bonds.
  • The app will generate 2·N bonds but build each ETF from N randomly sampled bonds — this permits comparing two ETF snapshots built from different random samples.

Key functions:

  • main.generate_bonds(n, price_range) — returns List[Bond].
  • main.build_etf(name, as_of_date, bonds) — returns an ETF instance.
  • ETF.price — computed as the weighted sum of underlying bond prices.

Below is a rendered class diagram for the main domain model.

UML class diagram

Contact

This project is a personal demo by Karl ODJO.

About

IRON FRONT Coding Interview

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages