Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PayComb

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.

Documentation

  • Language Guide — variables, types, the ST price table, operators, if statements, 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.

Prerequisites

OCaml Interpreter

Java GUI

  • Java Development Kit (JDK) 11 or higher.

Building and Running

opam exec -- dune build
opam exec -- dune exec src/main.exe <filename>.pco

A Taste of the Language

// 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.00

The 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.

Repository Layout

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

About

A domain-specific language for modelling financial payoffs such as options and structured products, backed by an OCaml interpreter and a Java-based GUI for interactive editing and visualization.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Contributors

Languages