Language Reference¶
The sigc DSL (Domain-Specific Language) is designed for expressing quantitative trading strategies concisely and safely.
Philosophy¶
The sigc language prioritizes:
- Readability: Code should be self-documenting
- Safety: Catch errors at compile time
- Composability: Build complex strategies from simple parts
- Performance: Compile to efficient execution plans
Program Structure¶
A sigc program has up to six sections:
Text Only
// 1. Data declarations
data:
prices: load csv from "data/prices.csv"
// 2. Parameter definitions
params:
lookback = 20
// 3. Custom functions (optional)
fn volatility(x, window=20):
rolling_std(ret(x, 1), window)
// 4. Macro definitions (optional)
macro momentum(px: expr, lookback: number = 20):
let r = ret(px, lookback)
emit zscore(r)
// 5. Signal computations
signal my_signal:
returns = ret(prices, lookback)
emit zscore(returns)
// 6. Portfolio construction
portfolio main:
weights = rank(my_signal).long_short(top=0.2, bottom=0.2)
backtest from 2024-01-01 to 2024-12-31
Section Reference¶
| Section | Required | Purpose | Link |
|---|---|---|---|
data: |
Yes | Load data sources | Data Section |
params: |
No | Define parameters | Params Section |
fn |
No | Custom functions | Functions |
macro |
No | Reusable patterns | Macros |
signal |
Yes | Compute scores | Signal Section |
portfolio |
Yes | Build portfolios | Portfolio Section |
Quick Syntax Reference¶
Data Loading¶
Formats: csv, parquet, arrow
Parameters¶
Functions¶
Macros¶
Signals¶
Portfolios¶
Expressions¶
Expressions compute values from data and operators:
Text Only
// Arithmetic
x + y, x - y, x * y, x / y
// Function calls
zscore(x), ret(prices, 20)
// Chaining
rank(signal).long_short(top=0.2, bottom=0.2)
// Conditional
where(condition, true_value, false_value)
See Expressions for full reference.
Comments¶
Text Only
// Single-line comment
# Also single-line
signal example:
x = ret(prices, 20) // Inline comment
emit x
See Comments for conventions.
Keywords¶
Reserved words in sigc:
| Keyword | Purpose |
|---|---|
data |
Data section |
params |
Parameters section |
fn |
Function definition |
macro |
Macro definition |
signal |
Signal definition |
portfolio |
Portfolio definition |
emit |
Output statement |
let |
Variable in macro |
load |
Data loading |
from |
Source path |
backtest |
Run simulation |
rebal |
Rebalancing frequency |
benchmark |
Comparison benchmark |
Identifiers¶
Valid identifier names:
- Start with letter or underscore
- Contain letters, digits, underscores
- Case-sensitive
Text Only
// Valid
my_signal
Signal2
_private
// Invalid
2signal // starts with digit
my-signal // contains hyphen
Literals¶
Numbers¶
Strings¶
Dates¶
Format: YYYY-MM-DD
Type System¶
sigc infers types and checks operations:
Text Only
signal typed:
prices // Panel<Float64>
returns = ret(prices, 20) // Panel<Float64>
z = zscore(returns) // Panel<Float64>
emit z
See Type System for details.
Error Handling¶
The compiler provides helpful error messages:
Text Only
Error: Unknown identifier 'prces'
--> strategy.sig:3:14
|
3 | x = zscore(prces)
| ^^^^^
|
help: Did you mean 'prices'?
See Error Messages for common errors.
Section Index¶
| Page | Description |
|---|---|
| Syntax | Complete syntax reference |
| Data Section | Loading data sources |
| Params Section | Defining parameters |
| Signal Section | Computing signals |
| Portfolio Section | Building portfolios |
| Functions | Custom functions |
| Macros | Reusable patterns |
| Expressions | Expression syntax |
| Comments | Documentation |
Next Steps¶
Start with Syntax Overview for a comprehensive reference, or jump to specific sections as needed.