Monte Carlo Convergence and Statistical Drift Test Suite Generator
Generate statistical test harnesses and Monte Carlo simulation scripts to validate convergence, bias, and distribution stability in quantitative models.
Use this template when testing non-deterministic models, probabilistic algorithms, or quantitative financial estimators. It creates executable validation scripts applying rigorous statistical hypothesis testing and convergence checks.
Role: Lead Quantitative Research Systems Engineer specializing in statistical validation and stochastic model quality assurance.
Context
- Stochastic Algorithm / Estimator Definition: {{stochastic_model_definition}}
- Theoretical Null Hypothesis and Properties: {{null_hypothesis_formulation}}
- Sample Size Progression Schedule: {{sample_size_schedule}}
- Significance Level Alpha: {{significance_alpha}}
- Statistical Test Methodology: {{statistical_test_type}}
- Convergence Metric and Error Bound: {{convergence_metric}}
Task
Develop an automated Python statistical testing script that executes Monte Carlo trials of {{stochastic_model_definition}}, applies {{statistical_test_type}} to test {{null_hypothesis_formulation}} at alpha {{significance_alpha}}, and verifies asymptotic behavior against {{convergence_metric}}.
Method
- Define reproducible multi-seed execution harness with vectorized pseudo-random and quasi-random sequence generators.
- Encapsulate {{stochastic_model_definition}} into a vectorized simulator capable of batch sampling across {{sample_size_schedule}}.
- Construct iterative estimators tracking running empirical means, higher-order moments (skewness, kurtosis), and standard error rates.
- Implement the exact test statistic computation for {{statistical_test_type}} (e.g., Kolmogorov-Smirnov, Anderson-Darling, permutation test, or t-test).
- Compute critical values and empirical p-values against the significance threshold {{significance_alpha}} to evaluate {{null_hypothesis_formulation}}.
- Evaluate convergence decay rates across {{sample_size_schedule}} to confirm empirical convergence matches {{convergence_metric}} (e.g., O(1/sqrt(N)) error decay).
- Build a failure diagnostic logger detailing distribution shifts, p-value trends, and bootstrap confidence intervals upon test failure.
Constraints
- MUST provide runnable Python script utilizing standard statistical libraries (e.g., SciPy, NumPy, Statsmodels).
- MUST enforce deterministic seed management with options to run permutation multi-seed sweeps.
- MUST NOT hardcode p-value outcomes; all metrics must be dynamically calculated from simulation outputs.
- Implement explicit assertion guards raising descriptive AssertionError messages with computed p-values.
Output format
Return a clean, self-contained Python script organized into the following explicit blocks:
- Imports, Seed Initialization, and Global Test Constants
- Monte Carlo Execution Engine for {{stochastic_model_definition}}
- Statistical Test Function Implementing {{statistical_test_type}}
- Asymptotic Convergence Verification Suite for {{convergence_metric}}
- Main CLI Runner with Structured Diagnostic Summary Output
Self-review
- Confirm that the script tests {{null_hypothesis_formulation}} using {{significance_alpha}} correctly.
- Verify that the sample iteration dynamically processes all values in {{sample_size_schedule}}.
- Check that convergence assertions explicitly validate the error bound defined in {{convergence_metric}}.
Explicit role, a named task, and discrete steps the model can follow.
Background, inputs and variables the model needs before it starts.
Hard boundaries — what the model must and must not do.
A named, field-level shape for the response.
Ordered work items that force analysis before an answer.
Length and structure that travel across frontier models.
Signal density — instruction weight without padding.
Documented variables so the scaffold adapts to new inputs.
Quality bar, assumptions and behaviour when inputs are thin.
How much real usage the template has behind it.