Crates.io | nyxs_owl |
lib.rs | nyxs_owl |
version | 0.7.2 |
created_at | 2025-05-19 22:56:36.446394+00 |
updated_at | 2025-06-16 23:58:56.590221+00 |
description | A comprehensive Rust library for trading, forecasting, and financial analysis |
homepage | |
repository | https://github.com/rustic-ml/NyxsOwl |
max_upload_size | |
id | 1680524 |
size | 937,462 |
Production-ready financial analysis library for Rust
NyxsOwl provides institutional-grade tools for quantitative finance, technical analysis, and algorithmic trading. Built for performance, reliability, and ease of use.
Named after Nyx (Greek goddess of night, strategic advantage) and Bubo (wise owl, wisdom in darkness) - embodying the essence of strategic financial analysis through wisdom, patience, and precision.
Add to your Cargo.toml
:
[dependencies]
nyxs_owl = "0.7.2"
Production-ready indicators with comprehensive test coverage (125/125 unit tests passing + memory optimized)
use nyxs_owl::trade_math::*;
let mut rsi = oscillators::RelativeStrengthIndex::new(14)?;
let mut bb = volatility::BollingerBands::new(20, 2.0)?;
for price in prices {
rsi.update(price)?;
println!("RSI: {:.2}", rsi.value()?);
}
Advanced forecasting with multiple model support (Enhanced with latest dependencies)
use nyxs_owl::forecast_trade::easy::*;
let (forecast, model) = auto_forecast(timestamps, values, 10)?;
println!("Best model: {} | Forecast: {:?}", model, forecast);
Memory-optimized, high-performance backtesting engine with Polars 0.47.x
use nyxs_owl::strategy_lib::backtest::*;
let config = BacktestConfig {
initial_capital: 100_000.0,
commission: 0.001,
slippage: 0.0005,
position_size: 1.0,
};
let results = run_backtest(&data, &signals, &config)?;
println!("Sharpe Ratio: {:.2}", results.sharpe_ratio);
use nyxs_owl::trade_math::{moving_averages::*, oscillators::*};
fn analyze_stock(prices: &[f64]) -> Result<(), Box<dyn std::error::Error>> {
let mut sma = SimpleMovingAverage::new(20)?;
let mut rsi = RelativeStrengthIndex::new(14)?;
for &price in prices {
sma.update(price)?;
rsi.update(price)?;
let signal = match rsi.value()? {
x if x > 70.0 => "SELL - Overbought",
x if x < 30.0 => "BUY - Oversold",
_ => "HOLD"
};
println!("Price: {:.2} | SMA: {:.2} | RSI: {:.2} | Signal: {}",
price, sma.value()?, rsi.value()?, signal);
}
Ok(())
}
use nyxs_owl::forecast_trade::easy::*;
use chrono::{DateTime, Utc, Duration};
fn forecast_prices() -> Result<(), Box<dyn std::error::Error>> {
// Generate sample data
let now = Utc::now();
let timestamps: Vec<DateTime<Utc>> = (0..30)
.map(|i| now - Duration::days(30 - i))
.collect();
let prices: Vec<f64> = (0..30)
.map(|i| 100.0 + i as f64 + (i as f64 * 0.1).sin() * 5.0)
.collect();
// Auto-select best model and forecast
let (forecast, model_name) = auto_forecast(timestamps, prices, 5)?;
println!("Selected model: {}", model_name);
println!("5-day forecast: {:?}", forecast);
// Compare multiple models
let ma_forecast = forecast_moving_average(&prices, 5, 5)?;
let es_forecast = forecast_exponential_smoothing(&prices, 0.3, 5)?;
let arima_forecast = forecast_arima(&prices, (1, 1, 1), 5)?;
println!("Moving Average: {:?}", ma_forecast);
println!("Exp Smoothing: {:?}", es_forecast);
println!("ARIMA: {:?}", arima_forecast);
Ok(())
}
use nyxs_owl::strategy_lib::backtest::*;
use polars::prelude::*;
fn backtest_strategy() -> Result<(), Box<dyn std::error::Error>> {
// Load market data (OHLCV format)
let data = df! {
"timestamp" => [1, 2, 3, 4, 5],
"open" => [100.0, 101.0, 102.0, 101.5, 103.0],
"high" => [101.0, 102.5, 103.0, 102.0, 104.0],
"low" => [99.5, 100.5, 101.0, 100.5, 102.0],
"close" => [100.5, 102.0, 101.5, 103.0, 103.5],
"volume" => [1000, 1500, 1200, 1800, 1600],
}?;
// Generate signals (1 = Buy, -1 = Sell, 0 = Hold)
let signals = Series::new("signal".into(), [1, 0, -1, 0, 1]);
// Configure backtest
let config = BacktestConfig {
initial_capital: 100_000.0,
commission: 0.001, // 0.1% commission
slippage: 0.0005, // 0.05% slippage
position_size: 1.0, // 100% of capital
};
// Run backtest
let results = run_backtest(&data, &signals, &config)?;
// Display results
println!("=== Backtest Results ===");
println!("Total Return: {:.2}%", results.total_return * 100.0);
println!("Sharpe Ratio: {:.2}", results.sharpe_ratio);
println!("Max Drawdown: {:.2}%", results.max_drawdown * 100.0);
println!("Win Rate: {:.2}%", results.win_rate * 100.0);
println!("Total Trades: {}", results.total_trades);
Ok(())
}
Control what you include:
[dependencies]
# Minimal - just technical indicators
nyxs_owl = { version = "0.7.2", default-features = false, features = ["trading-math"] }
# With forecasting
nyxs_owl = { version = "0.7.2", features = ["trading-math", "forecasting"] }
# Full features
nyxs_owl = { version = "0.7.2", features = ["all"] }
NyxsOwl is built for production environments:
examples/
directoryLicensed under either of:
at your option.