work on backtest engine
This commit is contained in:
parent
3a7557c8f4
commit
b8cefdb8cd
11 changed files with 1525 additions and 318 deletions
|
|
@ -150,20 +150,27 @@ async function testMeanReversionBacktest() {
|
|||
// Show first few trades
|
||||
console.log(` - First 3 trades:`);
|
||||
trades.slice(0, 3).forEach((trade, idx) => {
|
||||
console.log(` ${idx + 1}. ${trade.side} - Price: $${trade.price.toFixed(2)}, Quantity: ${trade.quantity}${trade.pnl ? `, PnL: $${trade.pnl.toFixed(2)}` : ''}`);
|
||||
console.log(` ${idx + 1}. Trade:`, JSON.stringify(trade, null, 2));
|
||||
});
|
||||
});
|
||||
|
||||
// Check position distribution
|
||||
const allDurations = result.trades.map(t => t.duration / 86400); // Convert to days
|
||||
const avgDuration = allDurations.reduce((a, b) => a + b, 0) / allDurations.length;
|
||||
const minDuration = Math.min(...allDurations);
|
||||
const maxDuration = Math.max(...allDurations);
|
||||
// Analyze trade pairing
|
||||
console.log('\n=== Trade Pairing Analysis ===');
|
||||
console.log(`Total fills: ${result.trades.length}`);
|
||||
console.log(`Expected pairs: ${result.trades.length / 2}`);
|
||||
|
||||
console.log('\n=== Duration Analysis ===');
|
||||
console.log(`Average trade duration: ${avgDuration.toFixed(1)} days`);
|
||||
console.log(`Min duration: ${minDuration.toFixed(1)} days`);
|
||||
console.log(`Max duration: ${maxDuration.toFixed(1)} days`);
|
||||
// Look for patterns that show instant buy/sell
|
||||
let instantPairs = 0;
|
||||
for (let i = 1; i < result.trades.length; i++) {
|
||||
const prev = result.trades[i-1];
|
||||
const curr = result.trades[i];
|
||||
if (prev.symbol === curr.symbol &&
|
||||
prev.side === 'buy' && curr.side === 'sell' &&
|
||||
new Date(curr.timestamp).getTime() - new Date(prev.timestamp).getTime() < 86400000) {
|
||||
instantPairs++;
|
||||
}
|
||||
}
|
||||
console.log(`Instant buy/sell pairs (< 1 day): ${instantPairs}`);
|
||||
|
||||
// Final positions
|
||||
console.log('\n=== Final Positions ===');
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue