xiaohongshu
xiaohongshu
capital-proportional-limits
Use percentage-based capital limits, not hard-coded dollar amounts. Trigger when: (1) trades blocked on small accounts, (2) min_cash_buffer is absolute dollars, (3) capital allocation doesn't scale with account size, (4) fixed dollar thresholds in risk code.
Full skill instructions
| Item | Details |
|---|---|
| Date | 2024-12-24 |
| Goal | Fix capital manager blocking trades with hard-coded dollar amounts |
| Environment | scripts/live_trader.py, alpaca_trading/risk/capital_manager.py |
| Status | Success |
The capital manager was initialized with min_cash_buffer=1000.0 - a fixed dollar amount that:
The 30% safety buffer (percentage-based) already provides proportional protection. The extra $1,000 was redundant and harmful for smaller accounts.
# WRONG: Hard-coded dollar amount
capital_mgr = CapitalManager(
safety_buffer_pct=0.30,
trading_allocation_pct=0.70,
max_position_pct=0.20,
min_cash_buffer=1000.0 # <-- Blocks 20% of $5k account!
)
# CORRECT: Let percentage-based safety buffer handle it
capital_mgr = CapitalManager(
safety_buffer_pct=0.30, # 30% safety buffer (proportional)
trading_allocation_pct=0.70, # 70% available for trading
max_position_pct=0.20, # 20% max per position
# min_cash_buffer defaults to 0.0 - safety buffer is proportional
)
The CapitalManager class is correctly designed with percentage-based defaults:
class CapitalManager:
def __init__(
self,
safety_buffer_pct: float = 0.30, # 30% reserved
trading_allocation_pct: float = 0.70, # 70% for trading
max_position_pct: float = 0.20, # 20% max per position
min_cash_buffer: float = 0.0, # Additional cash buffer (default: none)
min_trade_value: float = 1.0 # Supports fractional shares
):
The min_cash_buffer parameter exists for edge cases but should rarely be used since the percentage-based safety buffer already scales with account size.
| Account Size | Old (with $1,000 buffer) | New (0% buffer) | Improvement |
|---|---|---|---|
| $5,000 | $4,000 available | $5,000 available | +25% |
| $10,000 | $9,000 available | $10,000 available | +11% |
| $50,000 | $49,000 available | $50,000 available | +2% |
| $100,000 | $99,000 available | $100,000 available | +1% |
Note: The 30% safety buffer still applies to all accounts, so actual trading capital is 70% of these values.
| Attempt | Why it Failed | Lesson Learned |
|---|---|---|
| Hard-coded $1,000 min_cash_buffer | Disproportionately hurt small accounts | Use percentage-based limits only |
| Hard-coded $50 in strategies | Same problem at smaller scale | Remove absolute dollar amounts |
| Fixed confidence thresholds | Didn't adapt to volatility regimes | Consider adaptive thresholds |
| Hard-coded stop-loss percentages | Didn't account for asset volatility | Consider asset-specific thresholds |
| Approach | Pros | Cons | When to Use |
|---|---|---|---|
| Percentage-based | Scales with account, fair to all sizes | May allow tiny trades on small accounts | Default - almost always |
| Dollar-based | Prevents dust trades | Unfair to small accounts, doesn't scale | Only for minimum trade value |
These were identified during investigation (not fixed yet):
# In live_trader.py - consider making configurable:
confidence = 0.6 # Default fallback confidence
rl_confidence < 0.4 # Minimum RL confidence threshold
confidence < 0.70 # Extreme volatility threshold
base_breakeven = 0.02 # 2% breakeven stop
base_trailing = 0.05 # 5% trailing stop
# In harmonized.py:
min_cash_buffer = 50.0 # Should also be removed
The existing safety buffer provides strong protection:
# How it works:
conservative_value = account_value - unrealized_profits + unrealized_losses
safety_buffer = conservative_value * 0.30 # 30% reserved
available_capital = conservative_value * 0.70 # 70% for trading
# For a $10,000 account:
# - Safety buffer: $3,000 (never touched)
# - Trading capital: $7,000
# - Max per position: $1,400 (20% of $7,000)
scripts/live_trader.py:
- Line 1751-1756: Removed min_cash_buffer=1000.0
- Added comment explaining proportional protection
alpaca_trading/risk/capital_manager.py: Lines 74-100 (class design)scripts/live_trader.py: Lines 1750-1757 (initialization)xiaohongshu
technical spec
product ux expert
database patterns
Conduct multi-agent task orchestration and workflow coordination.
Initialize project with Conductor artifacts (product definition,
Expert in web animations, transitions, and motion design using Framer Motion and CSS
Creates Mermaid and ASCII diagrams for flowcharts, architecture, ERDs, state machines, mindmaps, and more. Use when user mentions diagram, flowchart, mermaid, ASCII diagram, text diagram, terminal diagram, visualize, C4, mindmap, architecture diagram, sequence diagram, ERD, or needs visual docume...
PostgreSQL bindings for H3 hexagonal grid system. Use when working with H3 cells in Postgres, including spatial indexing, geometry/geography integration, and raster analysis.
Context-Driven Development skill for projects using Conductor. Use this skill when you detect a `conductor/` directory in the project, when working on tasks defined in a `plan.md` file, or when the user asks about tracks, specs, or plans. Automatically applies TDD workflow, tracks task completion...
Display project status, active tracks, and next actions
Official Stakpak application containerization standard operating procedure, a step-by-step guidline to properly dockerize applications. This is a rule book curated by the Stakpak Team.
Generate, edit, and beat-sync AI video with leading models in one workspace.
The world's fastest calendar for remote work
Transform Your Design with AI Designer by ImgCreator.ai
Revolutionizing Video Production with AI-Powered Creativity
Extend an image past the frame and let AI fill the new aspect ratio.
Discover your celebrity doppelgänger with StarByFace!
ChainClarity explains 700+ crypto whitepapers in plain English, with layered summaries, comparisons, research tools, alerts, and a $4.99 Pro plan.
Opus.ai: Revolutionize Your Web Experience