Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Principle:51bitquant Ai hedge fund crypto Position Sizing Risk Control

From Leeroopedia
Knowledge Sources
Domains Risk_Management, Portfolio_Management
Last Updated 2026-10-28 14:00 GMT

Overview

A risk control pattern that caps the maximum capital allocated to any single position as a fraction of total portfolio value, preventing concentration risk from a single asset.

Description

Position sizing risk control enforces a hard ceiling on per-asset exposure. For each ticker, it computes the current position value, the total portfolio value, and a position limit (a fixed fraction — 20% here — of the total). The remaining buying power is `position_limit − current_position_value`, further capped by available cash. This remaining limit flows downstream as a constraint on the decision-maker: the LLM cannot buy more than `max_shares = remaining_limit / current_price`.

This addresses the problem that an unconstrained AI agent, given a strong bullish signal, might allocate the entire portfolio to one ticker, creating catastrophic concentration risk.

Usage

Use this pattern whenever a decision-maker (LLM or otherwise) could otherwise over-allocate to a single asset. Apply it as a hard constraint computed before the decision, not as a post-check. Tune the fraction (e.g. 20%) to the desired diversification level and risk tolerance.

Theoretical Basis

For ticker i with current price pi and current position value vi, total portfolio value V, and limit fraction f:

limiti=f⋅V

remainingi=limiti−vi

Failed to parse (syntax error): {\displaystyle \text{max\_size}_i = \min(\text{remaining}_i,\ \text{cash}) }

Failed to parse (syntax error): {\displaystyle \text{max\_shares}_i = \frac{\text{max\_size}_i}{p_i} }

The decision-maker's buy quantity is bounded by Failed to parse (syntax error): {\displaystyle \text{max\_shares}_i} .

Pseudo-code:

# Abstract pattern
for ticker in tickers:
    price = last_close(ticker)
    total_value = cash + sum(position_values)
    limit = fraction * total_value
    remaining = limit - current_position_value(ticker)
    max_size = min(remaining, cash)
    max_shares[ticker] = max_size / price

Practical Guide

  • Compute the constraint before the decision, and pass `max_shares` into the prompt as a hard cap.
  • Make the constraint visible to the decision-maker (include reasoning: portfolio value, current position, limit) so the model understands why a buy is capped.
  • Treat short positions symmetrically where possible, with margin requirements applied.
  • Re-evaluate each bar since portfolio value and prices move.

Related Pages

Implemented By

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment