Skip to content

Latest commit

 

History

History
142 lines (111 loc) · 4.4 KB

README.md

File metadata and controls

142 lines (111 loc) · 4.4 KB

financial accumulator

Accumulator is a derivative product for purchasing shares with leverage in a continuous and accumulating manner (often on a daily basis) until either its settlement date is reached or the share price goes up above some pre-agreed knock-out price.
If you are not familiar with its concept, be advised to take a look at this wikipedia article.

accumulator in dsl4sc/scxml

A simplified version of accumulator is defined as a statechart as follows.

  • accumulator in dsl4sc

  • accumulator in scxml generated from the above dsl4sc definition

    operation flow
    Upon each day_close event,
    • if the share price (carried by day_close as _event.data.price) is high above ko_price,
      perform the knockout (sell-off) operation and terminate (_knockout)
    • otherwise (_not_knockout),
      1. purchase shares (_over_strike or _under_strike), the amount of which varies depending on the price
      2. terminate normally if the expiration date is reached, or wait for a day_open event to repeat the entire process

accumulator

For the detail of the definition (and its monitors listed below), refer to this material.

monitors for accumulator

In addition, several monitors are defined, also as statecharts, to ensure that the accumulator works exactly as intended.

  • monitor1: simple event-pattern checking

    monitor1 statechart
    monitor1 examines whether incoming events match with the following regular pattern:

    init; day_close; (day_open; day_close)*; (knockout + terminate)

  • monitor2: monitor1 + event parameter validation

    monitor2 statechart
    in addition to what monitor1 does, monitor2 validates the share price upon knockout.
    if knockout is triggered incorrectly (when the price is not higher than ko_price), a runtime error is raised.
  • monitor3: safety and liveness

    monitor3 statechart
    safety: it never occurs that both knockout termination and normal termination take place in a single run.
    liveness: it will always eventually occur that either knockout termination or normal termination takes place.
  • monitor4: anomaly detection, a sort of

    monitor4 statechart
    let us call it an anomaly that the following conditions both hold.
    • _over_strike never occurs until termination
    • _under_strike never occurs until termination
    monitor4 detects this anomaly and raises an error.

scenarios

running the accumulator statechart and its monitors

  • to run the accumulator against the valid scenarios

    $ shelltest accumulator.conf
    

    send input events to accumulator via MQTT

    $ shelltest passthru_accumulator.conf
    
  • to run the monitors against the all valid/invalid scenarios

    $ shelltest monitors.conf
    

    send input events to monitors via MQTT

    $ shelltest passthru_monitors.conf
    
  • to run the accumulator and each monitor connected via MQTT against the scenarios

    $ shelltest accumulator_monitors.conf