swift_mt_message/fields/
field37.rs

1use serde::{Deserialize, Serialize};
2use swift_mt_message_macros::SwiftField;
3
4///   **Field 37H: Interest Rate**
5///
6/// ## Purpose
7/// Specifies interest rates for financial instruments, derivatives, and investment products.
8/// This field family provides precise rate specifications required for interest calculations,
9/// derivative pricing, option valuations, and various financial product definitions.
10/// Interest rates are fundamental to financial market operations and risk management.
11///
12/// ## Format
13/// - **Swift Format**: `1!a[N]12d` (Field 37H), `[N]12d` (Field 37R), `12d` (Field 37L)
14/// - **Rate Indicator**: `1!a` - C (Credit) or D (Debit) for directional rates
15/// - **Negative Sign**: `[N]` - Optional 'N' for negative rates
16/// - **Rate Value**: `12d` - Decimal rate with comma separator
17///
18/// ## Presence
19/// - **Status**: Conditional/Mandatory depending on instrument type and market requirements
20/// - **Swift Error Codes**: T40 (invalid rate), T51 (format violation), T50 (invalid indicator)
21/// - **Usage Context**: Interest rate specifications and derivative pricing
22///
23/// ## Usage Rules
24/// - **Rate Expression**: Typically expressed as percentage (e.g., 2.5000 = 2.5%)
25/// - **Sign Logic**: Negative rates supported in low interest rate environments
26/// - **Precision**: Adequate precision for accurate interest calculations
27/// - **Market Standards**: Compliance with market rate quotation conventions
28///
29/// ## Network Validation Rules
30/// - **Format Validation**: Must follow exact rate format specifications
31/// - **Rate Range**: Must be within reasonable market rate ranges
32/// - **Precision Rules**: Integer part must contain at least one digit
33/// - **Decimal Requirement**: Decimal comma mandatory for proper formatting
34/// - **Negative Validation**: If rate is zero, negative sign must not be present
35///
36/// ## Field Variants and Applications
37///
38/// ### Field 37H - Interest Rate with Indicator
39/// - **Format**: `1!a[N]12d`
40/// - **Usage**: Directional interest rates with credit/debit specification
41/// - **Indicator Logic**: C (Credit rate), D (Debit rate)
42/// - **Applications**: Account interest, loan rates, deposit rates
43///
44/// ### Field 37R - Settlement Rate
45/// - **Format**: `[N]12d`
46/// - **Usage**: Settlement rates for derivatives and financial instruments
47/// - **Applications**: Forward rate agreements, interest rate swaps
48/// - **Context**: Final settlement rate determination
49///
50/// ### Field 37L - Lower Barrier Level
51/// - **Format**: `12d`
52/// - **Usage**: Barrier levels for structured products and options
53/// - **Applications**: Knock-in/knock-out options, barrier derivatives
54/// - **Context**: Risk management and option pricing
55///
56/// ## Business Context
57/// - **Interest Calculations**: Precise interest accrual and payment calculations
58/// - **Derivative Pricing**: Essential component of derivative valuation models
59/// - **Risk Management**: Interest rate risk assessment and hedging
60/// - **Market Operations**: Standard market rate communication and processing
61///
62/// ## Examples
63/// ```logic
64/// :37H:C2,5000        // 2.5% credit interest rate
65/// :37H:D3,7500        // 3.75% debit interest rate
66/// :37H:CN0,2500       // -0.25% negative credit rate
67/// :37R:N0,1000        // -0.1% negative settlement rate
68/// :37L:1,2500         // 1.25% lower barrier level
69/// ```
70///
71/// ## Interest Rate Types
72/// - **Fixed Rates**: Predetermined rates for entire term
73/// - **Floating Rates**: Variable rates linked to reference rates
74/// - **Negative Rates**: Below-zero rates in low interest environments
75/// - **Barrier Levels**: Trigger levels for structured products
76///
77/// ## Rate Calculation Applications
78/// - **Simple Interest**: Principal × Rate × Time
79/// - **Compound Interest**: Principal × (1 + Rate)^Time
80/// - **Day Count Conventions**: ACT/360, ACT/365, 30/360
81/// - **Accrual Periods**: Daily, monthly, quarterly, annual
82///
83/// ## Regional Considerations
84/// - **European Markets**: ECB rates, EURIBOR, negative rate environments
85/// - **US Markets**: Federal funds rate, LIBOR transition, SOFR adoption
86/// - **Asian Markets**: Local reference rates and central bank policies
87/// - **Emerging Markets**: High volatility and inflation considerations
88///
89/// ## Rate Precision Standards
90/// - **Standard Rates**: Typically 4 decimal places (basis points)
91/// - **High Precision**: 6+ decimal places for complex calculations
92/// - **Market Convention**: Alignment with market quoting standards
93/// - **Regulatory Compliance**: Meeting precision requirements for reporting
94///
95/// ## Error Prevention
96/// - **Rate Validation**: Verify rate is within reasonable market ranges
97/// - **Sign Consistency**: Ensure negative sign usage is appropriate
98/// - **Precision Check**: Confirm adequate precision for calculations
99/// - **Market Alignment**: Validate rate against current market conditions
100///
101/// ## Related Fields
102/// - **Field 30**: Date specifications (rate effective dates)
103/// - **Field 32A**: Value Date, Currency, Amount (principal amounts)
104/// - **Field 36**: Exchange Rate (currency conversion rates)
105/// - **Derivative Terms**: Rate application and calculation periods
106///
107/// ## Interest Rate Environment
108/// - **Normal Rates**: Positive interest rate environments
109/// - **Zero Rates**: Zero interest rate policy (ZIRP) periods
110/// - **Negative Rates**: Negative interest rate policy (NIRP) environments
111/// - **Volatile Rates**: High volatility and uncertainty periods
112///
113/// ## STP Processing
114/// - **Rate Standardization**: Consistent rate format for automation
115/// - **Automated Calculations**: System-driven interest calculations
116/// - **Validation Enhancement**: Real-time rate validation and verification
117/// - **Exception Handling**: Automated detection of rate anomalies
118///
119/// ## Compliance Framework
120/// - **Regulatory Rates**: Central bank and regulatory rate requirements
121/// - **Market Conduct**: Fair and transparent rate setting and application
122/// - **Documentation**: Comprehensive rate documentation and audit trails
123/// - **Risk Management**: Rate risk assessment and control frameworks
124///
125/// ## Risk Management Applications
126/// - **Interest Rate Risk**: Duration and convexity analysis
127/// - **Credit Risk**: Credit spread and default rate considerations
128/// - **Market Risk**: Rate volatility and scenario analysis
129/// - **Operational Risk**: Rate accuracy and calculation precision
130///
131/// ## See Also
132/// - Swift FIN User Handbook: Interest Rate Field Specifications
133/// - Market Rate Standards: Rate Quotation and Calculation Conventions
134/// - Central Bank Guidelines: Reference Rate Standards and Policies
135/// - Risk Management: Interest Rate Risk Measurement and Control
136///   **Field 37H: Interest Rate Structure**
137///
138/// Contains interest rate with directional indicator and negative rate support.
139#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, SwiftField)]
140pub struct Field37H {
141    /// Rate type indicator
142    ///
143    /// Format: 1!a - 'C' (Credit rate) or 'D' (Debit rate)
144    /// Specifies whether rate applies to credit or debit transactions
145    #[component("1!a")]
146    pub rate_indicator: char,
147
148    /// Negative rate indicator
149    ///
150    /// Format: \[1!a\] - Optional indicator for negative interest rates
151    /// True when rate is negative (below zero), None for positive rates
152    #[component("[1!a]")]
153    pub is_negative: Option<bool>,
154
155    /// Interest rate value
156    ///
157    /// Format: 12d - Decimal rate with comma separator (typically percentage)
158    /// Example: 2,5000 represents 2.5% interest rate
159    #[component("12d")]
160    pub rate: f64,
161}