### Install Rust Development Tools Source: https://github.com/minikin/antifragile/blob/main/CONTRIBUTING.md Install necessary Rust components like rustfmt for code formatting and clippy for linting. These tools are essential for maintaining code quality. ```bash rustup component add rustfmt clippy ``` -------------------------------- ### Install Antifragile Dependency Source: https://github.com/minikin/antifragile/blob/main/README.md Add the library to your Cargo.toml file. ```toml [dependencies] antifragile = "0.0.1" ``` -------------------------------- ### Conventional Commit Examples Source: https://github.com/minikin/antifragile/blob/main/CONTRIBUTING.md Provides examples of commit messages following the conventional commits format. These illustrate how to structure messages for different types of changes. ```markdown feat(core): add new is_nullish method fix(serde): correct deserialization of absent fields docs(readme): update usage examples test(conversion): add tests for from_nullable ``` -------------------------------- ### Quick Start System Analysis Source: https://github.com/minikin/antifragile/blob/main/README.md Define a system by implementing the Antifragile trait and classify its response to stress. ```rust use antifragile::{Antifragile, Triad, TriadAnalysis}; // Define a system with convex response (benefits from volatility) struct ConvexSystem; impl Antifragile for ConvexSystem { type Stressor = f64; type Payoff = f64; fn payoff(&self, x: Self::Stressor) -> Self::Payoff { x * x // Quadratic: convex response } } let system = ConvexSystem; assert_eq!(system.classify(10.0, 1.0), Triad::Antifragile); ``` -------------------------------- ### Clone Repository and Navigate Source: https://github.com/minikin/antifragile/blob/main/CONTRIBUTING.md Clone the antifragile repository and navigate into the project directory. This is the first step for setting up the development environment. ```bash git clone https://github.com/minikin/antifragile.git cd antifragile ``` -------------------------------- ### Build and Open Documentation Source: https://github.com/minikin/antifragile/blob/main/CONTRIBUTING.md Generate project documentation and automatically open it in the default web browser. This command includes documentation for all features but excludes dependencies. ```bash cargo doc --all-features --no-deps --open ``` -------------------------------- ### Deploy services with Docker Compose Source: https://github.com/minikin/antifragile/blob/main/examples/adaptive-pricing-api/README.md Commands to initialize the environment and execute load tests. ```bash # Start services and run load test docker compose --profile loadtest up # Or start services only, then run load test separately docker compose up -d docker compose --profile loadtest up loadtest ``` -------------------------------- ### Enable Serde Support Source: https://github.com/minikin/antifragile/blob/main/README.md Include the serde feature flag for serialization support. ```toml [dependencies] antifragile = { version = "0.0.1", features = ["serde"] } ``` -------------------------------- ### Interact with the Adaptive Pricing API Source: https://github.com/minikin/antifragile/blob/main/examples/adaptive-pricing-api/README.md Endpoints for calculating prices and retrieving system metrics. ```bash curl -X POST http://localhost:3000/price \ -H "Content-Type: application/json" \ -d '{"product_id": "widget", "quantity": 10}' curl http://localhost:3000/antifragile/status curl http://localhost:3000/antifragile/curve ``` -------------------------------- ### Verified Wrapper Usage Source: https://context7.com/minikin/antifragile/llms.txt Demonstrates wrapping a system with its verified Triad classification, caching results, and checking classification persistence. Shows access to inner system via Deref and explicit methods, re-verification, and unwrapping. ```rust use antifragile::{Antifragile, Triad, TriadAnalysis, Verified}; struct ConvexSystem; impl Antifragile for ConvexSystem { type Stressor = f64; type Payoff = f64; fn payoff(&self, x: Self::Stressor) -> Self::Payoff { x * x } } // Create verified system with classification at operating point 10.0, delta 1.0 let mut verified = Verified::check(ConvexSystem, 10.0, 1.0); // Access cached classification (no recomputation) assert_eq!(verified.classification(), Triad::Antifragile); // Use predicate methods assert!(verified.is_antifragile()); assert!(!verified.is_fragile()); assert!(!verified.is_robust()); // Access inner system through Deref let payoff_at_5 = verified.payoff(5.0); // 25.0 assert!((payoff_at_5 - 25.0).abs() < f64::EPSILON); // Access inner system explicitly let inner: &ConvexSystem = verified.inner(); let _ = inner.payoff(3.0); // Check if classification holds at different point assert!(verified.still_holds(5.0, 1.0)); // Still antifragile at x=5 assert!(!verified.still_holds(10.0, 0.0)); // With delta=0, becomes Robust // Re-verify at a new operating point (updates stored classification) verified.re_verify(10.0, 0.0); assert_eq!(verified.classification(), Triad::Robust); // Unwrap to get inner system let system = verified.into_inner(); let _ = system.payoff(10.0); ``` -------------------------------- ### Antifragile Crate Feature Flags Source: https://context7.com/minikin/antifragile/llms.txt Illustrates how to configure the antifragile crate using Cargo.toml for different environments and features. Shows default std support, no_std environments, and enabling serde serialization. ```toml # Cargo.toml # Default: std enabled [dependencies] antifragile = "0.0.1" # For no_std environments (embedded, WASM, etc.) [dependencies] antifragile = { version = "0.0.1", default-features = false } # Enable serde serialization/deserialization [dependencies] antifragile = { version = "0.0.1", features = ["serde"] } # Both no_std and serde [dependencies] antifragile = { version = "0.0.1", default-features = false, features = ["serde"] } ``` -------------------------------- ### Format and Lint Code Source: https://github.com/minikin/antifragile/blob/main/CONTRIBUTING.md Apply code formatting using `rustfmt` and check for linting issues with `clippy`. These commands are part of the pre-commit checks to ensure code quality. ```bash cargo fmt --all ``` ```bash cargo clippy --all-targets --all-features -- -D warnings ``` -------------------------------- ### Configure no_std Environment Source: https://github.com/minikin/antifragile/blob/main/README.md Disable default features to use the library in no_std environments. ```toml [dependencies] antifragile = { version = "0.0.1", default-features = false } ``` -------------------------------- ### Check Code Formatting Source: https://github.com/minikin/antifragile/blob/main/CONTRIBUTING.md Verify that the code adheres to the project's formatting standards using `rustfmt`. This command checks formatting without modifying files. ```bash cargo fmt --all -- --check ``` -------------------------------- ### Create Git Tag for Release Source: https://github.com/minikin/antifragile/blob/main/CONTRIBUTING.md Create an annotated Git tag for a new release version. This is a crucial step in the release process, marking a specific point in the project's history. ```bash git tag -a v0.x.y -m "Release v0.x.y" ``` -------------------------------- ### Run All Tests Source: https://github.com/minikin/antifragile/blob/main/CONTRIBUTING.md Execute all tests within the project, including those that depend on feature flags. This command ensures the entire codebase is functioning as expected. ```bash cargo test --all-features ``` -------------------------------- ### Serde Serialization/Deserialization with Triad Source: https://context7.com/minikin/antifragile/llms.txt Shows how to serialize and deserialize the Triad enum to/from JSON when the 'serde' feature is enabled. Requires importing Triad and serde_json. ```rust // With serde feature enabled #[cfg(feature = "serde")] { use antifragile::Triad; use serde_json; let triad = Triad::Antifragile; // Serialize to JSON let json = serde_json::to_string(&triad).unwrap(); // "\"Antifragile\"" // Deserialize from JSON let parsed: Triad = serde_json::from_str(&json).unwrap(); assert_eq!(parsed, Triad::Antifragile); } ``` -------------------------------- ### Verify System Classification Source: https://github.com/minikin/antifragile/blob/main/README.md Use the Verified wrapper to store a system alongside its verified classification. ```rust use antifragile::{Antifragile, Verified, TriadAnalysis}; struct MySystem; impl Antifragile for MySystem { type Stressor = f64; type Payoff = f64; fn payoff(&self, x: Self::Stressor) -> Self::Payoff { x * x } } let verified = Verified::check(MySystem, 10.0, 1.0); println!("Classification: {}", verified.classification()); ``` -------------------------------- ### Antifragile Trait Implementation Source: https://context7.com/minikin/antifragile/llms.txt Demonstrates how to implement the `Antifragile` trait for different system types, such as a financial call option (convex payoff) and an insurance portfolio (concave payoff). ```APIDOC ## Antifragile Trait The core trait that all systems must implement to be analyzed for fragility. It defines the stressor type, payoff type, and the payoff function that maps stress levels to outcomes. ```rust use antifragile::Antifragile; // Define a financial call option with convex payoff struct CallOption { strike: f64, } impl Antifragile for CallOption { type Stressor = f64; // Underlying price type Payoff = f64; // Option value fn payoff(&self, price: f64) -> f64 { (price - self.strike).max(0.0) } } // Define an insurance portfolio with concave payoff struct InsurancePortfolio { premium_collected: f64, max_liability: f64, } impl Antifragile for InsurancePortfolio { type Stressor = f64; // Claim rate type Payoff = f64; // Profit fn payoff(&self, claim_rate: f64) -> f64 { self.premium_collected - (claim_rate * self.max_liability).min(self.max_liability) } } let option = CallOption { strike: 100.0 }; let portfolio = InsurancePortfolio { premium_collected: 1000.0, max_liability: 10000.0, }; // Access payoff at different stress levels println!("Option payoff at price 110: {}", option.payoff(110.0)); // 10.0 println!("Option payoff at price 90: {}", option.payoff(90.0)); // 0.0 println!("Portfolio profit at 5% claims: {}", portfolio.payoff(0.05)); // 500.0 ``` ``` -------------------------------- ### Run Linter Source: https://github.com/minikin/antifragile/blob/main/CONTRIBUTING.md Execute the `clippy` linter to identify potential code errors and style issues. Warnings are treated as errors, enforcing stricter code quality. ```bash cargo clippy --all-targets --all-features -- -D warnings ``` -------------------------------- ### Run Specific Test Suites Source: https://github.com/minikin/antifragile/blob/main/CONTRIBUTING.md Execute specific types of tests, such as integration tests or unit tests, or target a particular test file. This is useful for focused testing during development. ```bash # Run only integration tests ``` ```bash cargo test --tests --all-features ``` ```bash # Run only unit tests ``` ```bash cargo test --lib ``` ```bash # Run a specific test file ``` ```bash cargo test --test basic_tests ``` -------------------------------- ### Analyze Financial Options for Antifragility Source: https://context7.com/minikin/antifragile/llms.txt Implements the Antifragile trait for individual call options and portfolios to evaluate payoff behavior under price stressors. ```rust use antifragile::{Antifragile, Triad, TriadAnalysis, Verified}; /// A call option with strike price struct CallOption { strike: f64, } impl Antifragile for CallOption { type Stressor = f64; // Underlying asset price type Payoff = f64; // Option intrinsic value fn payoff(&self, price: f64) -> f64 { (price - self.strike).max(0.0) } } /// A portfolio of options struct OptionsPortfolio { options: Vec<(CallOption, i32)>, // (option, quantity: positive=long, negative=short) } impl Antifragile for OptionsPortfolio { type Stressor = f64; type Payoff = f64; fn payoff(&self, price: f64) -> f64 { self.options .iter() .map(|(opt, qty)| opt.payoff(price) * (*qty as f64)) .sum() } } fn main() { // Single call option analysis let option = CallOption { strike: 100.0 }; // At-the-money analysis (price = strike) let at = 100.0; let delta = 10.0; println!("Call Option (strike: $100)"); println!(" Payoff at ${}: ${:.2}", at - delta, option.payoff(at - delta)); println!(" Payoff at ${}: ${:.2}", at, option.payoff(at)); println!(" Payoff at ${}: ${:.2}", at + delta, option.payoff(at + delta)); println!(" Classification: {}", option.classify(at, delta)); // Output: Antifragile (benefits from volatility) // Verify the option is antifragile let verified = Verified::check(option, at, delta); assert!(verified.is_antifragile()); // Portfolio analysis: long call spread let portfolio = OptionsPortfolio { options: vec![ (CallOption { strike: 100.0 }, 1), // Long 1 call at 100 (CallOption { strike: 110.0 }, -1), // Short 1 call at 110 ], }; println!("\nCall Spread Portfolio"); println!(" Classification: {}", portfolio.classify(105.0, 5.0)); // Check if portfolio gains from stress if portfolio.gains_from_stress(100.0, 120.0) { println!(" Portfolio profits from price increase"); } } ``` -------------------------------- ### TriadAnalysis::classify Method Source: https://context7.com/minikin/antifragile/llms.txt Explains how to use the `classify` method from the `TriadAnalysis` trait to determine if a system is Antifragile, Fragile, or Robust based on its payoff function's convexity. ```APIDOC ## TriadAnalysis::classify Classifies a system on Taleb's Triad at a specific operating point using the convexity test. Returns `Triad::Antifragile` for convex payoffs, `Triad::Fragile` for concave payoffs, and `Triad::Robust` for linear payoffs. ```rust use antifragile::{Antifragile, Triad, TriadAnalysis}; struct ConvexSystem; // f(x) = x² - benefits from volatility impl Antifragile for ConvexSystem { type Stressor = f64; type Payoff = f64; fn payoff(&self, x: Self::Stressor) -> Self::Payoff { x * x } } struct ConcaveSystem; // f(x) = √x - harmed by volatility impl Antifragile for ConcaveSystem { type Stressor = f64; type Payoff = f64; fn payoff(&self, x: Self::Stressor) -> Self::Payoff { x.abs().sqrt() } } struct LinearSystem; // f(x) = 2x + 5 - unaffected by volatility impl Antifragile for LinearSystem { type Stressor = f64; type Payoff = f64; fn payoff(&self, x: Self::Stressor) -> Self::Payoff { 2.0 * x + 5.0 } } let convex = ConvexSystem; let concave = ConcaveSystem; let linear = LinearSystem; let at = 10.0; // Operating point let delta = 1.0; // Perturbation size // Classify each system assert_eq!(convex.classify(at, delta), Triad::Antifragile); // Convex -> Antifragile assert_eq!(concave.classify(at, delta), Triad::Fragile); // Concave -> Fragile assert_eq!(linear.classify(at, delta), Triad::Robust); // Linear -> Robust // Print classifications with full description println!("{}", convex.classify(at, delta)); // "Antifragile (benefits from volatility)" println!("{}", concave.classify(at, delta)); // "Fragile (harmed by volatility)" println!("{}", linear.classify(at, delta)); // "Robust (unaffected by volatility)" ``` ``` -------------------------------- ### Classify Systems using TriadAnalysis Source: https://context7.com/minikin/antifragile/llms.txt Use the classify method to determine if a system is Antifragile, Fragile, or Robust based on its response to perturbations at a specific operating point. ```rust use antifragile::{Antifragile, Triad, TriadAnalysis}; struct ConvexSystem; // f(x) = x² - benefits from volatility impl Antifragile for ConvexSystem { type Stressor = f64; type Payoff = f64; fn payoff(&self, x: Self::Stressor) -> Self::Payoff { x * x } } struct ConcaveSystem; // f(x) = √x - harmed by volatility impl Antifragile for ConcaveSystem { type Stressor = f64; type Payoff = f64; fn payoff(&self, x: Self::Stressor) -> Self::Payoff { x.abs().sqrt() } } struct LinearSystem; // f(x) = 2x + 5 - unaffected by volatility impl Antifragile for LinearSystem { type Stressor = f64; type Payoff = f64; fn payoff(&self, x: Self::Stressor) -> Self::Payoff { 2.0 * x + 5.0 } } let convex = ConvexSystem; let concave = ConcaveSystem; let linear = LinearSystem; let at = 10.0; // Operating point let delta = 1.0; // Perturbation size // Classify each system assert_eq!(convex.classify(at, delta), Triad::Antifragile); // Convex -> Antifragile assert_eq!(concave.classify(at, delta), Triad::Fragile); // Concave -> Fragile assert_eq!(linear.classify(at, delta), Triad::Robust); // Linear -> Robust // Print classifications with full description println!("{}", convex.classify(at, delta)); // "Antifragile (benefits from volatility)" println!("{}", concave.classify(at, delta)); // "Fragile (harmed by volatility)" println!("{}", linear.classify(at, delta)); // "Robust (unaffected by volatility)" ``` -------------------------------- ### Check for antifragility at an operating point Source: https://context7.com/minikin/antifragile/llms.txt Determines if a system exhibits a convex response to stress at a specific point. ```rust use antifragile::{Antifragile, TriadAnalysis}; struct OptionsPortfolio { vega_exposure: f64, // Long volatility position } impl Antifragile for OptionsPortfolio { type Stressor = f64; // Market volatility type Payoff = f64; // Portfolio P&L fn payoff(&self, volatility: f64) -> f64 { self.vega_exposure * volatility * volatility } } let portfolio = OptionsPortfolio { vega_exposure: 1.0 }; // Quick check if portfolio benefits from volatility if portfolio.is_antifragile(0.2, 0.05) { println!("Portfolio is antifragile - it benefits from market volatility!"); } else { println!("Portfolio does not benefit from volatility"); } assert!(portfolio.is_antifragile(0.2, 0.05)); // true ``` -------------------------------- ### Tear down the environment Source: https://github.com/minikin/antifragile/blob/main/examples/adaptive-pricing-api/README.md Removes containers and volumes associated with the project. ```bash docker compose down -v ``` -------------------------------- ### Triad Enum Usage Source: https://context7.com/minikin/antifragile/llms.txt Demonstrates creating, comparing, sorting, and converting Triad enum variants. Includes usage of classification predicates, rank, opposite, iteration, string parsing, and conversion to/from u8. Defaults to Robust. ```rust use antifragile::Triad; // Create and compare classifications let classification = Triad::Antifragile; // Check classification type assert!(classification.is_antifragile()); assert!(!classification.is_fragile()); assert!(!classification.is_robust()); // Ordering by desirability assert!(Triad::Fragile < Triad::Robust); assert!(Triad::Robust < Triad::Antifragile); // Sort systems by desirability let mut triads = vec![Triad::Antifragile, Triad::Fragile, Triad::Robust]; triads.sort(); assert_eq!(triads, vec![Triad::Fragile, Triad::Robust, Triad::Antifragile]); // Get desirability rank (Fragile=0, Robust=1, Antifragile=2) assert_eq!(Triad::Fragile.rank(), 0); assert_eq!(Triad::Robust.rank(), 1); assert_eq!(Triad::Antifragile.rank(), 2); // Get opposite classification assert_eq!(Triad::Antifragile.opposite(), Triad::Fragile); assert_eq!(Triad::Fragile.opposite(), Triad::Antifragile); assert_eq!(Triad::Robust.opposite(), Triad::Robust); // Robust is self-opposite // Iterate over all variants for triad in Triad::iter() { println!("{}: rank {}", triad, triad.rank()); } // Convert to/from strings (case insensitive parsing) let s: &str = Triad::Antifragile.into(); // "antifragile" let parsed: Triad = "robust".parse().unwrap(); let upper: Triad = "FRAGILE".parse().unwrap(); // Convert to/from u8 let n: u8 = Triad::Antifragile.into(); // 2 let from_n = Triad::try_from(1u8).unwrap(); // Triad::Robust // Default is Robust (neutral) assert_eq!(Triad::default(), Triad::Robust); ``` -------------------------------- ### Classify systems with numerical tolerance Source: https://context7.com/minikin/antifragile/llms.txt Uses epsilon-based comparison to classify systems where floating-point precision might otherwise cause false results. ```rust use antifragile::{Antifragile, Triad, TriadAnalysis}; struct NearlyLinear; impl Antifragile for NearlyLinear { type Stressor = f64; type Payoff = f64; fn payoff(&self, x: Self::Stressor) -> Self::Payoff { 2.0 * x + 1e-10 * x * x // Almost linear with tiny convexity } } let system = NearlyLinear; // Exact classification detects the tiny convexity assert_eq!(system.classify(10.0, 1.0), Triad::Antifragile); // With tolerance, it's effectively Robust assert_eq!(system.classify_with_tolerance(10.0, 1.0, 1e-6), Triad::Robust); // Different tolerance levels for different precision needs let tight = system.classify_with_tolerance(10.0, 1.0, 1e-15); // Antifragile let loose = system.classify_with_tolerance(10.0, 1.0, 1.0); // Robust println!("Tight tolerance: {:?}, Loose tolerance: {:?}", tight, loose); ``` -------------------------------- ### Push Git Tag Source: https://github.com/minikin/antifragile/blob/main/CONTRIBUTING.md Push the newly created Git tag to the remote repository. This makes the release tag visible to others and is part of the automated release process. ```bash git push origin v0.x.y ``` -------------------------------- ### Conventional Commit Types Source: https://github.com/minikin/antifragile/blob/main/CONTRIBUTING.md Lists the standard types used in conventional commits, such as 'feat' for new features, 'fix' for bug fixes, and 'docs' for documentation changes. ```markdown - feat: New feature - fix: Bug fix - docs: Documentation changes - test: Adding or updating tests - refactor: Code refactoring - perf: Performance improvements - chore: Maintenance tasks ``` -------------------------------- ### Implement the Antifragile Trait Source: https://context7.com/minikin/antifragile/llms.txt Define custom systems by implementing the Antifragile trait, specifying stressor and payoff types along with the payoff function. ```rust use antifragile::Antifragile; // Define a financial call option with convex payoff struct CallOption { strike: f64, } impl Antifragile for CallOption { type Stressor = f64; // Underlying price type Payoff = f64; // Option value fn payoff(&self, price: f64) -> f64 { (price - self.strike).max(0.0) } } // Define an insurance portfolio with concave payoff struct InsurancePortfolio { premium_collected: f64, max_liability: f64, } impl Antifragile for InsurancePortfolio { type Stressor = f64; // Claim rate type Payoff = f64; // Profit fn payoff(&self, claim_rate: f64) -> f64 { self.premium_collected - (claim_rate * self.max_liability).min(self.max_liability) } } let option = CallOption { strike: 100.0 }; let portfolio = InsurancePortfolio { premium_collected: 1000.0, max_liability: 10000.0, }; // Access payoff at different stress levels println!("Option payoff at price 110: {}", option.payoff(110.0)); // 10.0 println!("Option payoff at price 90: {}", option.payoff(90.0)); // 0.0 println!("Portfolio profit at 5% claims: {}", portfolio.payoff(0.05)); // 500.0 ``` -------------------------------- ### Verify gains from increased stress Source: https://context7.com/minikin/antifragile/llms.txt Tests if a system's payoff improves when moving from a low stress level to a high stress level. ```rust use antifragile::{Antifragile, TriadAnalysis}; struct LearningSystem { learning_rate: f64, } impl Antifragile for LearningSystem { type Stressor = f64; // Training iterations type Payoff = f64; // Model accuracy fn payoff(&self, iterations: f64) -> f64 { // Accuracy improves with more training (logarithmic improvement) 1.0 - 1.0 / (1.0 + self.learning_rate * iterations) } } let model = LearningSystem { learning_rate: 0.1 }; // Does more training improve accuracy? assert!(model.gains_from_stress(100.0, 1000.0)); // true - more training helps // Check at different levels let low_stress = 10.0; let high_stress = 100.0; if model.gains_from_stress(low_stress, high_stress) { println!("Model improves with more training iterations"); } ``` -------------------------------- ### Implement Antifragile Trait Source: https://github.com/minikin/antifragile/blob/main/README.md Define the payoff function for a custom system to determine its response to stress. ```rust use antifragile::Antifragile; struct MySystem; impl Antifragile for MySystem { type Stressor = f64; // The type of stress applied type Payoff = f64; // The outcome produced fn payoff(&self, stressor: Self::Stressor) -> Self::Payoff { // Define your system's response to stress stressor * stressor } } ``` -------------------------------- ### Conventional Commits Format Source: https://github.com/minikin/antifragile/blob/main/CONTRIBUTING.md Specifies the conventional commits format for commit messages, including type, scope, subject, body, and footer. This standardizes commit history for better understanding and automation. ```markdown type(scope): subject body footer ``` -------------------------------- ### Assess system stability across stress levels Source: https://context7.com/minikin/antifragile/llms.txt Checks if the payoff variation between two stress levels remains within a specified threshold. ```rust use antifragile::{Antifragile, TriadAnalysis}; struct ConstantSystem; impl Antifragile for ConstantSystem { type Stressor = f64; type Payoff = f64; fn payoff(&self, _: Self::Stressor) -> Self::Payoff { 10.0 } } struct VolatileSystem; impl Antifragile for VolatileSystem { type Stressor = f64; type Payoff = f64; fn payoff(&self, x: Self::Stressor) -> Self::Payoff { x * x } } let constant = ConstantSystem; let volatile = VolatileSystem; // Constant system is perfectly stable assert!(constant.is_stable(1.0, 100.0, 0.001)); // Volatile system is not stable (payoff varies greatly) assert!(!volatile.is_stable(1.0, 10.0, 1.0)); // |1 - 100| = 99 > 1 // Use for risk assessment let threshold = 50.0; if volatile.is_stable(5.0, 10.0, threshold) { println!("Acceptable volatility range"); } else { println!("Warning: High volatility detected"); // This prints } ``` -------------------------------- ### TriadAnalysis::classify_with_tolerance Source: https://context7.com/minikin/antifragile/llms.txt Classifies a system by considering numerical tolerance for floating-point payoffs. Values within a specified epsilon are treated as equal, which is useful for systems with near-exact or imprecise payoffs. ```APIDOC ## TriadAnalysis::classify_with_tolerance ### Description Classifies a system with numerical tolerance for floating-point payoffs where exact equality is rare due to precision issues. Values within epsilon of each other are treated as equal. ### Method This is a method call on a type implementing the `Antifragile` trait. ### Endpoint N/A (Rust method call) ### Parameters - **`self`**: The system instance implementing `Antifragile`. - **`operating_point`** (f64) - The specific stress level at which to classify. - **`delta`** (f64) - The change in stress to observe the payoff difference. - **`epsilon`** (f64) - The tolerance for considering two floating-point values as equal. ### Request Example ```rust use antifragile::{Antifragile, Triad, TriadAnalysis}; struct NearlyLinear; impl Antifragile for NearlyLinear { type Stressor = f64; type Payoff = f64; fn payoff(&self, x: Self::Stressor) -> Self::Payoff { 2.0 * x + 1e-10 * x * x // Almost linear with tiny convexity } } let system = NearlyLinear; // Exact classification detects the tiny convexity assert_eq!(system.classify(10.0, 1.0), Triad::Antifragile); // With tolerance, it's effectively Robust assert_eq!(system.classify_with_tolerance(10.0, 1.0, 1e-6), Triad::Robust); // Different tolerance levels for different precision needs let tight = system.classify_with_tolerance(10.0, 1.0, 1e-15); // Antifragile let loose = system.classify_with_tolerance(10.0, 1.0, 1.0); // Robust println!("Tight tolerance: {:?}, Loose tolerance: {:?}", tight, loose); ``` ### Response #### Success Response (Triad) - **`Triad`** (enum) - The classification of the system (e.g., `Antifragile`, `Robust`, `Perverse`). #### Response Example ```rust // Example output from the code snippet: Tight tolerance: Antifragile, Loose tolerance: Robust ``` ``` -------------------------------- ### TriadAnalysis::is_stable Source: https://context7.com/minikin/antifragile/llms.txt Assesses the stability of a system's payoff across different stress levels by comparing payoff differences to a threshold. ```APIDOC ## TriadAnalysis::is_stable ### Description Checks if the payoff is stable across stress levels by comparing the absolute difference to a threshold. Returns true if the system's output doesn't vary significantly with stress changes. ### Method This is a method call on a type implementing the `Antifragile` trait. ### Endpoint N/A (Rust method call) ### Parameters - **`self`**: The system instance implementing `Antifragile`. - **`low_stress`** (f64) - The lower level of stress. - **`high_stress`** (f64) - The higher level of stress. - **`threshold`** (f64) - The maximum acceptable absolute difference in payoff between `low_stress` and `high_stress`. ### Request Example ```rust use antifragile::{Antifragile, TriadAnalysis}; struct ConstantSystem; impl Antifragile for ConstantSystem { type Stressor = f64; type Payoff = f64; fn payoff(&self, _: Self::Stressor) -> Self::Payoff { 10.0 } } struct VolatileSystem; impl Antifragile for VolatileSystem { type Stressor = f64; type Payoff = f64; fn payoff(&self, x: Self::Stressor) -> Self::Payoff { x * x } } let constant = ConstantSystem; let volatile = VolatileSystem; // Constant system is perfectly stable assert!(constant.is_stable(1.0, 100.0, 0.001)); // Volatile system is not stable (payoff varies greatly) assert!(!volatile.is_stable(1.0, 10.0, 1.0)); // |1 - 100| = 99 > 1 // Use for risk assessment let threshold = 50.0; if volatile.is_stable(5.0, 10.0, threshold) { println!("Acceptable volatility range"); } else { println!("Warning: High volatility detected"); // This prints } ``` ### Response #### Success Response (Boolean) - **`true`** (bool) - If the absolute difference between payoffs at `low_stress` and `high_stress` is less than or equal to the `threshold`. - **`false`** (bool) - Otherwise. #### Response Example ```rust // Example output from the code snippet: // Warning: High volatility detected ``` ``` -------------------------------- ### Classify with Triad Enum Source: https://github.com/minikin/antifragile/blob/main/README.md Use the Triad enum to represent and manipulate system classifications. ```rust use antifragile::Triad; let classification = Triad::Antifragile; // Check classification assert!(classification.is_antifragile()); // Ordering: Fragile < Robust < Antifragile assert!(Triad::Fragile < Triad::Robust); assert!(Triad::Robust < Triad::Antifragile); // Convert to/from strings let s: &str = classification.into(); // "antifragile" let parsed: Triad = "robust".parse().unwrap(); // Convert to/from u8 (Fragile=0, Robust=1, Antifragile=2) let n: u8 = classification.into(); // 2 let from_n = Triad::try_from(1u8).unwrap(); // Triad::Robust ``` -------------------------------- ### TriadAnalysis::is_antifragile Source: https://context7.com/minikin/antifragile/llms.txt A convenience method to determine if a system exhibits antifragile behavior, meaning its payoff increases with stress (convex response). ```APIDOC ## TriadAnalysis::is_antifragile ### Description Convenience method to check if a system is antifragile at a given operating point. Returns true only if the system has a convex response to stress. ### Method This is a method call on a type implementing the `Antifragile` trait. ### Endpoint N/A (Rust method call) ### Parameters - **`self`**: The system instance implementing `Antifragile`. - **`operating_point`** (f64) - The specific stress level at which to evaluate the payoff. - **`delta`** (f64) - The change in stress to observe the payoff difference. ### Request Example ```rust use antifragile::{Antifragile, TriadAnalysis}; struct OptionsPortfolio { vega_exposure: f64 } impl Antifragile for OptionsPortfolio { type Stressor = f64; type Payoff = f64; fn payoff(&self, volatility: f64) -> f64 { self.vega_exposure * volatility * volatility } } let portfolio = OptionsPortfolio { vega_exposure: 1.0 }; // Quick check if portfolio benefits from volatility if portfolio.is_antifragile(0.2, 0.05) { println!("Portfolio is antifragile - it benefits from market volatility!"); } else { println!("Portfolio does not benefit from volatility"); } assert!(portfolio.is_antifragile(0.2, 0.05)); // true ``` ### Response #### Success Response (Boolean) - **`true`** (bool) - If the system's payoff increases with a small increase in stress (convex response). - **`false`** (bool) - Otherwise. #### Response Example ```rust // Example output from the code snippet: // Portfolio is antifragile - it benefits from market volatility! ``` ``` -------------------------------- ### TriadAnalysis::gains_from_stress Source: https://context7.com/minikin/antifragile/llms.txt Determines if a system's payoff improves with increased stress, useful for systems that learn or improve with exposure. ```APIDOC ## TriadAnalysis::gains_from_stress ### Description Practical test to determine if higher stress leads to better payoff. Returns true if payoff(high_stress) > payoff(low_stress). Useful for learning systems where payoff improves with exposure. ### Method This is a method call on a type implementing the `Antifragile` trait. ### Endpoint N/A (Rust method call) ### Parameters - **`self`**: The system instance implementing `Antifragile`. - **`low_stress`** (f64) - The lower level of stress. - **`high_stress`** (f64) - The higher level of stress. ### Request Example ```rust use antifragile::{Antifragile, TriadAnalysis}; struct LearningSystem { learning_rate: f64 } impl Antifragile for LearningSystem { type Stressor = f64; type Payoff = f64; fn payoff(&self, iterations: f64) -> f64 { // Accuracy improves with more training (logarithmic improvement) 1.0 - 1.0 / (1.0 + self.learning_rate * iterations) } } let model = LearningSystem { learning_rate: 0.1 }; // Does more training improve accuracy? assert!(model.gains_from_stress(100.0, 1000.0)); // true - more training helps // Check at different levels let low_stress = 10.0; let high_stress = 100.0; if model.gains_from_stress(low_stress, high_stress) { println!("Model improves with more training iterations"); } ``` ### Response #### Success Response (Boolean) - **`true`** (bool) - If the payoff at `high_stress` is greater than the payoff at `low_stress`. - **`false`** (bool) - Otherwise. #### Response Example ```rust // Example output from the code snippet: // Model improves with more training iterations ``` ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.