RiskManager

Trait RiskManager 

Source
pub trait RiskManager: Send + Sync {
    // Required methods
    fn validate_signal<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        signal: &'life1 Signal,
        portfolio_value: Decimal,
        positions: &'life2 [Position],
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait;
    fn calculate_position_size<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        signal: &'life1 Signal,
        portfolio_value: Decimal,
        risk_params: &'life2 StrategyRiskParameters,
    ) -> Pin<Box<dyn Future<Output = Result<Decimal>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait;
    fn check_daily_loss_limit<'life0, 'async_trait>(
        &'life0 self,
        current_pnl: Decimal,
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn check_max_drawdown<'life0, 'async_trait>(
        &'life0 self,
        peak_equity: Decimal,
        current_equity: Decimal,
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn calculate_risk_metrics<'life0, 'life1, 'async_trait>(
        &'life0 self,
        positions: &'life1 [Position],
    ) -> Pin<Box<dyn Future<Output = Result<RiskMetrics>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
}
Expand description

Trait for risk management systems

Validates signals and orders before execution to ensure risk limits are met.

Required Methods§

Source

fn validate_signal<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, signal: &'life1 Signal, portfolio_value: Decimal, positions: &'life2 [Position], ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Validate a trading signal before execution

§Arguments
  • signal - Signal to validate
  • portfolio_value - Current portfolio value
  • positions - Current positions
§Returns

Ok(()) if signal passes risk checks, Err otherwise

Source

fn calculate_position_size<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, signal: &'life1 Signal, portfolio_value: Decimal, risk_params: &'life2 StrategyRiskParameters, ) -> Pin<Box<dyn Future<Output = Result<Decimal>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Calculate position size for a signal

Uses strategy risk parameters and portfolio constraints to determine appropriate position size.

§Arguments
  • signal - Trading signal
  • portfolio_value - Current portfolio value
  • risk_params - Strategy risk parameters
§Returns

Recommended position size (in shares)

Source

fn check_daily_loss_limit<'life0, 'async_trait>( &'life0 self, current_pnl: Decimal, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Check if daily loss limit has been exceeded

Source

fn check_max_drawdown<'life0, 'async_trait>( &'life0 self, peak_equity: Decimal, current_equity: Decimal, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Check if maximum drawdown has been exceeded

Source

fn calculate_risk_metrics<'life0, 'life1, 'async_trait>( &'life0 self, positions: &'life1 [Position], ) -> Pin<Box<dyn Future<Output = Result<RiskMetrics>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Calculate portfolio risk metrics

Implementors§