-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug_velocity.js
More file actions
94 lines (81 loc) · 3.87 KB
/
Copy pathdebug_velocity.js
File metadata and controls
94 lines (81 loc) · 3.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
const fs = require('fs');
// Read from example backup if available
const files = fs.readdirSync('examples').filter(f => f.includes('wheelhouse'));
if (files.length === 0) {
console.log('No backup files found');
process.exit(1);
}
const data = JSON.parse(fs.readFileSync('examples/' + files[0], 'utf8'));
const closed = data.closedPositions || [];
// Filter credit trades
const creditTrades = closed.filter(p => {
const type = p.type || '';
return type === 'short_put' || type === 'covered_call' || type === 'buy_write';
});
console.log('Total closed:', closed.length);
console.log('Credit trades:', creditTrades.length);
// Sample first 10
console.log('\nSample trades (first 10):');
creditTrades.slice(0, 10).forEach(p => {
const pnl = p.realizedPnL ?? p.closePnL ?? 0;
const capital = (p.strike || 0) * 100 * (p.contracts || 1);
const days = p.daysHeld || 30;
console.log(` ${p.ticker} ${p.type} $${p.strike}: PnL=$${pnl}, Capital=$${capital}, Days=${days}`);
});
// Calculate total
let totalPnL = 0, totalCapitalDays = 0, totalDays = 0;
let winCount = 0, lossCount = 0, totalWins = 0, totalLosses = 0;
creditTrades.forEach(p => {
const pnl = p.realizedPnL ?? p.closePnL ?? 0;
const capital = p.type === 'buy_write' ? (p.stockPrice || p.strike || 0) * 100 * (p.contracts || 1)
: (p.strike || 0) * 100 * (p.contracts || 1);
const days = p.daysHeld || 30;
totalPnL += pnl;
totalCapitalDays += capital * days;
totalDays += days;
if (pnl >= 0) {
winCount++;
totalWins += pnl;
} else {
lossCount++;
totalLosses += Math.abs(pnl);
}
});
console.log('\n--- TOTALS ---');
console.log('Total PnL:', totalPnL.toFixed(2));
console.log('Total Capital-Days:', totalCapitalDays.toFixed(0));
console.log('Avg Days:', (totalDays / creditTrades.length).toFixed(1));
console.log('Daily yield:', (totalPnL / totalCapitalDays * 100).toFixed(4) + '%');
console.log('Monthly yield:', (totalPnL / totalCapitalDays * 30 * 100).toFixed(2) + '%');
console.log('\n--- WIN/LOSS ---');
console.log('Wins:', winCount, 'Total:', totalWins.toFixed(2));
console.log('Losses:', lossCount, 'Total:', totalLosses.toFixed(2));
console.log('Win Rate:', ((winCount / creditTrades.length) * 100).toFixed(1) + '%');
// Find the biggest losers
console.log('\n--- BIGGEST LOSERS (dragging down yield) ---');
const sorted = [...creditTrades].sort((a, b) => (a.realizedPnL ?? a.closePnL ?? 0) - (b.realizedPnL ?? b.closePnL ?? 0));
sorted.slice(0, 5).forEach(p => {
const pnl = p.realizedPnL ?? p.closePnL ?? 0;
const capital = (p.strike || 0) * 100 * (p.contracts || 1);
console.log(` ${p.ticker} ${p.type} $${p.strike}: PnL=$${pnl}, Capital=$${capital}`);
});
// Check if maybe we should use premium-based yield instead
console.log('\n--- PREMIUM-BASED YIELD (alternative calc) ---');
let totalPremium = 0;
let totalCapital = 0;
creditTrades.forEach(p => {
const premium = (p.premium || 0) * 100 * (p.contracts || 1);
const capital = p.type === 'buy_write' ? (p.stockPrice || p.strike || 0) * 100 * (p.contracts || 1)
: (p.strike || 0) * 100 * (p.contracts || 1);
totalPremium += premium;
totalCapital += capital;
});
const avgCapital = totalCapital / creditTrades.length;
const avgDays = totalDays / creditTrades.length;
const tradesPerMonth = 30 / avgDays;
const monthlyPremium = (totalPremium / creditTrades.length) * tradesPerMonth;
const premiumYield = (monthlyPremium / avgCapital) * 100;
console.log('Avg Premium/trade:', (totalPremium / creditTrades.length).toFixed(2));
console.log('Avg Capital/trade:', avgCapital.toFixed(0));
console.log('Trades per month:', tradesPerMonth.toFixed(1));
console.log('Premium-based monthly yield:', premiumYield.toFixed(2) + '%');