small fixes for backtest
This commit is contained in:
parent
6df32dc18b
commit
6cf3179092
16 changed files with 2180 additions and 16 deletions
|
|
@ -413,11 +413,11 @@ export class BacktestEngine extends EventEmitter {
|
|||
let trendDuration = 0;
|
||||
|
||||
while (currentTime <= endTime) {
|
||||
// Every 20-50 days, change trend
|
||||
// Every 10-30 days, change trend (more frequent for testing)
|
||||
if (trendDuration <= 0) {
|
||||
trend = Math.random() > 0.5 ? 1 : -1;
|
||||
trendStrength = 0.002 + Math.random() * 0.003; // 0.2% to 0.5% daily trend
|
||||
trendDuration = Math.floor(20 + Math.random() * 30);
|
||||
trendStrength = 0.003 + Math.random() * 0.005; // 0.3% to 0.8% daily trend
|
||||
trendDuration = Math.floor(10 + Math.random() * 20); // Shorter trends
|
||||
}
|
||||
|
||||
// Generate price movement with trend and noise
|
||||
|
|
|
|||
|
|
@ -11,11 +11,11 @@ export class SimpleMovingAverageCrossover extends BaseStrategy {
|
|||
private totalSignals = 0;
|
||||
|
||||
// Strategy parameters
|
||||
private readonly FAST_PERIOD = 10;
|
||||
private readonly SLOW_PERIOD = 20;
|
||||
private readonly FAST_PERIOD = 5; // Changed from 10 to generate more signals
|
||||
private readonly SLOW_PERIOD = 15; // Changed from 20 to generate more signals
|
||||
private readonly POSITION_SIZE = 0.1; // 10% of capital per position
|
||||
private readonly MIN_HOLDING_BARS = 1; // Minimum bars to hold position
|
||||
private readonly DEBUG_INTERVAL = 20; // Log every N bars for debugging
|
||||
private readonly DEBUG_INTERVAL = 10; // Log every N bars for debugging
|
||||
|
||||
constructor(config: any, modeManager?: any, executionService?: any) {
|
||||
super(config, modeManager, executionService);
|
||||
|
|
@ -119,8 +119,8 @@ export class SimpleMovingAverageCrossover extends BaseStrategy {
|
|||
logger.info(` Current position: ${currentPosition} shares`);
|
||||
|
||||
// For golden cross, we want to be long
|
||||
// If we're short, we need to close the short first
|
||||
if (currentPosition < 0) {
|
||||
// Close short position first
|
||||
logger.info(` Closing short position of ${Math.abs(currentPosition)} shares`);
|
||||
const signal: Signal = {
|
||||
type: 'buy',
|
||||
|
|
@ -206,10 +206,7 @@ export class SimpleMovingAverageCrossover extends BaseStrategy {
|
|||
logger.info(`👉 Total signals generated: ${this.totalSignals}`);
|
||||
return signal;
|
||||
} else if (currentPosition === 0) {
|
||||
// Optional: Open short position (comment out if long-only)
|
||||
logger.info(` No position, staying flat (long-only strategy)`);
|
||||
// Uncomment below for long/short strategy:
|
||||
/*
|
||||
// Open short position for long/short strategy
|
||||
const positionSize = this.calculatePositionSize(currentPrice);
|
||||
logger.info(` Opening short position: ${positionSize} shares`);
|
||||
|
||||
|
|
@ -233,7 +230,6 @@ export class SimpleMovingAverageCrossover extends BaseStrategy {
|
|||
this.totalSignals++;
|
||||
logger.info(`👉 Total signals generated: ${this.totalSignals}`);
|
||||
return signal;
|
||||
*/
|
||||
} else {
|
||||
logger.info(` ⚠️ Already short, skipping sell signal`);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue