pub struct CorrelationBreakdownDetector { /* private fields */ }Expand description
Tracks pairwise rolling correlations across N assets and detects rapid decorrelation, which is a hallmark of systemic crisis events.
The detector maintains a sliding window of cross-asset return pairs.
When the fraction of pairs with |r| < threshold exceeds
crisis_pair_fraction, a crisis signal is raised.
§Example
use fin_primitives::regime::CorrelationBreakdownDetector;
let mut detector = CorrelationBreakdownDetector::new(20, 0.3, 0.6).unwrap();
// Feed returns for two assets over time
for i in 0..25 {
let r_a = if i % 2 == 0 { 0.01 } else { -0.01 };
let r_b = if i % 3 == 0 { 0.01 } else { -0.01 }; // decorrelated
detector.update(0, r_a);
detector.update(1, r_b);
if detector.is_crisis() {
println!("Crisis at bar {i}");
}
}Implementations§
Source§impl CorrelationBreakdownDetector
impl CorrelationBreakdownDetector
Sourcepub fn new(
window: usize,
threshold: f64,
crisis_fraction: f64,
) -> Result<Self, FinError>
pub fn new( window: usize, threshold: f64, crisis_fraction: f64, ) -> Result<Self, FinError>
Constructs a new detector.
window: rolling window length for correlation estimation.threshold: Pearson |r| below which a pair is considered decorrelated.crisis_fraction: fraction of pairs that must be decorrelated to signal crisis.
§Errors
Returns FinError::InvalidInput on invalid parameters.
Sourcepub fn update(&mut self, asset_idx: usize, log_return: f64)
pub fn update(&mut self, asset_idx: usize, log_return: f64)
Registers a new return observation for asset asset_idx.
Assets are identified by a zero-based index. The detector auto-expands its internal storage as new asset indices are encountered.
Trait Implementations§
Source§impl Clone for CorrelationBreakdownDetector
impl Clone for CorrelationBreakdownDetector
Auto Trait Implementations§
impl Freeze for CorrelationBreakdownDetector
impl RefUnwindSafe for CorrelationBreakdownDetector
impl Send for CorrelationBreakdownDetector
impl Sync for CorrelationBreakdownDetector
impl Unpin for CorrelationBreakdownDetector
impl UnsafeUnpin for CorrelationBreakdownDetector
impl UnwindSafe for CorrelationBreakdownDetector
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more