Skip to content

Commit ecb55f8

Browse files
authored
Vwap test isolated fix (#1)
2 parents 6f4aa8c + c90d783 commit ecb55f8

File tree

140 files changed

+7062
-13406
lines changed

Some content is hidden

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

140 files changed

+7062
-13406
lines changed

Cargo.toml

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
[package]
22
name = "ta-lib-in-rust"
3-
version = "1.0.5"
3+
version = "1.0.6"
44
edition = "2021"
55
description = "A library of technical indicators for financial analysis, similar to TA-Lib"
66
authors = ["Celsis Durham <[email protected]>"]
77
license = "MIT"
8-
repository = "https://github.com/rustic-ml/ta-lib-in-rust"
8+
repository = "https://github.com/rustic-ml/RusTaLib"
99
# Add homepage, often same as repository if no separate project page
10-
homepage = "https://github.com/rustic-ml/ta-lib-in-rust"
10+
homepage = "https://github.com/rustic-ml/RusTaLib"
1111
documentation = "https://docs.rs/ta-lib-in-rust"
1212
readme = "README.md"
1313
keywords = ["finance", "technical-analysis", "trading", "indicators", "stocks"]
@@ -24,23 +24,23 @@ exclude = [
2424
".gitignore",
2525
"Cargo.lock",
2626
"images_processed.png",
27-
"tag_version.sh",
2827

2928
# You can add more patterns:
3029
# "another_folder/",
3130
# "*.log", # Exclude all .log files
3231
]
3332

3433
[dependencies]
35-
polars = { version = "0.46.0", features = ["lazy", "strings", "temporal", "rolling_window"] }
34+
polars = { version = "0.47.1", features = ["lazy", "strings", "temporal", "rolling_window", "parquet", "dtype-categorical", "dtype-struct"] }
3635
chrono = "0.4.34"
3736
thiserror = "2.0.11" # Consider updating if needed, check compatibility
3837
ndarray = "0.16.1" # Consider updating if needed, check compatibility
3938
serde = { version = "1.0", features = ["derive"] }
40-
rand = "0.8.5"
39+
rand = "0.9.1"
4140

4241
[dev-dependencies]
4342
approx = "0.5.1"
43+
tempfile = "3.10.1"
4444

4545
# General examples
4646
[[example]]
@@ -82,6 +82,14 @@ path = "examples/moving_averages_basic.rs"
8282
name = "rsi_basic"
8383
path = "examples/rsi_basic.rs"
8484

85+
[[example]]
86+
name = "vwap_basic"
87+
path = "examples/vwap_basic.rs"
88+
8589
[[example]]
8690
name = "working_with_multi_stock_data"
87-
path = "examples/working_with_multi_stock_data.rs"
91+
path = "examples/working_with_multi_stock_data.rs"
92+
93+
[[example]]
94+
name = "file_reading_example"
95+
path = "examples/file_reading_example.rs"

README.md

Lines changed: 8 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# RusTalib, the Crustacean Financial Analyst 🦀
22

3-
Meet **Rustalib**, your steadfast crustacean companion for navigating the currents of financial markets! This comprehensive Rust library, `ta-lib-in-rust`, provides a powerful toolkit for calculating technical indicators and building trading strategies, all powered by the high-performance [Polars](https://pola.rs/) DataFrame library.
3+
Meet **Rustalib**, your steadfast crustacean companion for navigating the currents of financial markets! This comprehensive Rust library, `ta-lib-in-rust`, provides a powerful toolkit for calculating technical indicators, all powered by the high-performance [Polars](https://pola.rs/) DataFrame library.
44

55
Whether you're charting, backtesting, or building live trading systems, Rustalib is here to help you process market data with speed and precision.
66

@@ -11,11 +11,11 @@ Whether you're charting, backtesting, or building live trading systems, Rustalib
1111

1212
## Project Overview
1313

14-
**Technical Indicators** aims to provide a robust, extensible, and efficient toolkit for quantitative finance, algorithmic trading, and data science in Rust. The library is designed for:
14+
**ta-lib-in-rust** provides a robust, extensible, and efficient toolkit for quantitative finance, algorithmic trading, and data science in Rust. The library is designed for:
1515
- **Fast, vectorized computation** using Polars DataFrames
1616
- **Easy integration** with modern Rust data workflows
17-
- **Modular design**: Use only the indicators or strategies you need
18-
- **Extensibility**: Add your own indicators or strategies easily
17+
- **Modular design**: Use only the indicators you need
18+
- **Extensibility**: Add your own indicators easily
1919

2020
Whether you are backtesting, researching, or building production trading systems, this crate offers a solid foundation for technical analysis in Rust.
2121

@@ -24,7 +24,6 @@ Whether you are backtesting, researching, or building production trading systems
2424
## Features
2525

2626
- **Wide range of indicators**: Moving averages, oscillators, volatility, volume, trend, momentum, and more
27-
- **Strategy modules**: Combine indicators into rule-based trading strategies
2827
- **Convenience functions**: Add a suite of indicators to your DataFrame in one call
2928
- **CSV and DataFrame workflows**: Read, process, and save data efficiently
3029
- **Well-documented and tested**
@@ -37,51 +36,6 @@ Whether you are backtesting, researching, or building production trading systems
3736
- **Volume**: On-Balance Volume (OBV), Chaikin Money Flow (CMF)
3837
- **Other**: Price returns, daily range, lagged prices, rolling returns/volatility, cyclical time features
3938

40-
### Planned/Upcoming
41-
- Average Directional Index (ADX)
42-
- Rate of Change (ROC)
43-
44-
---
45-
46-
## Feature Selection
47-
48-
This crate supports feature selection, allowing you to include only the parts you need:
49-
50-
### Types of Features
51-
- **indicators**: Only include technical indicator calculations
52-
- **strategies**: Only include trading strategies
53-
- **all**: Include both indicators and strategies (default)
54-
55-
### How to Choose Features in Cargo.toml
56-
57-
You can enable features in your `Cargo.toml` like this:
58-
59-
```toml
60-
[dependencies]
61-
ta-lib-in-rust = { version = "x.y.z", features = ["strategies"] } # Only strategies
62-
ta-lib-in-rust = { version = "x.y.z", features = ["indicators"] } # Only indicators
63-
ta-lib-in-rust = { version = "x.y.z", features = ["all"] } # Everything (default)
64-
```
65-
66-
If you omit the `features` key, the default is `all`.
67-
68-
### Programmatic Feature Selection
69-
70-
You can also select features at runtime using the `FeatureSelection` enum and `select_features` function:
71-
72-
```rust
73-
use ta_lib_in_rust::{FeatureSelection, select_features};
74-
let mut df = ...; // your Polars DataFrame
75-
// To add only indicators:
76-
let result = select_features(&mut df, FeatureSelection::Indicators);
77-
// To run a strategy:
78-
let result = select_features(&mut df, FeatureSelection::Strategy { strategy_name: "daily_1", params: None });
79-
// To do both:
80-
let result = select_features(&mut df, FeatureSelection::All { strategy_name: "daily_1", params: None });
81-
```
82-
83-
See the crate documentation for more details and examples.
84-
8539
---
8640

8741
## Installation
@@ -91,7 +45,6 @@ Add to your `Cargo.toml`:
9145
```toml
9246
[dependencies]
9347
ta-lib-in-rust = "*" # Or specify a version
94-
tokio = { version = "1", features = ["full"] } # If using async examples
9548
polars = { version = "0.46", features = ["lazy", "dtype-full"] }
9649
```
9750

@@ -138,50 +91,7 @@ fn main() -> PolarsResult<()> {
13891
}
13992
```
14093

141-
### 3. Run a Strategy and Analyze Results
142-
```rust
143-
use polars::prelude::*;
144-
use ta_lib_in_rust::strategy::minute::enhanced_minute_strategy::{
145-
run_strategy, calculate_performance, StrategyParams
146-
};
147-
148-
fn main() -> PolarsResult<()> {
149-
let df = CsvReadOptions::default()
150-
.with_has_header(true)
151-
.try_into_reader_with_file_path(Some("examples/AAPL_minute_ohlcv.csv".into()))?
152-
.finish()?;
153-
154-
// Note: This library expects lowercase column names (open, high, low, close, volume)
155-
// If your CSV has uppercase names, you need to rename them:
156-
let df = df.lazy()
157-
.select([
158-
col("Open").alias("open"),
159-
col("High").alias("high"),
160-
col("Low").alias("low"),
161-
col("Close").alias("close"),
162-
col("Volume").cast(DataType::Float64).alias("volume"),
163-
])
164-
.collect()?;
165-
166-
let params = StrategyParams::default();
167-
let signals = run_strategy(&df, &params)?;
168-
let (
169-
final_value, total_return, num_trades, win_rate, max_drawdown, profit_factor, avg_profit_per_trade
170-
) = calculate_performance(
171-
df.column("close")?,
172-
&signals.buy_signals,
173-
&signals.sell_signals,
174-
&signals.stop_levels,
175-
&signals.target_levels,
176-
10000.0,
177-
true,
178-
);
179-
println!("Final Value: ${:.2}, Total Return: {:.2}%", final_value, total_return);
180-
Ok(())
181-
}
182-
```
183-
184-
### 4. Reading Data from CSV and Saving Results
94+
### 3. Reading Data from CSV and Saving Results
18595
```rust
18696
let df = CsvReadOptions::default()
18797
.with_has_header(true)
@@ -201,7 +111,7 @@ let mut df = df.lazy()
201111
])
202112
.collect()?;
203113

204-
// ... apply indicators or strategies ...
114+
// ... apply indicators ...
205115
CsvWriter::new(std::io::BufWriter::new(std::fs::File::create("results.csv")?))
206116
.finish(&mut df)?;
207117
```
@@ -212,25 +122,22 @@ CsvWriter::new(std::io::BufWriter::new(std::fs::File::create("results.csv")?))
212122

213123
See the [`examples/`](examples/) directory for:
214124
- **Basic indicator usage** (SMA, EMA, RSI, MACD, Bollinger Bands, etc.)
215-
- **Strategy backtests** (minute and daily)
216125
- **CSV workflows** for real-world data
126+
- **Multi-stock analysis** with cross-asset comparisons
217127
- **Saving and analyzing results**
218128

219129
## Important Notes
220130

221131
### Column Name Sensitivity
222132
This library expects lowercase column names (`open`, `high`, `low`, `close`, `volume`) in DataFrames. When working with CSVs that might have different case formats (e.g., `Open`, `High`, etc.), make sure to rename the columns using Polars' selection and aliasing capabilities as shown in the examples above.
223133

224-
### Working with Multiple Stock Data Files
225-
The examples directory contains sample code for running strategies on multiple stocks (AAPL, GOOGL, MSFT). You can use these as templates for your own multi-asset analysis.
226-
227134
---
228135

229136
## Contributing
230137

231138
Contributions are welcome! Please:
232139
- Open issues for bugs, questions, or feature requests
233-
- Submit pull requests for new indicators, strategies, or improvements
140+
- Submit pull requests for new indicators or improvements
234141
- Follow Rust best practices and add tests/docs for new code
235142

236143
---

examples/README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@ Options market specific trading strategies:
3535
- `options/volatility_strategies.rs` - Demonstrates volatility-based options strategies
3636
- `options/delta_neutral.rs` - Shows delta-neutral options strategies implementation
3737

38+
## Multi-Asset Analysis Examples
39+
40+
Examples for processing and analyzing multiple assets:
41+
42+
- `working_with_multi_stock_data.rs` - Demonstrates how to load, process, and compare technical indicators across multiple stocks. Shows how to handle data from different CSV sources, standardize column formats, calculate key technical indicators, and perform cross-stock comparison analysis.
43+
3844
## Running the Examples
3945

4046
To run any example, use the following command from the project root:
@@ -48,6 +54,7 @@ For instance:
4854
```bash
4955
cargo run --example general/basic_indicators
5056
cargo run --example stock/trend_following
57+
cargo run --example working_with_multi_stock_data
5158
```
5259

5360
## Notes for Real-World Application

0 commit comments

Comments
 (0)