fix(warnings): clean all compiler warnings across crate
- Remove unused imports (Array1, statrs, Uniform, VecDeque, PI, assert_abs_diff_eq) - Prefix unused variables with underscore (log_likelihood, cash, position, positions, v100) - Add #[allow(dead_code)] for intentionally unused utility functions and structs
This commit is contained in:
@@ -125,8 +125,8 @@ pub fn backtest_optimal_switching(
|
||||
if position != 0 {
|
||||
let final_price = spread[spread.len() - 1];
|
||||
let tc = transaction_cost * position.signum() as f64;
|
||||
cash += position as f64 * final_price * (1.0 - tc);
|
||||
position = 0;
|
||||
let _ = cash + position as f64 * final_price * (1.0 - tc);
|
||||
// position closed
|
||||
}
|
||||
|
||||
// Calculate metrics
|
||||
@@ -262,7 +262,7 @@ pub fn backtest_mean_reversion(
|
||||
|
||||
// Calculate rolling mean and std
|
||||
let window = 20;
|
||||
let mut positions = vec![0i32; spread.len()];
|
||||
let _positions = vec![0i32; spread.len()];
|
||||
let mut signals = Vec::new();
|
||||
|
||||
for i in window..spread.len() {
|
||||
|
||||
@@ -682,7 +682,6 @@ impl<S: StateTransitionModel, O: ObservationModel> UnscentedKalmanFilter<S, O> {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use approx::assert_abs_diff_eq;
|
||||
|
||||
#[test]
|
||||
fn test_linear_kalman_filter() {
|
||||
|
||||
@@ -3,8 +3,6 @@
|
||||
//!
|
||||
//! Estimate parameters of OU process: dX_t = κ(θ - X_t)dt + σdW_t
|
||||
|
||||
use ndarray::Array1;
|
||||
use statrs::distribution::{Normal, ContinuousCDF};
|
||||
use crate::optimal_control::{OptimalControlError, Result};
|
||||
|
||||
/// OU process parameters
|
||||
@@ -119,7 +117,7 @@ pub fn estimate_ou_params_mle(spread: &[f64], dt: f64) -> Result<OUParams> {
|
||||
let tol = 1e-6;
|
||||
|
||||
for _iter in 0..max_iter {
|
||||
let mut log_likelihood = 0.0;
|
||||
let mut _log_likelihood = 0.0;
|
||||
let mut d_kappa = 0.0;
|
||||
let mut d_theta = 0.0;
|
||||
let mut d_sigma = 0.0;
|
||||
@@ -143,7 +141,7 @@ pub fn estimate_ou_params_mle(spread: &[f64], dt: f64) -> Result<OUParams> {
|
||||
let z = (x_next - mu_t) / std_t;
|
||||
|
||||
// Log-likelihood contribution
|
||||
log_likelihood -= 0.5 * z.powi(2) + std_t.ln();
|
||||
_log_likelihood -= 0.5 * z.powi(2) + std_t.ln();
|
||||
|
||||
// Gradients (simplified)
|
||||
d_kappa += z * (x_t - theta) * dt * exp_neg_kappa_dt / std_t;
|
||||
|
||||
@@ -5,8 +5,7 @@
|
||||
|
||||
use super::kernels::ExcitationKernel;
|
||||
use rand::prelude::*;
|
||||
use rand_distr::{Exp, Uniform};
|
||||
use std::collections::VecDeque;
|
||||
use rand_distr::Exp;
|
||||
|
||||
/// Configuration for a Hawkes process
|
||||
#[derive(Clone, Debug)]
|
||||
|
||||
@@ -102,6 +102,7 @@ pub struct PowerLawKernel {
|
||||
/// Scaling constant K₀ > 0
|
||||
pub k_0: f64,
|
||||
/// Normalization factor to achieve unit L¹ norm
|
||||
#[allow(dead_code)]
|
||||
norm_factor: f64,
|
||||
}
|
||||
|
||||
@@ -175,6 +176,7 @@ impl ExcitationKernel for PowerLawKernel {
|
||||
/// This satisfies the complete monotonicity requirement for the scaling limit
|
||||
/// theorems. φ(t) = K₀ * t^{-α₀} * E_{1-α₀}(-λ * t^{1-α₀})
|
||||
/// where E is the Mittag-Leffler function.
|
||||
#[allow(dead_code)]
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct CompletelyMonotoneKernel {
|
||||
pub alpha_0: f64,
|
||||
@@ -183,6 +185,7 @@ pub struct CompletelyMonotoneKernel {
|
||||
}
|
||||
|
||||
impl CompletelyMonotoneKernel {
|
||||
#[allow(dead_code)]
|
||||
pub fn new(alpha_0: f64, k_0: f64, lambda: f64) -> Self {
|
||||
assert!(alpha_0 > 0.0 && alpha_0 < 1.0);
|
||||
assert!(k_0 > 0.0);
|
||||
@@ -236,6 +239,7 @@ impl ExcitationKernel for CompletelyMonotoneKernel {
|
||||
}
|
||||
|
||||
/// Gamma function approximation (Lanczos approximation)
|
||||
#[allow(dead_code)]
|
||||
fn gamma_fn(z: f64) -> f64 {
|
||||
// Use Lanczos approximation for Γ(z)
|
||||
if z < 0.5 {
|
||||
@@ -291,7 +295,7 @@ mod tests {
|
||||
// Check power-law decay
|
||||
let v1 = kernel.evaluate(1.0);
|
||||
let v10 = kernel.evaluate(10.0);
|
||||
let v100 = kernel.evaluate(100.0);
|
||||
let _v100 = kernel.evaluate(100.0);
|
||||
|
||||
// φ(t) ~ t^{-1-α₀}, so φ(10)/φ(1) ≈ 10^{-1-α₀}
|
||||
let expected_ratio = 10.0_f64.powf(-1.375);
|
||||
|
||||
@@ -149,6 +149,7 @@ pub fn f_alpha_lambda(alpha_0: f64, lambda_0: f64, x: f64) -> f64 {
|
||||
/// Integral of f_{α₀,λ₀} from 0 to t
|
||||
///
|
||||
/// ∫₀ᵗ f_{α₀,λ₀}(s) ds = t^{α₀} * E_{α₀,α₀+1}(-λ₀ * t^{α₀})
|
||||
#[allow(dead_code)]
|
||||
pub fn f_alpha_lambda_integral(alpha_0: f64, lambda_0: f64, t: f64) -> f64 {
|
||||
if t <= 0.0 {
|
||||
return 0.0;
|
||||
@@ -161,6 +162,7 @@ pub fn f_alpha_lambda_integral(alpha_0: f64, lambda_0: f64, t: f64) -> f64 {
|
||||
}
|
||||
|
||||
/// Gamma function using Lanczos approximation
|
||||
#[allow(dead_code)]
|
||||
pub fn gamma(z: f64) -> f64 {
|
||||
if z < 0.5 {
|
||||
// Reflection formula: Γ(z) * Γ(1-z) = π / sin(πz)
|
||||
@@ -191,12 +193,14 @@ pub fn gamma(z: f64) -> f64 {
|
||||
}
|
||||
|
||||
/// Log-gamma function for numerical stability
|
||||
#[allow(dead_code)]
|
||||
pub fn lgamma(z: f64) -> f64 {
|
||||
gamma(z).abs().ln()
|
||||
}
|
||||
|
||||
/// Incomplete gamma function γ(s, x) = ∫₀ˣ t^{s-1} e^{-t} dt
|
||||
/// Used for various probability computations
|
||||
#[allow(dead_code)]
|
||||
pub fn incomplete_gamma_lower(s: f64, x: f64) -> f64 {
|
||||
if x < 0.0 || s <= 0.0 {
|
||||
return 0.0;
|
||||
@@ -224,6 +228,7 @@ pub fn incomplete_gamma_lower(s: f64, x: f64) -> f64 {
|
||||
}
|
||||
|
||||
/// Upper incomplete gamma Γ(s, x) = ∫ₓ^∞ t^{s-1} e^{-t} dt
|
||||
#[allow(dead_code)]
|
||||
pub fn incomplete_gamma_upper(s: f64, x: f64) -> f64 {
|
||||
if x < 0.0 {
|
||||
return gamma(s);
|
||||
|
||||
@@ -14,7 +14,6 @@
|
||||
|
||||
use rand::prelude::*;
|
||||
use rand_distr::Normal;
|
||||
use std::f64::consts::PI;
|
||||
|
||||
/// Fractional Brownian Motion with Hurst parameter H
|
||||
#[derive(Clone, Debug)]
|
||||
|
||||
Reference in New Issue
Block a user