Enhance finlearner with advanced options pricing models (Binomial, Monte Carlo) and a flexible BacktestEngine that can simulate trading strategies using both internal pre-trained models and arbitrary user-defined Python functions.
Note
The Agent class in agent.py will be marked as legacy/deprecated in favor of the new BacktestEngine in backtest.py, though I will keep Agent for backward compatibility or refactor it to use BacktestEngine internally if feasible.
- Add
BinomialTreePricingclass for American/European options. - Add
MonteCarloPricingclass for path-dependent options (Asian) or complex payoffs.
- Create
BacktestEngineclass. - Support
add_strategy(strategy_func_or_class). - Support
run(data). - return
BacktestResultobject with metrics (Sharpe, Returns, Drawdown) and equity curve.
- Export new options classes.
- Export
BacktestEngine.
- Demonstrate backtesting with a standard
LSTMmodel fromfinlearner. - Demonstrate backtesting with a simple "Golden Cross" SMA python function.
- Compare results.
- Create
tests/test_backtest.pyto verify engine logic (entry/exit/profit calc). - Update
tests/test_options.pyto test new pricing models against known benchmarks (e.g. comparing Binomial with large N to Black-Scholes).
- Run
10_comprehensive_backtest.pyand inspect console output and potential plots.