Skip to main content
Version: 1.0 (Current)

Position Sizing Schema

This document provides the complete schema reference for the positionSizing configuration object. Position sizing determines how much capital to allocate to each trade.

Overview​

Position sizing is Step 2 of algorithm configuration. It controls:

  • How position sizes are calculated
  • Whether pyramiding (scaling in) is enabled
  • Position size limits and constraints

Schema Structure​

interface PositionSizing {
method: PositionSizingMethod

// Method-specific parameters
percentage?: number // For 'percentage' method
fixedQuantity?: number // For 'fixed_quantity' method
fixedAmount?: number // For 'fixed_amount' method
riskPercentage?: number // For 'risk_based' method
atrPeriod?: number // For 'volatility_adjusted' method
atrMultiplier?: number // For 'volatility_adjusted' method
kellyFraction?: number // For 'kelly_criterion' method

// Pyramiding configuration
pyramiding: PyramidingConfig
}

Position Sizing Methods​

method​

  • Type: enum
  • Required: Yes
  • Values:
    • percentage - Fixed percentage of account balance
    • fixed_quantity - Fixed number of shares/contracts
    • fixed_amount - Fixed rupee amount per trade
    • risk_based - Based on risk percentage and stop loss distance
    • volatility_adjusted - Adjusted based on ATR volatility
    • kelly_criterion - Optimal bet sizing based on win rate and profit factor

Method-Specific Parameters​

Percentage-Based Sizing​

Uses a fixed percentage of account balance for each trade.

{
method: 'percentage',
percentage: number // 0.01 to 100
}

percentage​

  • Type: number
  • Required: Yes (when method is 'percentage')
  • Range: 0.01 to 100
  • Recommended: 1 to 5
  • Description: Percentage of account balance to risk per trade
  • Example: 2.5 (2.5% of account)

Calculation:

Position Size = (Account Balance × Percentage) / Current Price

Example:

{
"method": "percentage",
"percentage": 2.5,
"pyramiding": {
"enabled": false
}
}

With ₹100,000 account and ₹500 stock price:

  • Position Value = ₹100,000 × 2.5% = ₹2,500
  • Quantity = ₹2,500 / ₹500 = 5 shares

Fixed Quantity Sizing​

Uses a fixed number of shares or contracts per trade.

{
method: 'fixed_quantity',
fixedQuantity: number // Minimum 1
}

fixedQuantity​

  • Type: number
  • Required: Yes (when method is 'fixed_quantity')
  • Minimum: 1
  • Description: Fixed number of shares/contracts to trade
  • Example: 10 (always trade 10 shares)

Use Cases:

  • Testing strategies with consistent exposure
  • Trading futures/options with specific lot sizes
  • Maintaining equal position sizes across symbols

Example:

{
"method": "fixed_quantity",
"fixedQuantity": 10,
"pyramiding": {
"enabled": false
}
}

Always trades 10 shares regardless of price or account size.


Fixed Amount Sizing​

Uses a fixed rupee amount per trade.

{
method: 'fixed_amount',
fixedAmount: number // Minimum 100
}

fixedAmount​

  • Type: number
  • Required: Yes (when method is 'fixed_amount')
  • Minimum: 100
  • Description: Fixed rupee amount to invest per trade
  • Example: 5000 (always invest ₹5,000)

Calculation:

Quantity = Fixed Amount / Current Price

Example:

{
"method": "fixed_amount",
"fixedAmount": 5000,
"pyramiding": {
"enabled": false
}
}

With ₹500 stock price:

  • Quantity = ₹5,000 / ₹500 = 10 shares

With ₹250 stock price:

  • Quantity = ₹5,000 / ₹250 = 20 shares

Risk-Based Sizing​

Calculates position size based on risk percentage and stop loss distance.

{
method: 'risk_based',
riskPercentage: number // 0.1 to 10
}

riskPercentage​

  • Type: number
  • Required: Yes (when method is 'risk_based')
  • Range: 0.1 to 10
  • Recommended: 0.5 to 2
  • Description: Percentage of account to risk per trade
  • Example: 1.5 (risk 1.5% of account)

Calculation:

Risk Amount = Account Balance × Risk Percentage
Stop Distance = Entry Price - Stop Loss Price
Position Size = Risk Amount / Stop Distance

Example:

{
"method": "risk_based",
"riskPercentage": 1.5,
"pyramiding": {
"enabled": false
}
}

With ₹100,000 account, ₹500 entry, ₹490 stop loss:

  • Risk Amount = ₹100,000 × 1.5% = ₹1,500
  • Stop Distance = ₹500 - ₹490 = ₹10
  • Quantity = ₹1,500 / ₹10 = 150 shares

Volatility-Adjusted Sizing​

Adjusts position size based on ATR (Average True Range) volatility.

{
method: 'volatility_adjusted',
atrPeriod: number, // 5 to 50
atrMultiplier: number // 0.5 to 5.0
}

atrPeriod​

  • Type: number
  • Required: Yes (when method is 'volatility_adjusted')
  • Range: 5 to 50
  • Default: 14
  • Description: Period for ATR calculation
  • Example: 20

atrMultiplier​

  • Type: number
  • Required: Yes (when method is 'volatility_adjusted')
  • Range: 0.5 to 5.0
  • Default: 2.0
  • Description: Multiplier for ATR-based position sizing
  • Example: 2.5

Calculation:

ATR = Average True Range over period
Risk Amount = Account Balance × Base Risk %
Adjusted Risk = Risk Amount / (ATR × Multiplier)
Position Size = Adjusted Risk / Current Price

Example:

{
"method": "volatility_adjusted",
"atrPeriod": 14,
"atrMultiplier": 2.0,
"pyramiding": {
"enabled": false
}
}

Higher volatility (larger ATR) = Smaller position size Lower volatility (smaller ATR) = Larger position size


Kelly Criterion Sizing​

Optimal bet sizing based on historical win rate and profit factor.

{
method: 'kelly_criterion',
kellyFraction: number // 0.1 to 1.0
}

kellyFraction​

  • Type: number
  • Required: Yes (when method is 'kelly_criterion')
  • Range: 0.1 to 1.0
  • Default: 0.25 (Quarter Kelly)
  • Description: Fraction of Kelly percentage to use
  • Example: 0.5 (Half Kelly)

Formula:

Kelly % = (Win Rate × Avg Win - Loss Rate × Avg Loss) / Avg Win
Position Size = Account Balance × Kelly % × Kelly Fraction

Requirements:

  • Minimum 30 historical trades
  • Win rate between 30% and 70%
  • Profit factor > 1.0

Example:

{
"method": "kelly_criterion",
"kellyFraction": 0.25,
"pyramiding": {
"enabled": false
}
}

With 60% win rate, 1.5 profit factor:

  • Full Kelly might suggest 20% position size
  • Quarter Kelly (0.25) = 5% position size (more conservative)

Pyramiding Configuration​

Pyramiding allows adding to winning positions (scaling in).

interface PyramidingConfig {
enabled: boolean
maxLevels?: number // 1 to 10
sizingMethod?: 'equal' | 'decreasing' | 'increasing'
profitThreshold?: number // Percentage profit to add
}

enabled​

  • Type: boolean
  • Required: Yes
  • Description: Whether pyramiding is enabled
  • Default: false
  • Example: true

maxLevels​

  • Type: number
  • Required: Yes (when enabled is true)
  • Range: 1 to 10
  • Description: Maximum number of pyramid levels (including initial entry)
  • Example: 3 (initial + 2 add-ons)

sizingMethod​

  • Type: enum
  • Required: Yes (when enabled is true)
  • Values:
    • equal - Each level has same size as initial
    • decreasing - Each level is 50% of previous
    • increasing - Each level is 1.5x previous
  • Example: "decreasing"

profitThreshold​

  • Type: number
  • Required: Yes (when enabled is true)
  • Range: 0.1 to 10
  • Description: Percentage profit required before adding to position
  • Example: 1.5 (add when 1.5% in profit)

Pyramiding Examples​

Equal Sizing​

{
"method": "percentage",
"percentage": 2.0,
"pyramiding": {
"enabled": true,
"maxLevels": 3,
"sizingMethod": "equal",
"profitThreshold": 1.0
}
}

With ₹100,000 account:

  • Level 1: ₹2,000 (2%)
  • Level 2: ₹2,000 (2%) - after 1% profit
  • Level 3: ₹2,000 (2%) - after another 1% profit
  • Total: ₹6,000 (6%)

Decreasing Sizing​

{
"method": "percentage",
"percentage": 4.0,
"pyramiding": {
"enabled": true,
"maxLevels": 3,
"sizingMethod": "decreasing",
"profitThreshold": 1.5
}
}

With ₹100,000 account:

  • Level 1: ₹4,000 (4%)
  • Level 2: ₹2,000 (2%) - 50% of level 1
  • Level 3: ₹1,000 (1%) - 50% of level 2
  • Total: ₹7,000 (7%)

Increasing Sizing​

{
"method": "percentage",
"percentage": 2.0,
"pyramiding": {
"enabled": true,
"maxLevels": 3,
"sizingMethod": "increasing",
"profitThreshold": 2.0
}
}

With ₹100,000 account:

  • Level 1: ₹2,000 (2%)
  • Level 2: ₹3,000 (3%) - 1.5x level 1
  • Level 3: ₹4,500 (4.5%) - 1.5x level 2
  • Total: ₹9,500 (9.5%)

Warning: Increasing sizing is aggressive and increases risk significantly.

Complete Examples​

Conservative Risk-Based​

{
"method": "risk_based",
"riskPercentage": 1.0,
"pyramiding": {
"enabled": false
}
}

Moderate with Pyramiding​

{
"method": "percentage",
"percentage": 3.0,
"pyramiding": {
"enabled": true,
"maxLevels": 2,
"sizingMethod": "equal",
"profitThreshold": 1.5
}
}

Aggressive Volatility-Adjusted​

{
"method": "volatility_adjusted",
"atrPeriod": 14,
"atrMultiplier": 1.5,
"pyramiding": {
"enabled": true,
"maxLevels": 3,
"sizingMethod": "decreasing",
"profitThreshold": 2.0
}
}

Kelly Criterion with Conservative Fraction​

{
"method": "kelly_criterion",
"kellyFraction": 0.25,
"pyramiding": {
"enabled": false
}
}

Validation Rules​

General Rules​

  • Exactly one method-specific parameter must be provided
  • If pyramiding is enabled, all pyramiding fields are required
  • Position size must not exceed riskParameters.maxPositionSize

Method-Specific Validation​

  • percentage: Must be between 0.01 and 100
  • fixedQuantity: Must be at least 1
  • fixedAmount: Must be at least 100
  • riskPercentage: Must be between 0.1 and 10
  • atrPeriod: Must be between 5 and 50
  • atrMultiplier: Must be between 0.5 and 5.0
  • kellyFraction: Must be between 0.1 and 1.0

Pyramiding Validation​

  • maxLevels must be between 1 and 10
  • profitThreshold must be between 0.1 and 10
  • sizingMethod must be one of: equal, decreasing, increasing