Wave 64-65 cleanup: Proto regeneration and build system updates from Tonic 0.12→0.14 upgrade Files updated: - Cargo.lock: Dependency resolution for Tonic 0.14.2 - All build.rs: Updated for tonic-prost-build - Proto files: Regenerated with tonic-prost 0.14 - Examples/tests: Updated for new gRPC API 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
232 lines
8.1 KiB
Plaintext
232 lines
8.1 KiB
Plaintext
//! Asset Classification System Demo
|
||
//!
|
||
//! This example demonstrates the comprehensive asset classification system
|
||
//! including pattern-based matching, trading parameters, and volatility profiling.
|
||
|
||
#![allow(clippy::default_numeric_fallback)]
|
||
#![allow(clippy::arithmetic_side_effects)]
|
||
#![allow(clippy::as_conversions)]
|
||
#![allow(unused_crate_dependencies)]
|
||
|
||
use chrono::Utc;
|
||
use config::{
|
||
create_default_configurations, AssetClass, AssetClassificationManager, AssetConfig,
|
||
ConfigManager, EquitySector, ExecutionConfig, GeographicRegion, JumpRiskProfile, MarketCapTier,
|
||
OrderType, PositionLimits, RiskThresholds, ServiceConfig, SettlementConfig, TimeInForce,
|
||
TradingParameters, VolatilityProfile,
|
||
};
|
||
use rust_decimal::Decimal;
|
||
use std::str::FromStr;
|
||
use uuid::Uuid;
|
||
|
||
#[tokio::main]
|
||
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||
println!("🎯 Foxhunt Asset Classification System Demo");
|
||
println!("==========================================");
|
||
|
||
// Initialize asset classification manager
|
||
let mut manager = AssetClassificationManager::new();
|
||
|
||
// Load default configurations
|
||
let configs = create_default_configurations();
|
||
println!("✅ Loading {} default asset configurations", configs.len());
|
||
manager.load_configurations(configs).await?;
|
||
|
||
// Demo 1: Symbol Classification
|
||
println!("\n📊 Demo 1: Symbol Classification");
|
||
println!("---------------------------------");
|
||
|
||
let test_symbols = vec![
|
||
"AAPL",
|
||
"MSFT",
|
||
"BTCUSD",
|
||
"ETHUSD",
|
||
"EURUSD",
|
||
"GBPJPY",
|
||
"UNKNOWN_SYMBOL",
|
||
"TESLA",
|
||
"GOOGL",
|
||
];
|
||
|
||
for symbol in test_symbols {
|
||
let asset_class = manager.classify_symbol(symbol);
|
||
println!("Symbol: {:8} -> {:?}", symbol, asset_class);
|
||
}
|
||
|
||
// Demo 2: Trading Parameters
|
||
println!("\n⚙️ Demo 2: Trading Parameters");
|
||
println!("------------------------------");
|
||
|
||
if let Some(params) = manager.get_trading_parameters("AAPL") {
|
||
println!("AAPL Trading Parameters:");
|
||
println!(
|
||
" Max Position Fraction: {:.2}%",
|
||
params.position_limits.max_position_fraction * 100.0
|
||
);
|
||
println!(" Max Leverage: {}x", params.position_limits.max_leverage);
|
||
println!(
|
||
" Daily Loss Limit: {:.2}%",
|
||
params.risk_thresholds.daily_loss_limit * 100.0
|
||
);
|
||
println!(
|
||
" Preferred Orders: {:?}",
|
||
params.execution_config.preferred_order_types
|
||
);
|
||
}
|
||
|
||
// Demo 3: Volatility Profiling
|
||
println!("\n📈 Demo 3: Volatility Profiling");
|
||
println!("-------------------------------");
|
||
|
||
let volatility_symbols = vec!["AAPL", "BTCUSD", "EURUSD"];
|
||
for symbol in volatility_symbols {
|
||
let daily_vol = manager.get_daily_volatility(symbol);
|
||
let annual_vol = daily_vol * 252.0_f64.sqrt();
|
||
println!("{}:", symbol);
|
||
println!(" Daily Volatility: {:.2}%", daily_vol * 100.0);
|
||
println!(" Annual Volatility: {:.2}%", annual_vol * 100.0);
|
||
|
||
if let Some(profile) = manager.get_volatility_profile(symbol) {
|
||
println!(
|
||
" Stress Multiplier: {}x",
|
||
profile.stress_volatility_multiplier
|
||
);
|
||
println!(
|
||
" Jump Probability: {:.2}%",
|
||
profile.jump_risk.jump_probability * 100.0
|
||
);
|
||
}
|
||
}
|
||
|
||
// Demo 4: Position Sizing
|
||
println!("\n💰 Demo 4: Position Size Recommendations");
|
||
println!("----------------------------------------");
|
||
|
||
let portfolio_nav = Decimal::from_str("1000000.00").unwrap(); // $1M portfolio
|
||
let position_symbols = vec!["AAPL", "BTCUSD", "EURUSD"];
|
||
|
||
for symbol in position_symbols {
|
||
if let Some(recommended_size) =
|
||
manager.get_position_size_recommendation(symbol, portfolio_nav)
|
||
{
|
||
let percentage = (recommended_size / portfolio_nav) * Decimal::from(100);
|
||
println!(
|
||
"{}: ${} ({:.1}% of portfolio)",
|
||
symbol, recommended_size, percentage
|
||
);
|
||
}
|
||
}
|
||
|
||
// Demo 5: Custom Asset Configuration
|
||
println!("\n🔧 Demo 5: Custom Asset Configuration");
|
||
println!("------------------------------------");
|
||
|
||
let custom_config = create_custom_equity_config();
|
||
println!("Created custom configuration for: {}", custom_config.name);
|
||
println!("Pattern: {}", custom_config.symbol_pattern);
|
||
println!("Asset Class: {:?}", custom_config.asset_class);
|
||
|
||
// Demo 6: ConfigManager Integration
|
||
println!("\n🏗️ Demo 6: ConfigManager Integration");
|
||
println!("------------------------------------");
|
||
|
||
let service_config = ServiceConfig {
|
||
name: "trading_service".to_string(),
|
||
environment: "development".to_string(),
|
||
version: "1.0.0".to_string(),
|
||
settings: serde_json::json!({"debug": true}),
|
||
};
|
||
|
||
let config_manager = ConfigManager::new(service_config);
|
||
|
||
// Note: ConfigManager methods would need to be implemented to use asset classification
|
||
// For now, use the manager directly
|
||
let asset_class = manager.classify_symbol("AAPL");
|
||
let daily_vol = manager.get_daily_volatility("AAPL");
|
||
|
||
println!("ConfigManager Results:");
|
||
println!(" AAPL Asset Class: {:?}", asset_class);
|
||
println!(" AAPL Daily Volatility: {:.2}%", daily_vol * 100.0);
|
||
|
||
// Demo 7: Trading Hours and Market Status
|
||
println!("\n🕒 Demo 7: Trading Hours and Market Status");
|
||
println!("-----------------------------------------");
|
||
|
||
let now = Utc::now();
|
||
let trading_symbols = vec!["AAPL", "BTCUSD", "EURUSD"];
|
||
|
||
for symbol in trading_symbols {
|
||
let is_active = manager.is_trading_active(symbol, now);
|
||
println!(
|
||
"{}: Trading {}",
|
||
symbol,
|
||
if is_active { "ACTIVE" } else { "INACTIVE" }
|
||
);
|
||
}
|
||
|
||
println!("\n✨ Demo completed successfully!");
|
||
Ok(())
|
||
}
|
||
|
||
/// Creates a custom asset configuration for demonstration
|
||
fn create_custom_equity_config() -> AssetConfig {
|
||
let now = Utc::now();
|
||
|
||
AssetConfig {
|
||
id: Uuid::new_v4(),
|
||
name: "Mid-Cap Technology Stocks".to_string(),
|
||
symbol_pattern: "^(SHOP|SQ|ROKU|PINS|SNAP)$".to_string(),
|
||
compiled_pattern: None,
|
||
asset_class: AssetClass::Equity {
|
||
sector: EquitySector::Technology,
|
||
market_cap: MarketCapTier::MidCap,
|
||
region: GeographicRegion::NorthAmerica,
|
||
},
|
||
volatility_profile: VolatilityProfile {
|
||
base_annual_volatility: 0.40, // 40% annual volatility
|
||
stress_volatility_multiplier: 2.5,
|
||
intraday_pattern: vec![1.0; 24], // Flat pattern
|
||
volatility_persistence: 0.88,
|
||
jump_risk: JumpRiskProfile {
|
||
jump_probability: 0.03,
|
||
jump_magnitude: 0.08,
|
||
max_jump_size: 0.25,
|
||
},
|
||
},
|
||
trading_parameters: TradingParameters {
|
||
position_limits: PositionLimits {
|
||
max_position_fraction: 0.15, // 15% max position
|
||
max_leverage: 2.0,
|
||
concentration_limit: 0.25,
|
||
min_position_size: Decimal::from(500),
|
||
},
|
||
risk_thresholds: RiskThresholds {
|
||
var_limit: 0.06,
|
||
daily_loss_limit: 0.04,
|
||
stop_loss_threshold: 0.12,
|
||
volatility_circuit_breaker: 0.08,
|
||
max_drawdown_threshold: 0.18,
|
||
},
|
||
execution_config: ExecutionConfig {
|
||
preferred_order_types: vec![OrderType::Limit, OrderType::Market],
|
||
tick_size: Decimal::from_str("0.01").unwrap(),
|
||
min_order_size: Decimal::from(1),
|
||
max_order_size: Decimal::from(5000),
|
||
time_in_force_default: TimeInForce::Day,
|
||
slippage_tolerance: 0.002,
|
||
},
|
||
market_making: None,
|
||
},
|
||
priority: 85,
|
||
is_active: true,
|
||
created_at: now,
|
||
updated_at: now,
|
||
trading_hours: None, // Use default US equity hours
|
||
settlement_config: SettlementConfig {
|
||
settlement_days: 2,
|
||
settlement_currency: "USD".to_string(),
|
||
physical_settlement: false,
|
||
},
|
||
}
|
||
}
|