Add daily target logic and consistency reference line to equity curve
- lib/trading-logic.ts: computeDailyTarget() computes the next trading
day's profit target via two paths:
• No positive days yet → profitTarget × consistency (first day)
• Positive days exist → maxDay / consistency gives the total profit
needed to satisfy the consistency rule; target maxDay when far away,
or the exact remaining amount when close
- Account detail page: display "Next Trading Day Amount" in Objectives card
- Equity curve: add indigo dashed reference line for the consistency target
(maxDay / consistency), labelled top-left to avoid overlapping the amber
profit-target line (top-right)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
645041c600
commit
532c2e2279
@@ -0,0 +1,38 @@
|
||||
/**
|
||||
* Compute the next trading day's profit target for an account.
|
||||
*
|
||||
* Path 1 – No positive trading days yet:
|
||||
* target = profitTarget × consistency
|
||||
*
|
||||
* Path 2 – At least one positive day exists:
|
||||
* maxDay = highest single-day P&L so far
|
||||
* realTarget = maxDay / consistency (the total profit at which maxDay ≤ consistency% of total)
|
||||
* needed = realTarget − totalProfit
|
||||
*
|
||||
* if needed > maxDay → target maxDay (still a long way from the real target; trade a normal day)
|
||||
* else → target needed (close to the real target; aim for exactly what's left)
|
||||
*/
|
||||
export function computeDailyTarget(
|
||||
profitTarget: number,
|
||||
consistency: number,
|
||||
totalProfit: number,
|
||||
dailyPnL: { date: string; pnl: number }[]
|
||||
): { amount: number; path: 'first_day' | 'normal_day' | 'reduced_day' } {
|
||||
const positiveDays = dailyPnL.filter((d) => d.pnl > 0);
|
||||
|
||||
if (positiveDays.length === 0) {
|
||||
return {
|
||||
amount: Math.round(profitTarget * consistency * 100) / 100,
|
||||
path: 'first_day',
|
||||
};
|
||||
}
|
||||
|
||||
const maxDay = Math.max(...positiveDays.map((d) => d.pnl));
|
||||
const realTarget = maxDay / consistency;
|
||||
const needed = realTarget - totalProfit;
|
||||
|
||||
if (needed > maxDay) {
|
||||
return { amount: Math.round(maxDay * 100) / 100, path: 'normal_day' };
|
||||
}
|
||||
return { amount: Math.round(Math.max(0, needed) * 100) / 100, path: 'reduced_day' };
|
||||
}
|
||||
Reference in New Issue
Block a user