From 591b6abd51401cdf8efbed2a8eacf16b3dcf06d1 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Tue, 25 Aug 2020 16:19:57 +0200 Subject: [PATCH] Bug Fixed --- LowFrequencyTrading/TradingOutput.js | 30 ++++++++++++++++++++++++--- LowFrequencyTrading/TradingProcess.js | 7 ++++++- 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/LowFrequencyTrading/TradingOutput.js b/LowFrequencyTrading/TradingOutput.js index 47bb6ce6b..37b7bad6e 100644 --- a/LowFrequencyTrading/TradingOutput.js +++ b/LowFrequencyTrading/TradingOutput.js @@ -43,10 +43,34 @@ exports.newTradingOutput = function newTradingOutput(bot, logger, tradingEngineM let outputDatasets = bot.processNode.referenceParent.processOutput.outputDatasets let outputDatasetsMap = new Map() - if (bot.FIRST_EXECUTION === true && bot.RESUME === false) { - await initializeOutputs() + if (bot.processingDailyFiles === true) { + /* + For Daily Files, we are going to initialize the outputs at the first execution + if we are not resuming, but also at every following execution except when + we are at the head of the market, because at the head of the market we need to + append more data to the same output files that already exists. + */ + if (bot.FIRST_EXECUTION === true && bot.RESUME === false) { + await initializeOutputs() + } else { + if (bot.simulationState.tradingEngine.current.episode.headOfTheMarket.value === true) { + await readFiles() + } else { + await initializeOutputs() + } + } } else { - await readFiles() + /* + Form Market Files, we are only going to initialize the outputs at the first run + and if we are not resuming execution. Subsequent runs means that we are at the + head of the market. Remember that backtests finishes the session once the reach + the final datetime. + */ + if (bot.FIRST_EXECUTION === true && bot.RESUME === false) { + await initializeOutputs() + } else { + await readFiles() + } } await tradingSimulation.runSimulation( diff --git a/LowFrequencyTrading/TradingProcess.js b/LowFrequencyTrading/TradingProcess.js index 5258f1adc..7e0a2e418 100644 --- a/LowFrequencyTrading/TradingProcess.js +++ b/LowFrequencyTrading/TradingProcess.js @@ -557,7 +557,12 @@ tradingProcessDate ) - bot.FIRST_EXECUTION = false // From here on, all other loops executions wont be the first execution. + /* + From here on, all other loops executions wont be the first execution and also + we will consider that it is not resuming a previous execution as well. + */ + bot.FIRST_EXECUTION = false + bot.RESUME = false } async function writeProcessFiles() {