feedback

Workspace Structure

Understand every file and folder in your BlaveClaw workspace.

Directory Overview

workspace/
├── strategies/          # your strategies
├── examples/            # reference implementations
├── lib/                 # shared library
├── manager/             # portfolio management system
├── cache/               # API data cache (auto-generated)
├── references/          # guides for strategy code & deployment
└── AGENTS.md            # bot behavior rules

strategies/

Each strategy lives in its own subfolder. The bot runs strategy.py on a cron schedule and writes the output files automatically.

strategies/
└── my_strategy/
    ├── strategy.py      # strategy logic
    ├── scan.py          # parameter scan (optional)
    ├── stats.json       # backtest results + daily returns
    ├── state.json       # live position state
    ├── pnl.png          # equity curve chart
    └── orders.jsonl     # order log

lib/

All shared utilities live in lib/. Import from here — never duplicate code in strategy files.

FilePurpose
runner.pyUnified backtest & live runner (Type A and C)
data.pyAll data fetchers — kline, alpha indicators, Taiwan stocks, futures
execute.pyLive state management: load/save/update position, order log
pnl.pyWrite daily returns to stats.json; load all strategies for manager
portfolio.pyAggregate target positions, compute order diff, reconcile
strategy.pyVol targeting helpers: add_realized_vol, apply_vol_scaling
analysis.pyPnL charts, regime analysis, slippage, random B&H benchmark
param_scan.py2D parameter scan: percentile_thresholds, scan_grid, find_plateau, plot_heatmap
validation.pyMonte Carlo Permutation Test (mcpt) for statistical significance
notify.pyTelegram sender: make_sender(), send_text(), send_photo()

manager/

The manager/ folder handles multi-strategy portfolio optimization and order reconciliation. Do not delete any file here when removing individual strategies.

FilePurpose
manager.pyReads all strategies' stats.json, finds weights that maximize portfolio slope/std, writes optimal weights + leverage to portfolio_config.json.
Run: python3 manager/manager.py --target-vol 0.30
reconciler.pyPolls every 5 s; detects when a strategy's state.json changes, then computes target positions (with leverage) and places orders on the exchange.
Run: python3 manager/reconciler.py
portfolio_config.jsonWritten by manager.py. Contains weights, leverage, and target/actual volatility.
Leverage: manager.py computes leverage = target_vol / ann_volatility so the portfolio's realized risk matches your target (e.g. 30% annual vol). The reconciler multiplies all position sizes by this factor when placing orders.

Data Flow

strategy.py ──► state.json ──────────┐
   (cron)       stats.json           ├──► reconciler.py ──► exchange
manager.py ──► portfolio_config.json ┘

The reconciler needs both sources to compute order size: target = account_value × leverage × weight × position