A compiler for the ValuaScript financial modeling language.
Project description
ValuaScript: A Declarative Language for High-Performance Monte Carlo Simulations
ValuaScript combines a simple, declarative scripting language with a high-performance, multi-threaded C++ engine to create, run, and analyze complex quantitative models. It is purpose-built to deliver both clarity and speed, making sophisticated Monte Carlo simulations accessible and maintainable.
The Core Philosophy: A Vocabulary for Simulations
Financial and scientific modelling often forces a choice between two extremes: the intuitive but slow, error-prone nature of spreadsheets, and the powerful but verbose, complex nature of general-purpose programming languages.
ValuaScript was created to bridge this gap. It is not a general-purpose language; it is a vocabulary for describing simulations.
This approach is guided by three principles:
-
Declarative & Readable: A ValuaScript file describes what the model is, not how to compute it. There are no loops, complex data structures, or pointers. The script reads like a novel or a specification sheet, making models easy to write, review, and maintain for domain experts and programmers alike.
-
High-Performance by Design: All the heavy lifting—numerical calculations, statistical sampling, and data aggregation—is handled by a multi-threaded C++17 engine. Scripting a model in ValuaScript is simply wiring together these pre-compiled, high-speed components. A simulation that might take minutes in other tools is executed in seconds.
-
Extensible through Contribution: The language grows by expanding its C++ core. Need a niche financial model or a specific epidemiological simulation? Implement it once in optimized C++, and it instantly becomes a new "word" in the ValuaScript vocabulary for everyone to use. This creates a powerful, community-driven flywheel for growth.
Architecture: AOT Compiler & Virtual Machine
ValuaScript utilizes an Ahead-of-Time (AOT) compilation pipeline to ensure runtime efficiency:
- The
vscCompiler (Python): Parses the ValuaScript script, resolves imports, performs semantic analysis, optimizes the AST, and emits JSON bytecode. - The
vseEngine (C++17): A fast, multi-threaded VM that loads the bytecode and executes the simulation, handling numerical computation and sampling.
Key Features
✨ The ValuaScript Language
-
Intuitive Syntax: A clean, declarative language with a familiar, spreadsheet-like formula syntax.
-
📦 Code Modularity: Organize models into reusable modules with
@import. The compiler resolves the entire dependency graph, including nested and shared ("diamond") dependencies. -
🔧 User-Defined Functions: Create reusable, type-safe functions with docstrings, strict lexical scoping, and compile-time recursion detection.
-
✨ Tuples & Multi-Assignment: Functions can return multiple values (including mixed types like scalars and vectors), which can be unpacked into multiple variables in a single, clean assignment.
-
🛡️ Compile-Time Safety: Catch logical errors like type mismatches, incorrect function arguments, undefined variables, and circular imports before you run.
-
🎲 Integrated Monte Carlo Support: Natively supports a rich library of statistical distributions (
Normal,Pert,Lognormal,Beta, etc.).
🚀 The AOT Compiler & C++ Engine
-
High-Performance Backend: A multi-threaded Virtual Machine (VM) written in modern C++17, designed to leverage all available CPU cores for maximum parallelism.
-
🧠 Intelligent AOT Compiler: Performs all semantic analysis and optimization before execution, generating a low-level JSON bytecode for the engine.
-
⚙️ Advanced Optimizations:
-
Function Inlining: User-defined functions are seamlessly inlined, eliminating call overhead.
-
Loop-Invariant Code Motion: Deterministic calculations are automatically identified and run only once.
-
Dead Code Elimination: Unused variables are stripped from the final bytecode.
⚡ The VS Code Extension
- Live Value Preview: Hover over any variable to see its calculated value instantly. For stochastic variables, the engine runs a sample simulation in the background and displays the mean.
-
Real-Time Diagnostics: Get immediate, as-you-type feedback on errors.
-
Hover-for-Help: See full signatures and docstrings for all built-in and user-defined functions.
- Go-to-Definition: Seamlessly navigate to the source of any user-defined function.
Quick Start: Installation
Get started in minutes with our automated installation scripts.
Prerequisites
-
Python 3.13+ must be installed and available in your PATH.
-
Administrator/sudo privileges are required to add the tools to your system's PATH.
macOS & Linux
Open your terminal and run the following one-line command:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Alessio2704/valuascript/main/scripts/install.sh)"
Windows
Open a new PowerShell terminal as Administrator and run:
Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://raw.githubusercontent.com/Alessio2704/valuascript/main/scripts/install.ps1'))
After installation, you must open a new terminal window for the changes to take effect.
Uninstalling
The same scripts can be used to uninstall the tools. Simply replace install.sh with uninstall.sh (for Mac/Linux) or install.ps1 with uninstall.ps1 (for Windows) in the commands above.
🚀 Performance Benchmarks
Comparison running the project found at examples/financial/google_dcf_valuation for 100,000 iterations (MacBook Pro M4 Pro 24gb Ram macOS Sequoia 15.6.1):
| Platform | Iterations | Execution Time | Speedup |
|---|---|---|---|
| ValuaScript | 100k | 0.260s | 1x |
| Excel (XLRisk Add-In) | 100k | 45min 5s | ~10,400x Slower |
🌟 Current Status: Beta Release
ValuaScript is currently in a stable Beta release. Key features are implemented and tested across macOS, Windows, and Linux. The current version excels at DCF modeling and general Monte Carlo simulations.
Roadmap
- Empirical Distribution Sampling: Add a function to create a custom sampler from a real-world data series (e.g., historical stock returns), allowing models to be driven by actual data instead of theoretical distributions.
- GPU Acceleration: Explore CUDA/OpenCL to offload the "embarrassingly parallel" Monte Carlo workload to the GPU, providing an order-of-magnitude performance increase for simulations with millions of trials.
License
This project is distributed under the MIT License. See the LICENSE file for more information.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file vsc_toolchain-1.0.12.tar.gz.
File metadata
- Download URL: vsc_toolchain-1.0.12.tar.gz
- Upload date:
- Size: 54.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
705325e8ed88fea202301f71350940f891af15ac37781f8dc34497c96713f4f1
|
|
| MD5 |
ef8308c4f47eaeeb6b9c4239a5254093
|
|
| BLAKE2b-256 |
b046362f84a16495f963b10fec9a59666f2c02c3d7b173a38cc1f3906c022526
|
File details
Details for the file vsc_toolchain-1.0.12-py3-none-any.whl.
File metadata
- Download URL: vsc_toolchain-1.0.12-py3-none-any.whl
- Upload date:
- Size: 37.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
db42a158bd7b0dd27c9761ac1a8067d70b37e420e7599f60534c23e5a1b4dcc6
|
|
| MD5 |
a0d0b0c2b332165b8ee50352879fed12
|
|
| BLAKE2b-256 |
470eb8e7d63abc9bbad540d3643d175e8fc445b08f0c345c6162e7a705ae9849
|