indexes_rs/v2/cci/
types.rs1use serde::{Deserialize, Serialize};
2use std::collections::VecDeque;
3
4#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)]
6pub struct CCIConfig {
7 pub period: usize,
9 pub overbought: f64,
11 pub oversold: f64,
13 pub extreme_overbought: f64,
15 pub extreme_oversold: f64,
17}
18
19impl Default for CCIConfig {
20 fn default() -> Self {
21 Self {
22 period: 20,
23 overbought: 100.0,
24 oversold: -100.0,
25 extreme_overbought: 200.0,
26 extreme_oversold: -200.0,
27 }
28 }
29}
30
31#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)]
33pub struct CCIInput {
34 pub high: f64,
36 pub low: f64,
38 pub close: f64,
40}
41
42#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)]
44pub enum CCIMarketCondition {
45 ExtremeOverbought,
47 Overbought,
49 Normal,
51 Oversold,
53 ExtremeOversold,
55 Insufficient,
57}
58
59#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)]
61pub struct CCIOutput {
62 pub cci: f64,
64 pub typical_price: f64,
66 pub sma_tp: f64,
68 pub mean_deviation: f64,
70 pub market_condition: CCIMarketCondition,
72 pub distance_from_zero: f64,
74}
75
76#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
78pub struct CCIState {
79 pub config: CCIConfig,
81 pub typical_prices: VecDeque<f64>,
83 pub tp_sum: f64,
85 pub has_sufficient_data: bool,
87}
88
89impl CCIState {
90 pub fn new(config: CCIConfig) -> Self {
91 Self {
92 config,
93 typical_prices: VecDeque::with_capacity(config.period),
94 tp_sum: 0.0,
95 has_sufficient_data: false,
96 }
97 }
98}
99
100#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
102pub enum CCIError {
103 InvalidInput(String),
105 InvalidHLC,
107 InvalidPrice,
109 InvalidPeriod,
111 InvalidThresholds,
113 DivisionByZero,
115}