nyxs_owl 0.5.0

A comprehensive Rust library for trading, forecasting, and financial analysis
Documentation
//! # NyxsOwl
//!
//! A comprehensive Rust library for trading, forecasting, and financial analysis
//! Named after Nyx (Greek goddess of night, symbolizing strategic advantage) and
//! Bubo (wise owl, representing wisdom and strategy).
//!
//! ## Quick Start
//!
//! ```rust
//! use nyxs_owl::prelude::*;
//!
//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
//! let prices = vec![100.0, 102.0, 101.5, 103.0, 104.5];
//!
//! // Simple technical analysis
//! let sma_values = sma(&prices, 3)?;
//! let rsi_values = rsi(&prices, 14)?;
//!
//! println!("SMA: {:?}", sma_values);
//! # Ok(())
//! # }
//! ```

#![warn(missing_docs)]
#![warn(clippy::all)]

// Common types and utilities
pub mod common;

pub mod prelude {
    //! Common imports for typical NyxsOwl usage
    //!
    //! This module provides a convenient way to import the most commonly used
    //! types and functions with a single `use nyxs_owl::prelude::*;` statement.

    // Re-export essential technical indicators
    #[cfg(feature = "trading-math")]
    pub use crate::trade_math::simple_api::*;

    // Re-export backtesting essentials
    #[cfg(feature = "backtesting")]
    pub use crate::strategy_lib::backtest::{run_backtest, BacktestConfig, BacktestResults};

    // Re-export common types and new simplified types
    pub use crate::simple_types::{NyxsOwlError, Price, Result, Signal};
}

pub mod simple_types {
    //! Shared types and error definitions for the simplified API

    /// Price type alias for clarity
    pub type Price = f64;

    /// Trading signal enumeration
    #[derive(Debug, Clone, Copy, PartialEq, Eq)]
    pub enum Signal {
        /// Hold current position
        Hold = 0,
        /// Buy signal
        Buy = 1,
        /// Sell signal
        Sell = 2,
    }

    /// Main error type for NyxsOwl operations
    #[derive(Debug, thiserror::Error)]
    pub enum NyxsOwlError {
        /// Invalid parameter provided
        #[error("Invalid parameter: {0}")]
        InvalidParameter(String),

        /// Data processing error
        #[error("Data error: {0}")]
        DataError(String),

        /// Strategy execution error
        #[error("Strategy error: {0}")]
        StrategyError(String),

        /// Backtest execution error
        #[error("Backtest error: {0}")]
        BacktestError(String),

        /// Missing required data
        #[error("Missing data: {0}")]
        MissingData(String),
    }

    /// Result type alias for convenience
    pub type Result<T> = std::result::Result<T, NyxsOwlError>;
}

// Export main modules with feature gates
#[cfg(feature = "trading-math")]
pub mod trade_math;

#[cfg(feature = "day-trading")]
pub mod day_trade;

#[cfg(feature = "minute-trading")]
pub mod minute_trade;

#[cfg(feature = "forecasting")]
pub mod forecast_trade;

#[cfg(feature = "backtesting")]
pub mod strategy_lib;

pub mod performance_utils;

// Always include advanced optimizations
pub mod advanced_optimizations;

// Re-export commonly used types for convenience
pub use trade_math::{MathError, Result as MathResult};

#[cfg(feature = "day-trading")]
pub use day_trade::{DailyOhlcv, Signal, TradingStrategy};

#[cfg(feature = "minute-trading")]
pub use minute_trade::{MinuteOhlcv, ScalpingStrategy};

#[cfg(feature = "forecasting")]
pub use forecast_trade::{ForecastModel, ForecastResult, TimeSeriesData};

/// An owl from the NyxsOwl project.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Owl {
    name: String,
    wisdom_level: u32,
}

impl Owl {
    /// Creates a new owl with the given name and a default wisdom level of 10.
    ///
    /// # Examples
    ///
    /// ```
    /// use nyxs_owl::Owl;
    ///
    /// let owl = Owl::new("Hedwig");
    /// assert_eq!(owl.name(), "Hedwig");
    /// assert_eq!(owl.wisdom_level(), 10);
    /// ```
    pub fn new(name: &str) -> Self {
        Self {
            name: name.to_string(),
            wisdom_level: 10,
        }
    }

    /// Creates a new owl with a specific name and wisdom level.
    ///
    /// # Examples
    ///
    /// ```
    /// use nyxs_owl::Owl;
    ///
    /// let owl = Owl::with_wisdom("Archimedes", 100);
    /// assert_eq!(owl.name(), "Archimedes");
    /// assert_eq!(owl.wisdom_level(), 100);
    /// ```
    pub fn with_wisdom(name: &str, wisdom_level: u32) -> Self {
        Self {
            name: name.to_string(),
            wisdom_level,
        }
    }

    /// Returns the name of the owl.
    pub fn name(&self) -> &str {
        &self.name
    }

    /// Returns the wisdom level of the owl.
    pub fn wisdom_level(&self) -> u32 {
        self.wisdom_level
    }

    /// Increases the owl's wisdom by the given amount.
    pub fn gain_wisdom(&mut self, amount: u32) {
        self.wisdom_level += amount;
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_new_owl() {
        let owl = Owl::new("Hedwig");
        assert_eq!(owl.name(), "Hedwig");
        assert_eq!(owl.wisdom_level(), 10);
    }

    #[test]
    fn test_with_wisdom() {
        let owl = Owl::with_wisdom("Archimedes", 100);
        assert_eq!(owl.name(), "Archimedes");
        assert_eq!(owl.wisdom_level(), 100);
    }

    #[test]
    fn test_gain_wisdom() {
        let mut owl = Owl::new("Hedwig");
        owl.gain_wisdom(5);
        assert_eq!(owl.wisdom_level(), 15);
    }
}