Implementation:Avhz RustQuant ISO 4217
| Knowledge Sources | |
|---|---|
| Domains | Financial_Standards, Quantitative_Finance |
| Last Updated | 2026-02-07 19:00 GMT |
Overview
Concrete tool for representing ISO 4217 currency codes provided by the RustQuant library.
Description
The ISO_4217 struct represents a currency according to the ISO 4217 standard, storing both the alphabetic code (e.g., "USD") and the numeric code (e.g., "840"). The naming convention follows ISO standards: the first two letters correspond to the ISO 3166-1 alpha-2 country code and the third letter is the first letter of the currency name (e.g., USD = United States Dollar). The struct provides a constructor new(), accessor methods alphabetic() and numeric(), and implements Display for formatted output. It derives Debug, Clone, Copy, Eq, PartialEq, PartialOrd, Ord, and Hash for comprehensive use in collections and comparisons. The module contains implementations of 150+ currencies.
Usage
Use this module when you need standardized currency identification in pricing engines, FX calculations, portfolio accounting, or any context where currencies must be referenced by their ISO standard codes.
Code Reference
Source Location
- Repository: RustQuant
- File: crates/RustQuant_iso/src/iso_4217.rs
- Lines: 1-72
Signature
#[derive(Debug, Clone, Copy, Eq, PartialEq, PartialOrd, Ord, Hash)]
pub struct ISO_4217 {
pub alphabetic: &'static str,
pub numeric: &'static str,
}
impl ISO_4217 {
pub fn new(alphabetic: &'static str, numeric: &'static str) -> Self;
pub fn alphabetic(&self) -> &str;
pub fn numeric(&self) -> &'static str;
}
impl fmt::Display for ISO_4217 { ... }
Import
use RustQuant::iso::ISO_4217;
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| alphabetic | &'static str | Yes | ISO 4217 alphabetic currency code (e.g., "USD", "EUR") |
| numeric | &'static str | Yes | ISO 4217 numeric currency code (e.g., "840", "978") |
Outputs
| Name | Type | Description |
|---|---|---|
| ISO_4217 | struct | A currency code struct with both alphabetic and numeric representations |
| Display | String | Formatted as "Alphabetic: {code}, Numeric: {code}" |
Usage Examples
use RustQuant::iso::ISO_4217;
// Create a USD currency code
let usd = ISO_4217::new("USD", "840");
assert_eq!(usd.alphabetic(), "USD");
assert_eq!(usd.numeric(), "840");
// Display formatting
println!("{}", usd); // Output: Alphabetic: USD, Numeric: 840
// Can be used as HashMap keys (implements Hash)
use std::collections::HashMap;
let mut rates: HashMap<ISO_4217, f64> = HashMap::new();
rates.insert(usd, 1.0);