Built for Options Trading · Python · Flask · Black-Scholes · IG Markets API
Delta Hedging Platform
Reads the option positions of an IG demo account, prices each with Black-Scholes (greeks, and the implied volatility found from the option's own market price), adds the deltas across the whole portfolio and works out the trade in the underlying that makes it delta neutral. A dashboard and a small authenticated JSON API show the result. An order is placed only when hedging is switched on and a request confirms the exact order that was previewed. Python and Flask, demo environment only.
IG Positions → Black-Scholes → Net Delta Plan → Guarded Order

Role
Quantitative Developer
Duration
4 weeks
Tech Stack
The Problem
A book of options moves with the price of its underlying, and the sum of every option's delta says by how much. Keeping that sum near zero by trading the underlying is delta hedging, and doing it by hand across many positions is slow and easy to get wrong.
The starting point was a Flask app that read an IG demo account's option positions and placed a hedge. Its core was wrong in ways that matter for a program that places orders: every hedge was a BUY whatever the position, the underlying's price was the option's own price, and the implied-volatility search did not converge. The job was to rebuild it so that its answers can be trusted and its orders cannot happen by accident.
My Approach
- Pricing. A Black-Scholes module on the standard library alone: price and the greeks, with implied volatility found by bisection from the option's own market price. Inputs are never silently clamped.
- Positions. Each IG position is read, or reported as unreadable with the reason. There are no defaults for the strike, the type or the expiry, which are read from the instrument's name.
- Plan. The deltas of the whole book are added up first, hedges already held in the underlying are counted, and one trade is worked out to bring the net delta inside a threshold. Large needs are hedged in capped steps.
- Orders. A request can only preview a hedge. An order needs hedging to be switched on and a request that repeats the exact side and size that were previewed; if the book moved by more than a tolerance in between the answer is a 409 with the new plan. After an order, IG's confirmation is read and ACCEPTED or REJECTED is what is recorded. A cooldown runs between orders.
- Safety. A bearer token on every API route, no CORS, a strict Content-Security-Policy, tokens and passwords never in logs or pages, one IG session per account so no request runs on the wrong one, and only IG's demo environment accepted.
- Interface. A single-page dashboard and a small JSON API (analysis, hedge, history), a command-line greeks calculator, and a non-root Docker image.
Results & Impact
Re-run on 2026-11-14 in a scratch copy: 530 tests passed and 1 was skipped under pytest with warnings as errors; ruff check and ruff format --check pass. Two hygiene tests that read the .env.example file were not part of that run, because that file was not copied.
The app was also run on that date against the repository's own fake IG, served over HTTP on loopback with six option positions priced at known volatilities. The dashboard's implied volatilities came back within 0.002 of the ones used for pricing (for example 0.189 for an option priced at 0.19, and 0.229 for 0.23), the plan was SELL 4.62 and left a remaining net delta of about -0.0001, a request without a token was refused with 401, and a confirmed order was accepted by the fake and listed in the order table. The greeks command returned 10.4506 and 0.6368 for the standard at-the-money example.
Recorded in the repository's work-done.md (2026-11): 532 passed and 1 skipped with 99% line and branch coverage; a mutation check that put 62 defects back one at a time, including 'every hedge is a BUY', and the tests failed for all 62; a no-cache Docker build of 197 MB, running as a non-root user, healthy, with no secret in the container log.
Not verified: any request to the real IG service. No credentials were available, so login, the account switch, the response shapes, order placement and confirmation were checked against fakes written from IG's documentation only, and may differ on the real demo service.