running prettier for cleanup
This commit is contained in:
parent
fe7733aeb5
commit
d85cd58acd
151 changed files with 29158 additions and 27966 deletions
|
|
@ -1,75 +1,75 @@
|
|||
/**
|
||||
* Event-Driven Backtesting Mode
|
||||
* Processes data point by point with realistic order execution
|
||||
*/
|
||||
import { ExecutionMode, Order, OrderResult, MarketData } from '../../framework/execution-mode';
|
||||
|
||||
export interface BacktestConfig {
|
||||
startDate: Date;
|
||||
endDate: Date;
|
||||
initialCapital: number;
|
||||
slippageModel?: string;
|
||||
commissionModel?: string;
|
||||
}
|
||||
|
||||
export class EventMode extends ExecutionMode {
|
||||
name = 'event-driven';
|
||||
private simulationTime: Date;
|
||||
private historicalData: Map<string, MarketData[]> = new Map();
|
||||
|
||||
constructor(private config: BacktestConfig) {
|
||||
super();
|
||||
this.simulationTime = config.startDate;
|
||||
}
|
||||
|
||||
async executeOrder(order: Order): Promise<OrderResult> {
|
||||
this.logger.debug('Simulating order execution', {
|
||||
orderId: order.id,
|
||||
simulationTime: this.simulationTime
|
||||
});
|
||||
|
||||
// TODO: Implement realistic order simulation
|
||||
// Include slippage, commission, market impact
|
||||
const simulatedResult: OrderResult = {
|
||||
orderId: order.id,
|
||||
symbol: order.symbol,
|
||||
executedQuantity: order.quantity,
|
||||
executedPrice: 100, // TODO: Get realistic price
|
||||
commission: 1.0, // TODO: Calculate based on commission model
|
||||
slippage: 0.01, // TODO: Calculate based on slippage model
|
||||
timestamp: this.simulationTime,
|
||||
executionTime: 50 // ms
|
||||
};
|
||||
|
||||
return simulatedResult;
|
||||
}
|
||||
|
||||
getCurrentTime(): Date {
|
||||
return this.simulationTime;
|
||||
}
|
||||
|
||||
async getMarketData(symbol: string): Promise<MarketData> {
|
||||
const data = this.historicalData.get(symbol) || [];
|
||||
const currentData = data.find(d => d.timestamp <= this.simulationTime);
|
||||
|
||||
if (!currentData) {
|
||||
throw new Error(`No market data available for ${symbol} at ${this.simulationTime}`);
|
||||
}
|
||||
|
||||
return currentData;
|
||||
}
|
||||
|
||||
async publishEvent(event: string, data: any): Promise<void> {
|
||||
// In-memory event bus for simulation
|
||||
this.logger.debug('Publishing simulation event', { event, data });
|
||||
}
|
||||
|
||||
// Simulation control methods
|
||||
advanceTime(newTime: Date): void {
|
||||
this.simulationTime = newTime;
|
||||
}
|
||||
|
||||
loadHistoricalData(symbol: string, data: MarketData[]): void {
|
||||
this.historicalData.set(symbol, data);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Event-Driven Backtesting Mode
|
||||
* Processes data point by point with realistic order execution
|
||||
*/
|
||||
import { ExecutionMode, MarketData, Order, OrderResult } from '../../framework/execution-mode';
|
||||
|
||||
export interface BacktestConfig {
|
||||
startDate: Date;
|
||||
endDate: Date;
|
||||
initialCapital: number;
|
||||
slippageModel?: string;
|
||||
commissionModel?: string;
|
||||
}
|
||||
|
||||
export class EventMode extends ExecutionMode {
|
||||
name = 'event-driven';
|
||||
private simulationTime: Date;
|
||||
private historicalData: Map<string, MarketData[]> = new Map();
|
||||
|
||||
constructor(private config: BacktestConfig) {
|
||||
super();
|
||||
this.simulationTime = config.startDate;
|
||||
}
|
||||
|
||||
async executeOrder(order: Order): Promise<OrderResult> {
|
||||
this.logger.debug('Simulating order execution', {
|
||||
orderId: order.id,
|
||||
simulationTime: this.simulationTime,
|
||||
});
|
||||
|
||||
// TODO: Implement realistic order simulation
|
||||
// Include slippage, commission, market impact
|
||||
const simulatedResult: OrderResult = {
|
||||
orderId: order.id,
|
||||
symbol: order.symbol,
|
||||
executedQuantity: order.quantity,
|
||||
executedPrice: 100, // TODO: Get realistic price
|
||||
commission: 1.0, // TODO: Calculate based on commission model
|
||||
slippage: 0.01, // TODO: Calculate based on slippage model
|
||||
timestamp: this.simulationTime,
|
||||
executionTime: 50, // ms
|
||||
};
|
||||
|
||||
return simulatedResult;
|
||||
}
|
||||
|
||||
getCurrentTime(): Date {
|
||||
return this.simulationTime;
|
||||
}
|
||||
|
||||
async getMarketData(symbol: string): Promise<MarketData> {
|
||||
const data = this.historicalData.get(symbol) || [];
|
||||
const currentData = data.find(d => d.timestamp <= this.simulationTime);
|
||||
|
||||
if (!currentData) {
|
||||
throw new Error(`No market data available for ${symbol} at ${this.simulationTime}`);
|
||||
}
|
||||
|
||||
return currentData;
|
||||
}
|
||||
|
||||
async publishEvent(event: string, data: any): Promise<void> {
|
||||
// In-memory event bus for simulation
|
||||
this.logger.debug('Publishing simulation event', { event, data });
|
||||
}
|
||||
|
||||
// Simulation control methods
|
||||
advanceTime(newTime: Date): void {
|
||||
this.simulationTime = newTime;
|
||||
}
|
||||
|
||||
loadHistoricalData(symbol: string, data: MarketData[]): void {
|
||||
this.historicalData.set(symbol, data);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue