Sobes.tech
Senior

Tell me about an interesting problem — online blocking based on daily drawdown

sobes.tech AI

Answer from AI

Online drawdown-based blocking is a task of limiting losses in real-time within a trading system.

The essence: if the loss (drawdown) for the current trading day reaches a specified threshold, the system blocks further operations to prevent significant losses.

Implementation in Go includes:

  • Tracking the current balance and the maximum for the day.
  • Calculating drawdown as the difference between the maximum and the current balance.
  • A blocking mechanism that activates when the limit is reached.

An example of simplified logic:

var maxBalance float64 = 100000
var currentBalance float64 = 100000
var drawdownLimit float64 = 5000

func updateBalance(newBalance float64) bool {
    if newBalance > maxBalance {
        maxBalance = newBalance
    }
    currentBalance = newBalance
    drawdown := maxBalance - currentBalance
    if drawdown >= drawdownLimit {
        return false // block operations
    }
    return true // allow operations
}

This approach helps control risks in real-time and prevents significant losses.

Tell me about an interesting problem — online… - sobes.tech