Skip to content

Commit 612c7cc

Browse files
committed
Fixing all the warnings.
1 parent 153530f commit 612c7cc

File tree

8 files changed

+17
-18
lines changed

8 files changed

+17
-18
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "ta-lib-in-rust"
3-
version = "1.0.4"
3+
version = "1.0.5"
44
edition = "2021"
55
description = "A library of technical indicators for financial analysis, similar to TA-Lib"
66
authors = ["Celsis Durham <[email protected]>"]

src/indicators/moving_averages/vwap.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ pub fn calculate_vwap(df: &DataFrame, lookback: usize) -> PolarsResult<Series> {
4848

4949
// Calculate price * volume (cumulative money flow)
5050
let mut price_volume = Vec::with_capacity(df.height());
51-
for i in 0..df.height() {
51+
for (i, _) in typical_prices.iter().enumerate().take(df.height()) {
5252
price_volume.push(typical_prices[i] * volume.get(i).unwrap_or(0.0));
5353
}
5454

@@ -60,8 +60,8 @@ pub fn calculate_vwap(df: &DataFrame, lookback: usize) -> PolarsResult<Series> {
6060
let mut cumulative_pv = 0.0;
6161
let mut cumulative_volume = 0.0;
6262

63-
for i in 0..df.height() {
64-
cumulative_pv += price_volume[i];
63+
for (i, &pv) in price_volume.iter().enumerate().take(df.height()) {
64+
cumulative_pv += pv;
6565
cumulative_volume += volume.get(i).unwrap_or(0.0);
6666

6767
if cumulative_volume > 0.0 {
@@ -78,8 +78,8 @@ pub fn calculate_vwap(df: &DataFrame, lookback: usize) -> PolarsResult<Series> {
7878
let mut window_pv = 0.0;
7979
let mut window_volume = 0.0;
8080

81-
for j in start_idx..=i {
82-
window_pv += price_volume[j];
81+
for (j, &pv) in price_volume.iter().enumerate().take(i + 1).skip(start_idx) {
82+
window_pv += pv;
8383
window_volume += volume.get(j).unwrap_or(0.0);
8484
}
8585

src/indicators/oscillators/stochastic.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ pub fn calculate_stochastic(
102102
let mut k_values = Vec::with_capacity(df.height());
103103

104104
// Fill initial values with NaN
105-
for i in 0..k_period + slowing - 2 {
105+
for _i in 0..k_period + slowing - 2 {
106106
k_values.push(f64::NAN);
107107
}
108108

@@ -133,7 +133,7 @@ pub fn calculate_stochastic(
133133
let mut d_values = Vec::with_capacity(df.height());
134134

135135
// Fill initial values with NaN
136-
for i in 0..k_period + slowing + d_period - 3 {
136+
for _i in 0..k_period + slowing + d_period - 3 {
137137
d_values.push(f64::NAN);
138138
}
139139

src/indicators/volatility/atr.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,15 @@ pub fn calculate_atr(df: &DataFrame, window: usize) -> PolarsResult<Series> {
5151

5252
// Initialize ATR with simple average of first window TR values
5353
let mut atr = 0.0;
54-
for i in 0..window {
55-
atr += tr_values[i];
54+
for &tr in tr_values.iter().take(window) {
55+
atr += tr;
5656
}
5757
atr /= window as f64;
5858
atr_values.push(atr);
5959

6060
// Apply Wilder's smoothing formula: ATR(t) = ((window-1) * ATR(t-1) + TR(t)) / window
61-
for i in window..tr_values.len() {
62-
atr = ((window as f64 - 1.0) * atr + tr_values[i]) / window as f64;
61+
for &tr in tr_values.iter().skip(window) {
62+
atr = ((window as f64 - 1.0) * atr + tr) / window as f64;
6363
atr_values.push(atr);
6464
}
6565

src/indicators/volume/cmf.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ pub fn calculate_cmf(df: &DataFrame, window: usize) -> PolarsResult<Series> {
6666

6767
// Calculate Money Flow Multiplier
6868
let mut money_flow_multipliers = Vec::with_capacity(df.height());
69-
for i in 0..df.height() {
69+
for (i, _) in high.iter().enumerate().take(df.height()) {
7070
let high_val = high.get(i).unwrap_or(f64::NAN);
7171
let low_val = low.get(i).unwrap_or(f64::NAN);
7272
let close_val = close.get(i).unwrap_or(f64::NAN);
@@ -113,8 +113,7 @@ pub fn calculate_cmf(df: &DataFrame, window: usize) -> PolarsResult<Series> {
113113
let mut has_nan = false;
114114

115115
// Sum up money flow volumes and volumes over the window
116-
for j in i - window..i {
117-
let mfv = money_flow_volumes[j];
116+
for (j, &mfv) in money_flow_volumes.iter().enumerate().take(i).skip(i - window) {
118117
let vol = volume.get(j).unwrap_or(f64::NAN);
119118

120119
if mfv.is_nan() || vol.is_nan() {

src/indicators/volume/mfi.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ pub fn calculate_mfi(df: &DataFrame, window: usize) -> PolarsResult<Series> {
5959

6060
// Calculate the typical price: (high + low + close) / 3
6161
let mut typical_prices = Vec::with_capacity(df.height());
62-
for i in 0..df.height() {
62+
for (i, _) in high.iter().enumerate().take(df.height()) {
6363
let high_val = high.get(i).unwrap_or(f64::NAN);
6464
let low_val = low.get(i).unwrap_or(f64::NAN);
6565
let close_val = close.get(i).unwrap_or(f64::NAN);

src/strategy/daily/multi_indicator_daily_3.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,7 @@ pub fn calculate_performance(
515515
let price = close.get(i).unwrap_or(0.0);
516516
let buy_signal = buy_signals[i];
517517
let sell_signal = sell_signals[i];
518-
let position_size = position_sizes[i].min(1.0).max(0.1); // Ensure position size is between 0.1 and 1.0
518+
let position_size = position_sizes[i].clamp(0.1, 1.0); // Ensure position size is between 0.1 and 1.0
519519

520520
if buy_signal == 1 {
521521
// Use position sizing

src/strategy/minute/multi_indicator_minute_2.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ pub fn run_strategy(
354354
// Smaller position for higher volatility
355355
let base_position = 1.0 / (params.atr_position_size_factor * atr_val / price);
356356
// Clamp between 0.1 and 1.0
357-
base_position.max(0.1).min(1.0)
357+
base_position.clamp(0.1, 1.0)
358358
} else {
359359
1.0 // Full position if not using ATR sizing
360360
};

0 commit comments

Comments
 (0)