#![warn(missing_docs)]
#![warn(clippy::all)]
pub mod common;
pub mod prelude {
#[cfg(feature = "trading-math")]
pub use crate::trade_math::simple_api::*;
#[cfg(feature = "backtesting")]
pub use crate::strategy_lib::backtest::{run_backtest, BacktestConfig, BacktestResults};
pub use crate::simple_types::{NyxsOwlError, Price, Result, Signal};
}
pub mod simple_types {
pub type Price = f64;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Signal {
Hold = 0,
Buy = 1,
Sell = 2,
}
#[derive(Debug, thiserror::Error)]
pub enum NyxsOwlError {
#[error("Invalid parameter: {0}")]
InvalidParameter(String),
#[error("Data error: {0}")]
DataError(String),
#[error("Strategy error: {0}")]
StrategyError(String),
#[error("Backtest error: {0}")]
BacktestError(String),
#[error("Missing data: {0}")]
MissingData(String),
}
pub type Result<T> = std::result::Result<T, NyxsOwlError>;
}
#[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;
pub mod advanced_optimizations;
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};
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Owl {
name: String,
wisdom_level: u32,
}
impl Owl {
pub fn new(name: &str) -> Self {
Self {
name: name.to_string(),
wisdom_level: 10,
}
}
pub fn with_wisdom(name: &str, wisdom_level: u32) -> Self {
Self {
name: name.to_string(),
wisdom_level,
}
}
pub fn name(&self) -> &str {
&self.name
}
pub fn wisdom_level(&self) -> u32 {
self.wisdom_level
}
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);
}
}