Nija

NIJA Capital Scaling Framework

Overview

The NIJA Capital Scaling Framework is a self-adjusting compounding engine that automatically scales capital based on:

This framework transforms NIJA into an autonomous capital growth system that adapts to market conditions in real-time.

Components

1. Capital Scaling Engine (bot/capital_scaling_engine.py)

The main orchestrator that integrates three subsystems:

  1. Profit Compounding Engine - Reinvests profits for exponential growth
  2. Drawdown Protection System - Reduces risk during losses
  3. Capital Milestone Manager - Tracks progress and locks in gains

Key Features:

2. Autonomous Scaling Engine (bot/autonomous_scaling_engine.py)

Advanced capital management with autonomous scaling features:

Market Regime Classification:

3. Drawdown Protection System (bot/drawdown_protection_system.py)

Automatically reduces position sizes during losing streaks:

Protection Levels:

Recovery Protocol:

Usage

Basic Setup

from bot.capital_scaling_engine import CapitalScalingEngine, CapitalEngineConfig

# Create config
config = CapitalEngineConfig(
    compounding_strategy="moderate",  # conservative/moderate/aggressive/full_compound
    reinvest_percentage=0.75,
    preserve_percentage=0.25,
    enable_drawdown_protection=True,
    halt_threshold_pct=20.0
)

# Initialize engine
engine = CapitalScalingEngine(
    base_capital=10000.0,
    current_capital=12000.0,
    config=config
)

# Get optimal position size
position_size = engine.get_optimal_position_size(
    available_balance=12000.0
)

Advanced Usage with Autonomous Scaling

from bot.autonomous_scaling_engine import (
    AutonomousScalingEngine,
    AutoScalingConfig,
    MarketRegime
)

# Create advanced config
auto_config = AutoScalingConfig(
    enable_volatility_leverage=True,
    min_leverage=0.5,
    max_leverage=2.0,
    enable_regime_allocation=True,
    enable_risk_adjustment=True,
    target_sharpe_ratio=1.5
)

# Initialize autonomous engine
auto_engine = AutonomousScalingEngine(
    base_capital=10000.0,
    current_capital=12000.0,
    config=auto_config
)

# Update market regime
auto_engine.update_market_regime(MarketRegime.BULL_TRENDING)

# Get optimal position with all adjustments
position_size = auto_engine.get_optimal_position_size(
    available_balance=12000.0,
    expected_return=0.15,  # 15% expected return
    volatility=0.25  # 25% volatility
)

Tracking Capital Growth

# Record profit
engine.record_profit(profit_amount=500.0)

# Record loss
engine.record_loss(loss_amount=-100.0)

# Get current state
state = engine.get_current_state()
print(f"Total capital: ${state['total_capital']:,.2f}")
print(f"Locked profit: ${state['locked_profit']:,.2f}")
print(f"Drawdown: {state['drawdown_pct']:.2f}%")
print(f"Protection level: {state['protection_level']}")

# Generate report
report = engine.generate_report()

Configuration Options

Compounding Strategies

  1. Conservative (60% reinvest, 40% preserve)
    • Best for: Risk-averse traders
    • Growth rate: Moderate
    • Capital preservation: High
  2. Moderate (75% reinvest, 25% preserve)
    • Best for: Balanced approach
    • Growth rate: Good
    • Capital preservation: Medium
  3. Aggressive (90% reinvest, 10% preserve)
    • Best for: Growth-focused traders
    • Growth rate: High
    • Capital preservation: Low
  4. Full Compound (100% reinvest)
    • Best for: Maximum growth
    • Growth rate: Highest
    • Capital preservation: Minimal

Drawdown Thresholds

Customize drawdown protection levels:

from bot.drawdown_protection_system import DrawdownConfig

drawdown_config = DrawdownConfig(
    caution_threshold_pct=5.0,
    warning_threshold_pct=10.0,
    danger_threshold_pct=15.0,
    halt_threshold_pct=20.0,
    caution_position_multiplier=0.75,
    warning_position_multiplier=0.50,
    danger_position_multiplier=0.25
)

Volatility Adaptation

Configure volatility-based position sizing:

auto_config = AutoScalingConfig(
    enable_volatility_leverage=True,
    min_leverage=0.5,  # Minimum 50% of base size
    max_leverage=2.0,  # Maximum 200% of base size
    volatility_leverage_sensitivity=0.8  # Sensitivity to volatility changes
)

Regime-Based Allocation

Capital allocation adjusts based on market regime:

regime_allocations = {
    MarketRegime.BULL_TRENDING: 1.2,    # 120% allocation in bull markets
    MarketRegime.BEAR_TRENDING: 0.6,    # 60% allocation in bear markets
    MarketRegime.RANGING: 0.8,          # 80% allocation in ranging markets
    MarketRegime.VOLATILE: 0.7,         # 70% allocation in volatile markets
    MarketRegime.CRISIS: 0.3            # 30% allocation in crisis
}

auto_config = AutoScalingConfig(
    enable_regime_allocation=True,
    regime_allocations=regime_allocations
)

Integration Example

Complete integration with trading strategy:

from bot.capital_scaling_engine import get_capital_engine
from bot.autonomous_scaling_engine import get_autonomous_engine

# Initialize engines
capital_engine = get_capital_engine(
    base_capital=10000.0,
    current_capital=10000.0
)

auto_engine = get_autonomous_engine(
    base_capital=10000.0,
    current_capital=10000.0
)

# In your trading loop
def execute_trade(symbol, expected_return, volatility):
    # Get available balance
    balance = get_account_balance()

    # Calculate optimal position size
    position_size = auto_engine.get_optimal_position_size(
        available_balance=balance,
        expected_return=expected_return,
        volatility=volatility
    )

    # Execute trade
    trade_result = place_order(symbol, position_size)

    # Record result
    if trade_result['pnl'] > 0:
        capital_engine.record_profit(trade_result['pnl'])
    else:
        capital_engine.record_loss(trade_result['pnl'])

    # Check if trading should halt
    if capital_engine.should_halt_trading():
        print("⚠️ Trading halted due to drawdown")
        return False

    return True

Performance Impact

Expected Improvements:

Best Practices

  1. Start Conservative: Begin with moderate or conservative compounding
  2. Monitor Drawdowns: Pay attention to protection level changes
  3. Adapt to Regimes: Allow regime detection to guide allocation
  4. Lock Profits: Enable milestone-based profit locking
  5. Review Regularly: Check capital reports weekly

Troubleshooting

Position Sizes Too Small

Frequent Halts

Not Compounding

API Reference

See code documentation in:

Future Enhancements