BlyxDocumentation
Browse chapters
Documentation / Workflow recipes

Merganser · Measure a loss that recovered before the final observation

Report drawdown depth and time below the running peak for a historical series.

Measure a loss that recovered before the final observation

A recovered account can finish near its starting value while hiding a long underwater spell. Keep depth and duration visible together. The sample falls from 100 to 75 and recovers. Its depth meets the limit but its time below peak exceeds the duration limit.

Run the framework with your own input

Install Blyx 0.2.1 and a Rust toolchain with a host linker, then run the versioned project. Each positional argument is a number or a comma-separated numerical vector. The CLI accepts up to 16 entries per vector. The imported module accepts longer inputs.

git clone --depth 1 --branch v0.1.0 https://github.com/Rahulchaube1/blyx-merganser.git
cd blyx-merganser
blyxc native-run project.blyx -- "100,80,75,100" 0.25 1

API and return values

Returns [deepest fractional loss, peak index, trough index, longest underwater spell, limit breached]. Durations count observations, not calendar days. Invalid input returns an empty vector.

ArgumentAccepted input
equityVector of: positive finite number
depth_limitprobability in [0,1]
duration_limitnonnegative exact integer

Use the libraries independently

The framework vendors the same library source published in these two repositories. Each module has its own package page, input contract and regression suite.

Try the program

Output Ready
Expected output
0.25
0
2
2
1
Open in the full playground →

Practice

Change equity = [4, 2, 4], depth_limit = 0.5. Predict the result, then run the program.

Hint

Returns [deepest fractional loss, peak index, trough index, longest underwater spell, limit breached]. Durations count observations, not calendar days.

Worked solution

The result vector is [0.5, 0, 1, 1, 0]. Compare its fields with the return layout in the API section.

Find

    let equity = [100, 80, 75, 100];

Replace with

    let equity = [4, 2, 4];

Find

    let depth_limit = 0.25;

Replace with

    let depth_limit = 0.5;

Output after the change

0.5
0
1
1
0