fix: Correct SQL column names and add navigation links

- Fixed tp1Hit/tp2Hit -> tp1Filled/tp2Filled in Runner Performance query
- Fixed atr -> atrAtEntry in ATR vs MFE Correlation and Data Collection queries
- Added Analytics card to homepage with link to /analytics/optimization
- Added Home button to optimization page header
- All 7 analyses now working without SQL errors
This commit is contained in:
mindesbunister
2025-11-23 20:28:33 +01:00
parent 11ae0938ba
commit 1e64e8145b
3 changed files with 51 additions and 14 deletions

View File

@@ -190,10 +190,10 @@ export async function GET() {
const runnerPerformance = await prisma.$queryRaw<any[]>`
SELECT
COUNT(*) as total_trades,
SUM(CASE WHEN "tp1Hit" = true THEN 1 ELSE 0 END) as tp1_hits,
SUM(CASE WHEN "tp2Hit" = true THEN 1 ELSE 0 END) as tp2_hits,
ROUND(100.0 * SUM(CASE WHEN "tp1Hit" = true THEN 1 ELSE 0 END) / COUNT(*)::numeric, 1) as tp1_rate,
ROUND(100.0 * SUM(CASE WHEN "tp2Hit" = true THEN 1 ELSE 0 END) / COUNT(*)::numeric, 1) as tp2_rate,
SUM(CASE WHEN "tp1Filled" = true THEN 1 ELSE 0 END) as tp1_hits,
SUM(CASE WHEN "tp2Filled" = true THEN 1 ELSE 0 END) as tp2_hits,
ROUND(100.0 * SUM(CASE WHEN "tp1Filled" = true THEN 1 ELSE 0 END) / COUNT(*)::numeric, 1) as tp1_rate,
ROUND(100.0 * SUM(CASE WHEN "tp2Filled" = true THEN 1 ELSE 0 END) / COUNT(*)::numeric, 1) as tp2_rate,
ROUND(AVG("maxFavorableExcursion")::numeric, 2) as avg_mfe,
ROUND(AVG("maxAdverseExcursion")::numeric, 2) as avg_mae
FROM "Trade"
@@ -244,9 +244,9 @@ export async function GET() {
const atrCorrelation = await prisma.$queryRaw<any[]>`
SELECT
CASE
WHEN atr < 0.3 THEN '<0.3 (Low Vol)'
WHEN atr < 0.5 THEN '0.3-0.5 (Med Vol)'
WHEN atr < 0.7 THEN '0.5-0.7 (High Vol)'
WHEN "atrAtEntry" < 0.3 THEN '<0.3 (Low Vol)'
WHEN "atrAtEntry" < 0.5 THEN '0.3-0.5 (Med Vol)'
WHEN "atrAtEntry" < 0.7 THEN '0.5-0.7 (High Vol)'
ELSE '0.7+ (Very High Vol)'
END as atr_range,
COUNT(*) as trades,
@@ -255,9 +255,9 @@ export async function GET() {
ROUND(100.0 * SUM(CASE WHEN "realizedPnL" > 0 THEN 1 ELSE 0 END) / COUNT(*)::numeric, 1) as win_rate
FROM "Trade"
WHERE "exitReason" IS NOT NULL
AND atr IS NOT NULL
AND "atrAtEntry" IS NOT NULL
GROUP BY atr_range
ORDER BY MIN(atr)
ORDER BY MIN("atrAtEntry")
`
const formattedData = atrCorrelation.map(row => ({
@@ -356,7 +356,7 @@ export async function GET() {
SELECT
COUNT(*) FILTER (WHERE "exitReason" IS NOT NULL) as completed_trades,
COUNT(*) FILTER (WHERE "signalQualityScore" IS NOT NULL) as with_quality,
COUNT(*) FILTER (WHERE atr IS NOT NULL) as with_atr,
COUNT(*) FILTER (WHERE "atrAtEntry" IS NOT NULL) as with_atr,
COUNT(*) FILTER (WHERE "maxFavorableExcursion" IS NOT NULL) as with_mfe,
COUNT(*) FILTER (WHERE "indicatorVersion" = 'v8') as v8_trades,
(SELECT COUNT(*) FROM "BlockedSignal" WHERE "blockReason" = 'QUALITY_SCORE_TOO_LOW') as blocked_quality