# Trade-up Profit Calculator

> A data pipeline and calculator that finds profitable CS2 trade-up contracts – market data ingestion, probability model and a tested TypeScript core.

- **Role:** Solo Developer
- **Year:** 2024
- **Tech:** TypeScript, Node.js, SQLite, Vitest, REST APIs
- **Repository:** https://github.com/ondraulehla/cs2-tradeup-calculator
- **Canonical page:** https://ulehla.dev/projects/tradeup-calculator

**Problem.** Trade-up contracts hide a genuine expected-value calculation behind fluctuating market prices – doing it by hand is slow and error-prone.

**Solution.** An automated pipeline that ingests market prices, models outcome probabilities and float values, and ranks every possible contract by expected profit.

**Outcome.** Evaluates thousands of contract combinations in seconds; the probability core is fully unit-tested against known outcomes.

---

{/* TODO(Ondřej): replace placeholder narrative with real numbers and a screenshot of the output. */}

## Context

In Counter-Strike 2, a _trade-up contract_ converts ten lower-tier skins into one random
higher-tier skin. Whether that gamble is profitable is a pure math problem – expected value
over outcome probabilities and current market prices – but the inputs shift constantly.

## Problem

Doing the calculation manually means juggling price lists, collection pools, float ranges
and probability weights for every candidate combination. Humans give up after a handful;
the interesting opportunities live in the long tail.

## Solution

A TypeScript pipeline in three stages:

- **Ingestion** – market price snapshots pulled into SQLite with rate-limit-aware fetching
- **Model** – outcome probabilities per collection, float value propagation, fee-adjusted pricing
- **Ranking** – exhaustive search over viable input pools, ranked by expected profit and variance

The probability model is the heart of it, so it's covered by **Vitest unit tests** against
hand-verified contract outcomes – refactoring the math is safe.

## Outcome

- Thousands of combinations evaluated in seconds instead of hours of spreadsheet work
- Reproducible results backed by versioned price snapshots
- A tested core I can extend to new game economies

## What I learned

Data quality beats model sophistication – most "profitable" contracts turned out to be
stale-price artifacts until ingestion got strict about freshness.
