Skip to content
SlashClone
Made by@qtrader

Position sizer

@qtrader/position-sizer

Work out how many shares to buy before you click. Fixed-fractional, ATR (volatility) based, and capped fractional-Kelly sizing, plus a portfolio heat check that totals the risk across open positions and tells you if a new trade fits. Not financial advice.

SkillTradingv1.0.0 (latest)Tested
Activity
New: be the first to try it
  1. 1{
  2. 2 "name": "position-sizer",
  3. 3 "owner": "qtrader",
  4. 4 "version": "1.0.0",
  5. 5 "type": "skill",
  6. 6 "description": "Work out how many shares to buy before you click. Fixed-fractional, ATR (volatility) based, and capped fractional-Kelly sizing, plus a portfolio heat check that totals the risk across open positions and tells you if a new trade fits. Not financial advice.",
  7. 7 "category": "trading",
  8. 8 "license": "MIT",
  9. 9 "compat": ["claude-code"],
  10. 10 "permissions": {
  11. 11 "shell": ["node scripts/size.mjs", "node scripts/selftest.mjs"],
  12. 12 "files": { "read": ["./data/**"], "write": ["./out/**"] }
  13. 13 },
  14. 14 "tests": {
  15. 15 "cases": [
  16. 16 {
  17. 17 "name": "sizing and heat match the hand calculations",
  18. 18 "inputs": {},
  19. 19 "checks": [{ "type": "command_exits_zero", "command": "node scripts/selftest.mjs" }]
  20. 20 },
  21. 21 {
  22. 22 "name": "fixed-fractional sizing writes JSON",
  23. 23 "inputs": {},
  24. 24 "checks": [
  25. 25 {
  26. 26 "type": "command_exits_zero",
  27. 27 "command": "node scripts/size.mjs fixed --equity 50000 --risk-pct 1 --entry 100 --stop 95 --out out/fixed.json"
  28. 28 },
  29. 29 {
  30. 30 "type": "output_matches_schema",
  31. 31 "path": "out/fixed.json",
  32. 32 "schema": {
  33. 33 "type": "object",
  34. 34 "required": ["method", "side", "shares", "dollar_risk"],
  35. 35 "properties": { "side": { "const": "long" }, "shares": { "const": 100 }, "dollar_risk": { "const": 500 } }
  36. 36 }
  37. 37 }
  38. 38 ]
  39. 39 },
  40. 40 {
  41. 41 "name": "heat check flags a missing stop and an oversized add",
  42. 42 "inputs": {
  43. 43 "data/positions.csv": "symbol,side,qty,entry,stop,price\nAAA,long,100,50,46,52\nBBB,long,200,30,31,35\nCCC,short,50,80,84,\nDDD,long,150,20,,\nEEE,long,300,40,37,41\n"
  44. 44 },
  45. 45 "checks": [
  46. 46 {
  47. 47 "type": "command_exits_zero",
  48. 48 "command": "node scripts/size.mjs heat --equity 100000 --positions data/positions.csv --add FFF,long,120,25,23 --out out/heat.json"
  49. 49 },
  50. 50 {
  51. 51 "type": "output_matches_schema",
  52. 52 "path": "out/heat.json",
  53. 53 "schema": {
  54. 54 "type": "object",
  55. 55 "required": ["status", "total_risk", "positions", "proposed"],
  56. 56 "properties": {
  57. 57 "status": { "const": "OK" },
  58. 58 "total_risk": { "const": 5800 },
  59. 59 "positions": { "type": "array", "minItems": 5, "maxItems": 5 },
  60. 60 "proposed": { "type": "object", "properties": { "fits": { "const": false }, "max_qty_that_fits": { "const": 100 } } }
  61. 61 }
  62. 62 }
  63. 63 },
  64. 64 { "type": "file_contains", "path": "out/heat.json", "text": "NO STOP: full value at risk" }
  65. 65 ]
  66. 66 }
  67. 67 ]
  68. 68 }