Part 6 · Challenges
Goal: Use the leak-free evaluation pipeline we built to try other tickers, a new feature (volume_change), other architectures (GRU, TinyTransformer), and a strategy test with trading costs (15 bps).
Catch-up cell: 🔄 Catch up: Part 6 (prepares every variable for the challenges)
Challenges and solution hints:
- Challenge 1 — Try your own ticker: Load data with
load_prices("ASELS.IS"),load_prices("BTC-USD")orload_prices("AAPL"). Pass an invalid ticker (load_prices("INVALID_TICKER_XYZ")) and see how theValueErroris caught. - Challenge 2 — Add the trading-volume feature (
volume_change): Passcols_5 = FEATURE_COLS + ["volume_change"]tofit_scaler_on_trainand retrain the model with five features (onTHYAO.IStest accuracy comes out around55.7%; compare it with the ±4.8-point uncertainty from Part 5 before calling it an improvement). - Challenge 3 —
nn.GRUinstead ofnn.LSTM, with a 15-day window: Try theGRUmodel, which has fewer parameters, withtrain_direction_classifier(..., window_size=15, model_cls=GRUModel)(Test Acc: 52.6%). - Challenge 4 (Bonus) —
TinyTransformerModeland a backtest with costs: Callbacktest_with_costs(test_rets, cls_res["y_pred"], cost_bps=15.0)and compare buy-and-hold with the strategy before and after a 0.15% commission-and-spread cost on every trade. On the THYAO test window the model is in the market only about one day in five and changes position just 29 times, so costs take little off: buy-and-hold ends at0.99x, the strategy at1.24xgross and1.18xnet. Before believing it, ask why: one 22-month window, an accuracy indistinguishable from 50%, and a strategy that mostly sat in cash during a flat market. Rerun it with other seeds, tickers and walk-forward folds.
Troubleshooting (if this step fails):
Not enough historyfor a BIST ticker you picked: Recently listed stocks can have fewer than 120 days of data. Pick an older ticker or lower themin_rowsparameter.- To see the solution code: Double-click the
💡 Solutioncell under each challenge in the notebook to open the code, or simply run it.