add position-size calculator to the recommendation panel
Deploy / lint (push) Successful in 5s
Deploy / test (push) Successful in 34s
Deploy / deploy (push) Successful in 23s

Risk-based sizing on each setup card: shares = floor((account × risk%) /
|entry − stop|), with position value and dollars-at-risk. Account size and
per-trade risk % are editable inline and persisted in localStorage. Flags when
a position would exceed the account (needs margin). Frontend-only.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-06-15 11:26:55 +02:00
co-authored by Claude Opus 4.8
parent ff48e4a3ff
commit 1951531453
4 changed files with 144 additions and 6 deletions
+37
View File
@@ -0,0 +1,37 @@
import { useCallback, useEffect, useState } from 'react';
export interface RiskSettings {
accountSize: number;
riskPct: number;
}
const STORAGE_KEY = 'risk-settings';
const DEFAULTS: RiskSettings = { accountSize: 10000, riskPct: 1 };
/** Account size + per-trade risk %, persisted in localStorage (per browser). */
export function useRiskSettings() {
const [settings, setSettings] = useState<RiskSettings>(() => {
try {
const raw = localStorage.getItem(STORAGE_KEY);
if (raw) return { ...DEFAULTS, ...JSON.parse(raw) };
} catch {
/* ignore malformed storage */
}
return DEFAULTS;
});
useEffect(() => {
try {
localStorage.setItem(STORAGE_KEY, JSON.stringify(settings));
} catch {
/* ignore quota/availability errors */
}
}, [settings]);
const update = useCallback(
(patch: Partial<RiskSettings>) => setSettings((s) => ({ ...s, ...patch })),
[],
);
return { settings, update };
}