Inspiration
Most trading backtests you see online look amazing but are secretly wrong. They use information from the future, ignore trading costs, and only show profits, not risk. In 2012, the trading firm Knight Capital lost $440 million in 45 minutes because nothing stopped a broken trading program. I wanted to build the safety system: a tool that measures risk honestly and stops dangerous trades before they happen.
What it does
RiskLens helps you understand and control the risk of a trading strategy.
- Analyze any stock: type a ticker like SPY or TSLA. RiskLens tests a strategy on years of real prices, once without safety rules and once with them, and shows how much the rules protect you in crashes like 2008 and COVID.
- Check the risk estimate: RiskLens predicts how much you could lose tomorrow in six different ways, then checks which predictions were actually right, using the same tests banks use.
- Live prices: it streams real Bitcoin trades and updates the risk on every trade.
- Risk gateway: before any (simulated) order goes through, it runs eight safety checks, like "is the order too big?" or "is the price out of date?". A kill switch can stop all trading instantly.
How I built it
I built it in Python as a website that runs on your computer. Real stock prices come from Yahoo Finance and live crypto prices from Coinbase. I made sure the results can be trusted: the program can never use future prices, every dollar is tracked to the cent, and the same inputs always give the exact same result.
Challenges
My first version of the risk check gave itself a good grade it didn't deserve. It counted days when the strategy held no stock, when you can't lose money anyway. Once I fixed that, the most common way of measuring risk turned out to be wrong far too often, while the method real risk desks use passed. I also had to be honest about speed: free stock prices are delayed by about a minute, so I added real-time crypto prices and show the measured delay on screen.
What I learned
Writing a backtest is easy; proving it's correct is the hard part. I wrote 175 automated tests, then deliberately planted 19 bugs in my own code to see if the tests would catch them. They caught all 19. I also learned that safety rules have trade-offs: one rule did most of the protecting, while another one on its own actually made losses worse.
What's next
Analyzing a whole portfolio of stocks at once, and testing how the strategy would hold up in a new crash.
Everything is simulated: no real money or real orders. Built with help from an AI coding assistant (Claude); I reviewed, ran and tested all the code.
Built With
- coinbaseapi
- css
- git
- html
- javascript
- pytest
- websockets
- y-finance
Log in or sign up for Devpost to join the conversation.