UNPKG

@showr/core

Version:
60 lines (59 loc) 1.77 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.BacktestReport = void 0; /** * Creates a back-test report. */ class BacktestReport { _currentCapital; profit; loss; numberOfTrades; initialCapital; finalCapital; returns; /** * Defines the initial capital for the back-test. * @param initialCapital - Initial capital for the back-test. */ constructor(initialCapital) { this.profit = 0; this.loss = 0; this.numberOfTrades = 0; this.initialCapital = initialCapital; this.finalCapital = initialCapital; this.returns = 0; this._currentCapital = initialCapital; } updateCapital(value) { this.finalCapital += value; } updateTotals() { this.returns = ((this.finalCapital - this.initialCapital) * 100) / this.initialCapital; this.numberOfTrades += 1; } /** * Updates the capital according to the traded value after executing the entry position. * @param tradedValue - Traded value at the time. */ markEntry(tradedValue) { this.updateCapital(-tradedValue); } /** * Updates the capital according to the traded value after executing the exit position. * @param tradedValue - Traded value at the time. */ markExit(tradedValue) { this.updateCapital(tradedValue); if (this._currentCapital > this.finalCapital) { this.loss += this._currentCapital - this.finalCapital; } else { this.profit += this.finalCapital - this._currentCapital; } this._currentCapital = this.finalCapital; this.updateTotals(); } } exports.BacktestReport = BacktestReport;