1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
//! Backtesting engine for trading strategy simulation.
//!
//! This module provides a complete backtesting framework with:
//! - Expression-based strategy builder for custom entry/exit conditions
//! - Pre-built strategies (SMA, RSI, MACD, Bollinger, SuperTrend, Donchian)
//! - Full technical indicator coverage (40+ indicators)
//! - Position tracking with long/short support
//! - Stop-loss, take-profit, and trailing stop management
//! - Comprehensive performance metrics
//!
//! # Quick Start
//!
//! ```no_run
//! use finance_query::{Ticker, Interval, TimeRange};
//! use finance_query::backtesting::{SmaCrossover, BacktestConfig};
//!
//! # async fn example() -> Result<(), Box<dyn std::error::Error>> {
//! let ticker = Ticker::new("AAPL").await?;
//! let result = ticker.backtest(
//! SmaCrossover::new(10, 20),
//! Interval::OneDay,
//! TimeRange::OneYear,
//! None,
//! ).await?;
//!
//! println!("Return: {:.2}%", result.metrics.total_return_pct);
//! println!("Sharpe: {:.2}", result.metrics.sharpe_ratio);
//! println!("Max Drawdown: {:.2}%", result.metrics.max_drawdown_pct * 100.0);
//! # Ok(())
//! # }
//! ```
//!
//! # Custom Strategies with StrategyBuilder
//!
//! Build custom strategies using the fluent builder API:
//!
//! ```ignore
//! use finance_query::backtesting::StrategyBuilder;
//! use finance_query::backtesting::refs::*;
//! use finance_query::backtesting::condition::*;
//!
//! let strategy = StrategyBuilder::new("RSI Mean Reversion")
//! .entry(
//! rsi(14).crosses_below(30.0)
//! .and(price().above_ref(sma(200)))
//! )
//! .exit(
//! rsi(14).crosses_above(70.0)
//! .or(stop_loss(0.05))
//! )
//! .build();
//! ```
//!
//! # Configuration
//!
//! ```no_run
//! use finance_query::backtesting::BacktestConfig;
//!
//! let config = BacktestConfig::builder()
//! .initial_capital(50_000.0)
//! .commission_pct(0.001) // 0.1% per trade
//! .slippage_pct(0.0005) // 0.05% slippage
//! .stop_loss_pct(0.05) // 5% stop-loss
//! .take_profit_pct(0.15) // 15% take-profit
//! .allow_short(true)
//! .build()
//! .unwrap();
//! ```
//!
//! # Pre-built Strategies
//!
//! | Strategy | Parameters | Description |
//! |----------|------------|-------------|
//! | [`SmaCrossover`] | fast, slow periods | Dual SMA crossover |
//! | [`RsiReversal`] | period, oversold, overbought | Mean reversion on RSI |
//! | [`MacdSignal`] | fast, slow, signal periods | MACD line crossover |
//! | [`BollingerMeanReversion`] | period, std_dev | Buy at lower band |
//! | [`SuperTrendFollow`] | period, multiplier | Trend following |
//! | [`DonchianBreakout`] | period | Channel breakout |
//!
//! # Available Indicators
//!
//! The strategy builder supports all indicators via [`refs`]:
//!
//! - **Moving Averages**: `sma`, `ema`, `wma`, `dema`, `tema`, `hma`, `vwma`, `alma`, `mcginley`
//! - **Oscillators**: `rsi`, `stochastic`, `stochastic_rsi`, `cci`, `williams_r`, `cmo`, `awesome_oscillator`
//! - **Trend**: `macd`, `adx`, `aroon`, `supertrend`, `ichimoku`, `parabolic_sar`
//! - **Volatility**: `atr`, `bollinger`, `keltner`, `donchian`, `choppiness_index`
//! - **Volume**: `obv`, `vwap`, `mfi`, `cmf`, `chaikin_oscillator`, `accumulation_distribution`, `balance_of_power`
//!
//! # Available Conditions
//!
//! Build conditions via [`condition`]:
//!
//! - **Comparisons**: `above()`, `below()`, `crosses_above()`, `crosses_below()`, `between()`, `equals()`
//! - **Composites**: `and()`, `or()`, `not()`
//! - **Position Management**: `stop_loss()`, `take_profit()`, `trailing_stop()`, `trailing_take_profit()`
//! - **Position State**: `has_position()`, `no_position()`, `is_long()`, `is_short()`, `in_profit()`, `in_loss()`
// Re-export main types
pub use ;
pub use BacktestEngine;
pub use ;
pub use ;
pub use ;
pub use ;
// Re-export strategy types
pub use ;
// Re-export strategy builder
pub use StrategyBuilder;
// Re-export pre-built strategies
pub use ;
// Re-export ensemble types
pub use ;
// Re-export optimiser types for convenience
pub use ;
// Re-export walk-forward types
pub use ;
// Re-export Monte Carlo types
pub use ;
// Re-export comparison types
pub use ;
// Re-export resample utility
pub use resample;