Skip to content

Replace @assert with proper exceptions in risk measure constructors #124

@alecloudenback

Description

@alecloudenback

Summary

The VaR, CTE, and WangTransform constructors use @assert for input validation:

function VaR::T) where {T}
    @assert 0 <= α < 1 "α of  is not 0 ≤ α < 1"
    return new{T}(α)
end

@assert can be optimized away by the compiler (e.g. with --check-bounds=no), making it unreliable for public API validation. These should use throw(DomainError(...)) or throw(ArgumentError(...)).

The test file (test/risk_measures.jl) currently tests for AssertionError specifically, which would need updating.

Fix

  • Replace @assert with explicit throw in VaR, CTE, WangTransform constructors
  • Update tests from @test_throws AssertionError to the new exception type

🤖 Generated with Claude Code

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions