PayComb is a domain-specific language (DSL) for describing combinations of
stock options and calculating the profit they would produce at different
terminal stock prices. The interpreter is built in OCaml using menhir for
parsing and ocamllex for lexing. A Java-based GUI is also available for a
more interactive experience.
- Language Guide — variables, types, the
STprice table, operators,ifstatements, user-defined functions, and scoping rules. - Built-in Payoffs — every payoff
constructor (
Call,Put,Collar, ...) with its payoff formula. - Implementation Notes — how the lexer, parser, and interpreter work, for those interested in the OCaml internals.
The scripts in test/ are runnable examples with expected output
in comments.
- Java Development Kit (JDK) 11 or higher.
opam exec -- dune build
opam exec -- dune exec src/main.exe <filename>.pco// Payoffs are built from Call, Put, and friends, and combined with + and *.
let strike = 100;
let strad = Call(strike) + Put(strike);
// ST holds the terminal stock prices you care about; printing a payoff
// tabulates its value at each of them.
ST = 80, 90, 100, 110, 120;
print(strad);
// ST 80.00 90.00 100.00 110.00 120.00
// output 20.00 10.00 0.00 10.00 20.00
// Functions, conditionals, and recursion:
fn protective(k) {
if (k <= 0) {
return Call(0);
}
return LongStock(k) + Put(k);
}
print(protective(100));
// Evaluate a payoff at a single price:
print(strad(80)); // 20.00The language also has booleans, comparison operators (==, !=, <,
>, <=, >=), mutable variables with lexical shadowing, and structural
equality on payoffs (Straddle(5) == Call(5) + Put(5) is true). See the
Language Guide for the full story.
| Path | Contents |
|---|---|
src/ |
lexer, parser, AST, interpreter, payoff algebra (OCaml) |
test/ |
example .pco scripts; error_*.pco demonstrate error messages |
docs/ |
detailed documentation |
gui/ |
Java GUI |
verification/ |
Isabelle theory for the payoff algebra |