Inspiration
When markets crash, many traders only realise how risky things were after they've lost money. I wanted to build a tool that notices the warning signs early and shows what could have been done about them.
What it does
Storm Guard downloads real historical prices and labels every day as CALM, WARNING, or STORM. It then simulates a simple protection strategy, moving money into cash while a storm is detected and back into the market when it eases. It compares that against doing nothing, and draws a chart with the price, the risk zones, and both portfolios.
It touches all four themes from the challenge: staying safe, early warning, understanding what comes next, and spotting the recovery.
How I built it
I used Python with pandas for the data, yfinance to download prices, and matplotlib for the charts.
The risk signal is built from two measures. The daily return is
$$r_t = \frac{P_t - P_{t-1}}{P_{t-1}}$$
and volatility is the standard deviation of the last $n = 10$ returns:
$$\sigma_t = \sqrt{\frac{1}{n-1}\sum_{i=t-n+1}^{t}\left(r_i - \bar{r}\right)^2}$$
I also track drawdown, which is how far the price has fallen from its highest point so far:
$$DD_t = \frac{\max_{s \le t} P_s - P_t}{\max_{s \le t} P_s}$$
Each day is labelled using thresholds on $\sigma_t$ and $DD_t$. High volatility means a STORM, and moderate volatility or a large drawdown means a WARNING.
To test the protection idea, a simulated portfolio starting at 1000 moves to cash the day after a storm is detected, then returns to the market once the storm label clears.
Challenges I ran into
- Avoiding look-ahead bias. My first idea was to sell on the same day a storm was detected, but that uses information you would not have had yet. I delayed every decision by one day so the strategy only uses data available at the time.
- Choosing thresholds. I picked the volatility and drawdown thresholds by hand, and they were not optimised on real data. Different assets behave very differently, so settings that suit an index may not suit something like Bitcoin.
- Library changes. Newer versions of yfinance return data in a different table layout, so I had to adjust how the prices are extracted.
What I learned
- How to use pandas to replace loops with whole-column operations such as rolling windows, cumulative maximums, and compound returns.
- Why backtests can be misleading, and how look-ahead bias and tuning on the same data you test on can make results look better than they are.
- How to turn financial ideas like volatility and drawdown into working code.
- How to use Git and GitHub to publish a project.
Results
[Add what you observed when you ran it on real data, such as the date range, which ticker you used, and how the final portfolio values compared. Only include numbers from your own runs.]
What's next
- Set thresholds automatically from percentiles of past volatility, and test them on a different period from the one used to choose them.
- Let users enter any ticker and date range.
- Compare several assets and rank them by risk.
- Build a web interface so it can be used without running any code.
Limitations
This is an educational project and not financial advice. The simulation ignores trading fees and taxes, and a result on one time period does not prove the strategy works in general.