Skip to content

Commit 6f4aa8c

Browse files
committed
refactoring tests.
1 parent 5402049 commit 6f4aa8c

60 files changed

Lines changed: 1993 additions & 3219 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Cargo.toml

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ exclude = [
1919
# Use a trailing slash '/' to ensure it's treated as a directory.
2020
"examples/",
2121
"target/",
22+
"src/test/",
2223

2324
".gitignore",
2425
"Cargo.lock",
@@ -36,6 +37,51 @@ chrono = "0.4.34"
3637
thiserror = "2.0.11" # Consider updating if needed, check compatibility
3738
ndarray = "0.16.1" # Consider updating if needed, check compatibility
3839
serde = { version = "1.0", features = ["derive"] }
40+
rand = "0.8.5"
3941

4042
[dev-dependencies]
41-
approx = "0.5.1"
43+
approx = "0.5.1"
44+
45+
# General examples
46+
[[example]]
47+
name = "general_basic_indicators"
48+
path = "examples/general/basic_indicators.rs"
49+
50+
# Stock market strategy examples
51+
[[example]]
52+
name = "stock_trend_following"
53+
path = "examples/stock/trend_following.rs"
54+
55+
[[example]]
56+
name = "stock_mean_reversion"
57+
path = "examples/stock/mean_reversion.rs"
58+
59+
# Options trading strategy examples
60+
[[example]]
61+
name = "options_vertical_spreads"
62+
path = "examples/options/vertical_spreads.rs"
63+
64+
[[example]]
65+
name = "options_iron_condor"
66+
path = "examples/options/iron_condor.rs"
67+
68+
# Basic indicators examples
69+
[[example]]
70+
name = "bollinger_bands_basic"
71+
path = "examples/bollinger_bands_basic.rs"
72+
73+
[[example]]
74+
name = "macd_basic"
75+
path = "examples/macd_basic.rs"
76+
77+
[[example]]
78+
name = "moving_averages_basic"
79+
path = "examples/moving_averages_basic.rs"
80+
81+
[[example]]
82+
name = "rsi_basic"
83+
path = "examples/rsi_basic.rs"
84+
85+
[[example]]
86+
name = "working_with_multi_stock_data"
87+
path = "examples/working_with_multi_stock_data.rs"

examples/README.md

Lines changed: 39 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,64 @@
1-
# Technical Indicators Examples
1+
# Technical Analysis and Trading Strategy Examples
22

3-
This directory contains simple examples showing how to use the technical indicators provided by this library.
3+
This directory contains examples showing how to use the technical indicators and trading strategies provided by this library.
44

5-
## Basic Examples
5+
## Directory Structure
66

7-
- `rsi_basic.rs` - Shows how to calculate and interpret the Relative Strength Index
8-
- `macd_basic.rs` - Demonstrates the Moving Average Convergence Divergence indicator
9-
- `bollinger_bands_basic.rs` - Example of Bollinger Bands volatility indicator
10-
- `moving_averages_basic.rs` - Comparison of different moving average types (SMA, EMA, WMA)
7+
The examples are organized by category:
118

12-
## CSV Reading Examples
9+
- `general/` - Basic technical indicators that apply to all markets
10+
- `stock/` - Stock market specific strategies and indicators
11+
- `options/` - Options trading strategies and volatility analysis
12+
- `csv/` - Sample CSV data files for testing
1313

14-
Several examples demonstrate how to load data from CSV files:
14+
## General Technical Indicators
1515

16-
- `compare_minute_indicator_strategies.rs` - Shows how to read minute-level OHLCV data and convert integer volume to float
17-
- `compare_multi_indicator_strategies.rs` - Demonstrates proper CSV reading with column renaming
18-
- `multi_indicator_strategy_for_daily_ohlcv.rs` - Shows CSV reading with a predefined schema
19-
- `enhanced_minute_strategy_example.rs` - Demonstrates a multi-indicator intraday strategy for minute-level OHLCV data. Runs a full backtest, prints performance metrics, and saves all signals and indicators to `enhanced_minute_strategy_results.csv` for further analysis.
16+
Basic examples showing fundamental technical analysis concepts:
2017

21-
Note that when using Polars 0.46.0, CSV files should be read using the `CsvReadOptions` approach:
18+
- `general/basic_indicators.rs` - Shows how to calculate and interpret various technical indicators including moving averages, oscillators, and Bollinger Bands
2219

23-
```rust
24-
// Read a CSV file with headers
25-
let df = CsvReadOptions::default()
26-
.with_has_header(true)
27-
.try_into_reader_with_file_path(Some("path/to/file.csv".into()))?
28-
.finish()?;
29-
```
20+
## Stock Market Strategies
21+
22+
Stock market specific trading strategies:
23+
24+
- `stock/trend_following.rs` - Demonstrates a trend following strategy using EMAs and RSI
25+
- `stock/mean_reversion.rs` - Shows a mean reversion strategy based on Z-score
26+
- `stock/breakout.rs` - Implements a breakout strategy with volume confirmation
27+
- `stock/volume_based.rs` - Shows volume-based strategies for stock trading
28+
29+
## Options Trading Strategies
30+
31+
Options market specific trading strategies:
32+
33+
- `options/vertical_spreads.rs` - Demonstrates vertical spread strategies (bull put and bear call spreads)
34+
- `options/iron_condor.rs` - Shows how to implement iron condor strategies for range-bound markets
35+
- `options/volatility_strategies.rs` - Demonstrates volatility-based options strategies
36+
- `options/delta_neutral.rs` - Shows delta-neutral options strategies implementation
3037

3138
## Running the Examples
3239

3340
To run any example, use the following command from the project root:
3441

3542
```bash
36-
cargo run --example <example_name>
43+
cargo run --example <folder>/<example_name>
3744
```
3845

3946
For instance:
4047

4148
```bash
42-
cargo run --example rsi_basic
49+
cargo run --example general/basic_indicators
50+
cargo run --example stock/trend_following
4351
```
4452

45-
## Notes
53+
## Notes for Real-World Application
4654

47-
These examples use synthetic data for demonstration purposes. In real-world applications, you would:
55+
These examples use synthetic data for demonstration purposes. In real-world applications, you should:
4856

4957
- Import actual market data (CSV files, APIs, etc.)
50-
- Apply proper backtesting methodology
51-
- Consider transaction costs and slippage
52-
- Combine multiple indicators for confirmation
53-
- Implement risk management strategies
58+
- Apply proper backtesting methodology with realistic assumptions
59+
- Consider transaction costs, slippage, and market impact
60+
- Implement proper position sizing and risk management
61+
- Test strategies across different market conditions
62+
- Consider regulatory and tax implications
5463

55-
The examples are designed to be simple and focus on demonstrating the basic usage of each indicator.
64+
Each example provides a simplified implementation to demonstrate the concepts. In production trading systems, more sophisticated implementations would be required.

0 commit comments

Comments
 (0)