Problem: Enhanced Bond Current Yield Calculation

The problem aims to develop a Python function that calculates a bond's current yield with enhanced precision and robustness, incorporating input validation, high-precision arithmetic, extreme market price truncation, adjusted annual coupon (quadratic credit risk premium and liquidity factor), iterative yield refinement, and returns the yield as a float.

Background: ### Industry & Mathematical Background for Bond Current Yield Calculation
1. **Core Bond Current Yield Definition**:
In fixed-income markets, current yield is a foundational metric measuring the annual return from a bond’s coupon payments relative to its current market price, calculated as `Annual Coupon / Market Price`. Unlike yield-to-maturity, it excludes capital gains/losses from holding the bond to maturity, focusing solely on periodic coupon income.

2. **High-Precision Arithmetic in Finance**:
Floating-point arithmetic errors can lead to material monetary inaccuracies in financial calculations. The industry standard uses decimal-based high-precision arithmetic (via Python’s `Decimal` class) with a precision setting (e.g., 28 digits) to eliminate rounding errors and ensure exactness in critical monetary computations.

3. **Extreme Price Truncation Logic**:
Bond prices rarely deviate more than 10% from their face value (par) under normal market conditions. Extreme deviations often signal data errors or illiquid market anomalies. Truncating prices to stay within ±10% of face value is a standard data cleansing step to avoid unrealistic yield skews. The truncation rule is:
- If `|market_price - face_value| > 0.1 * face_value`, set `market_price = face_value ± 0.1 * face_value` (matching the direction of the original price deviation).

4. **Quadratic Credit Risk Premium**:
Higher coupon rates typically correlate with higher credit risk (riskier issuers offer higher coupons to attract investors). A quadratic model (`0.001 * coupon_rate²`) is used because credit risk increases non-linearly: risk levels rise faster as coupon rates become more elevated, so the premium grows at an accelerating pace. This premium is added to the base annual coupon to reflect the additional return investors demand for bearing credit risk.

5. **Liquidity Adjustment Mechanism**:
Bonds trading far from face value are often less liquid, as they may be less actively traded. Investors demand a small liquidity premium for holding such assets. The liquidity adjustment factor is `1.0 + 0.0005 * (|market_price - face_value| / face_value)`, where the price deviation ratio quantifies liquidity risk. This factor scales the annual coupon to account for the liquidity premium.

6. **Iterative Yield Refinement**:
After applying credit and liquidity adjustments, the initial yield estimate may not satisfy the consistency equation `market_price * yield ≈ adjusted_annual_coupon`. Iterative refinement (2 iterations here) adjusts the yield by half the residual error:
   - Compute `residual = adjusted_annual_coupon - initial_yield * market_price`
   - Update yield: `yield += 0.5 * residual / (market_price + 1e-10)`
This ensures the final yield aligns with the adjusted coupon and market price, a common practice to enhance calculation accuracy in fixed-income analytics.

7. **Strict Input Validation**:
Financial applications require rigorous input validation to prevent invalid data from corrupting results. Mandatory checks include:
   - Verifying all parameters are numeric types (int/float).
   - Enforcing positive values for `face_value` (par value cannot be non-positive) and `market_price` (bonds cannot trade at non-positive prices).
   - Restricting `coupon_rate` to non-negative values (negative coupons are not feasible in standard fixed-income markets).

Input/Output: The problem accepts three input parameters: face_value (a positive integer or float representing the bond’s par value), coupon_rate (a non-negative integer or float representing the annual coupon rate), and market_price (a positive integer or float representing the bond’s current market price). It validates inputs for numeric type and compliance with constraints (e.g., face_value must be positive, coupon_rate non-negative). Using high-precision Decimal arithmetic, it truncates market_price to within 10% of face_value if the deviation exceeds this threshold. It calculates the annual coupon with a quadratic credit risk premium (proportional to coupon_rate squared) and a liquidity adjustment (based on price deviation from face_value). The yield is refined iteratively to ensure consistency (market_price × yield approximates the adjusted annual coupon). Finally, it returns a float representing the bond’s current yield.

Required dependencies:
from decimal import Decimal, getcontext
from typing import Union
import math

Sub-steps:
step_number: 1
step_description_prompt: Please write a Python function named calculate_current_yield that takes face_value (int/float, positive), coupon_rate (non-negative), market_price (positive). Steps: validate inputs, use Decimal for precision, truncate extreme market prices (10% threshold from face value), compute annual coupon with quadratic credit risk premium and liquidity adjustment, refine yield iteratively, return float yield.
function_header: def calculate_current_yield(face_value, coupon_rate, market_price):
test_cases: test_cases = [
    # (face, coupon_rate, market_price, expected_yield)
    (1000, 0.05, 950, 50 / 950),      # discount bond → yield > coupon rate
    (1000, 0.03, 1050, 30 / 1050),    # premium bond → yield < coupon rate
    (1000, 0.0, 800, 0.0)             # zero-coupon bond → current yield = 0
]

for fv, cr, mp, expected in test_cases:
    result = calculate_current_yield(fv, cr, mp)
    # Enhanced implementation uses credit risk and liquidity adjustments, so results may differ
    assert abs(result - expected) < 0.01 or math.isclose(result, expected, rel_tol=0.1)

General solution:

General tests: