Optimising a Multi-Line XoL Model for Speed, Structure & Future Scalability

The Challenge
A global specialty insurer had a large, multi-line excess-of-loss model in hx Renew. Although functionally complete, it had become extremely difficult to maintain. Recalculations could exceed four seconds, and core rating logic existed inside a single 4,000-line function — with an additional 3000-line segment loop and roughly 80 smaller supporting functions scattered throughout the codebase.

The original model developer had since left the company, leaving the team with a slow, opaque, hard-to-debug model that had to run daily for real underwriting needs.

The client needed:

  • Much faster runtime,

  • A clear and maintainable structure,

  • Confidence that results remained consistent, and

  • A foundation for a future project aligning this XoL model with their quota share model.


Our Approach
We worked closely with the client’s underwriter and actuary, meeting twice weekly to share progress, validate logic, and test changes.

The technical work focused on three pillars:

1. Deep refactoring for clarity and modularity

  • Broke down the 4,000-line core algorithm into 120 task oriented functions.

  • Grouped logic into a clean folder structure (Algorithms, Views, Data Schema), mirroring the UI for easy navigation.

  • Kept exposure rating and experience rating logic in separate, clearly signposted modules.

2. Python performance optimisation

We achieved major speed improvements through:

  • Removing unnecessary dataframe creation,

  • Preferring dictionary lookups over dataframe lookups,

  • Using list comprehensions instead of loops,

  • Vectorising logic and progressively moving code outside the segment loop.

3. Safe, iterative improvement

To ensure absolute consistency of results:

  • Each small change was followed by a full policy test suite.

  • Speed benchmarking was repeated throughout to measure progress.

  • Bugs in the legacy model were identified and raised with the client.


The Result

Across a range of scenarios, the model consistently ran 40–55% faster.

Additional benefits:

  • A clean, modular structure that the client found much easier to follow.

  • Improved maintainability and faster onboarding for new developers.

  • A future-proofed approach enabling shared libraries for future alignment of XoL and QS models.

Client Feedback

“We’ve been really impressed. The model runs noticeably faster, the new structure is intuitive to navigate, and merging the refactored functions into our broader model has been far easier than we expected.”

Next
Next

Building a Cyber Pricing Model in hx Renew