time constants implemented as global file
This commit is contained in:
1 parent
658dc4714a
commit
09f043fb51
13 files changed
+44
-33
No files matched your search
@@ -337,6 +337,12 @@
|
||||
"propertyName": "standardResponses",
|
||||
"functionName": "newSuperalgosGlobalsStandardResponses",
|
||||
"fileName": "StandardResponses.js"
|
||||
},
|
||||
{
|
||||
"name": "Time Constants",
|
||||
"propertyName": "timeConstants",
|
||||
"functionName": "newSuperalgosGlobalsTimeConstants",
|
||||
"fileName": "TimeConstants.js"
|
||||
}
|
||||
],
|
||||
"functionLibraries": [
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
exports.newSuperalgosGlobalsTimeConstants = function () {
|
||||
/* Callbacks default responses. */
|
||||
let thisObject = {
|
||||
ONE_YEAR_IN_MILISECONDS: 365 * 24 * 60 * 60 * 1000,
|
||||
ONE_DAY_IN_MILISECONDS: 24 * 60 * 60 * 1000,
|
||||
ONE_MIN_IN_MILISECONDS: 60 * 1000
|
||||
}
|
||||
|
||||
return thisObject
|
||||
}
|
||||
@@ -220,7 +220,7 @@
|
||||
|
||||
let system = { // These are the available system variables to be used in User Code and Formulas
|
||||
timeFrame: timeFrame,
|
||||
ONE_DAY_IN_MILISECONDS: global.ONE_DAY_IN_MILISECONDS
|
||||
ONE_DAY_IN_MILISECONDS: TS.projects.superalgos.globals.timeConstants.ONE_DAY_IN_MILISECONDS
|
||||
}
|
||||
let variable = {} // This is the structure where the user will define its own variables that will be shared across different code blocks and formulas.
|
||||
let results = []
|
||||
@@ -311,8 +311,8 @@
|
||||
let yesterday = {}
|
||||
let system = { // These are the available system variables to be used in User Code and Formulas
|
||||
timeFrame: timeFrame,
|
||||
ONE_DAY_IN_MILISECONDS: global.ONE_DAY_IN_MILISECONDS,
|
||||
ONE_MIN_IN_MILISECONDS: global.ONE_MIN_IN_MILISECONDS
|
||||
ONE_DAY_IN_MILISECONDS: TS.projects.superalgos.globals.timeConstants.ONE_DAY_IN_MILISECONDS,
|
||||
ONE_MIN_IN_MILISECONDS: TS.projects.superalgos.globals.timeConstants.ONE_MIN_IN_MILISECONDS
|
||||
}
|
||||
let variable = {} // This is the structure where the user will define its own variables that will be shared across different code blocks and formulas.
|
||||
let results = []
|
||||
@@ -361,7 +361,7 @@
|
||||
|
||||
if (processingDailyFiles) {
|
||||
/* Initialization of Last Instance */
|
||||
lastInstantOfTheDay = currentDay.valueOf() + global.ONE_DAY_IN_MILISECONDS - 1;
|
||||
lastInstantOfTheDay = currentDay.valueOf() + TS.projects.superalgos.globals.timeConstants.ONE_DAY_IN_MILISECONDS - 1;
|
||||
|
||||
if (interExecutionMemory[productName] === undefined) {
|
||||
/* The first time the intialization variables goes to the Inter Execution Memory. */
|
||||
@@ -469,7 +469,7 @@
|
||||
at the next day, in whole, even if it starts in the previous day.
|
||||
*/
|
||||
|
||||
let lastInstantOdDay = currentDay.valueOf() + global.ONE_DAY_IN_MILISECONDS - 1;
|
||||
let lastInstantOdDay = currentDay.valueOf() + TS.projects.superalgos.globals.timeConstants.ONE_DAY_IN_MILISECONDS - 1;
|
||||
|
||||
if (record.end < currentDay.valueOf() - 1) { continue; }
|
||||
if (record.end === lastInstantOdDay) { continue; }
|
||||
|
||||
+5
-10
@@ -11,13 +11,8 @@ exports.newGlobals = function newGlobals() {
|
||||
/* This is the Execution Datetime */
|
||||
|
||||
global.EXECUTION_DATETIME = new Date();
|
||||
|
||||
|
||||
global.ROOT_DIR = './';
|
||||
|
||||
global.ONE_YEAR_IN_MILISECONDS = 365 * 24 * 60 * 60 * 1000
|
||||
global.ONE_DAY_IN_MILISECONDS = 24 * 60 * 60 * 1000
|
||||
global.ONE_MIN_IN_MILISECONDS = 60 * 1000
|
||||
global.LOGGER_MAP = new Map() // We will put all the loggers in a map, so that we can eventually finalize them.
|
||||
global.SESSION_MAP = new Map() // We will put all the sessions in a map, so that we can eventually finalize them.
|
||||
|
||||
@@ -302,9 +297,9 @@ exports.newGlobals = function newGlobals() {
|
||||
global.STOP_TASK_GRACEFULLY = false;
|
||||
|
||||
global.GET_PERCENTAGE = function (fromDate, currentDate, lastDate) {
|
||||
let fromDays = Math.trunc(fromDate.valueOf() / global.ONE_DAY_IN_MILISECONDS)
|
||||
let currentDays = Math.trunc(currentDate.valueOf() / global.ONE_DAY_IN_MILISECONDS)
|
||||
let lastDays = Math.trunc(lastDate.valueOf() / global.ONE_DAY_IN_MILISECONDS)
|
||||
let fromDays = Math.trunc(fromDate.valueOf() / TS.projects.superalgos.globals.timeConstants.ONE_DAY_IN_MILISECONDS)
|
||||
let currentDays = Math.trunc(currentDate.valueOf() / TS.projects.superalgos.globals.timeConstants.ONE_DAY_IN_MILISECONDS)
|
||||
let lastDays = Math.trunc(lastDate.valueOf() / TS.projects.superalgos.globals.timeConstants.ONE_DAY_IN_MILISECONDS)
|
||||
let percentage = (currentDays - fromDays) * 100 / (lastDays - fromDays)
|
||||
if ((lastDays - fromDays) === 0) {
|
||||
percentage = 100
|
||||
@@ -313,8 +308,8 @@ exports.newGlobals = function newGlobals() {
|
||||
}
|
||||
|
||||
global.GET_EQUAL_DATES = function (date1, date2) {
|
||||
let day1Days = Math.trunc(date1.valueOf() / global.ONE_DAY_IN_MILISECONDS)
|
||||
let day2Days = Math.trunc(date2.valueOf() / global.ONE_DAY_IN_MILISECONDS)
|
||||
let day1Days = Math.trunc(date1.valueOf() / TS.projects.superalgos.globals.timeConstants.ONE_DAY_IN_MILISECONDS)
|
||||
let day2Days = Math.trunc(date2.valueOf() / TS.projects.superalgos.globals.timeConstants.ONE_DAY_IN_MILISECONDS)
|
||||
|
||||
if (day1Days === day2Days) {
|
||||
return true
|
||||
|
||||
@@ -196,7 +196,7 @@ exports.newLearningSession = function newLearningSession(bot, parentLogger) {
|
||||
type: 'Time Range',
|
||||
config: {
|
||||
initialDatetime: (new Date()).valueOf(),
|
||||
finalDatetime: (new Date()).valueOf() + global.ONE_YEAR_IN_MILISECONDS
|
||||
finalDatetime: (new Date()).valueOf() + TS.projects.superalgos.globals.timeConstants.ONE_YEAR_IN_MILISECONDS
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@@ -219,8 +219,8 @@ exports.newLearningSession = function newLearningSession(bot, parentLogger) {
|
||||
|
||||
/* Session Type Forced Values */
|
||||
let today = (new Date()).valueOf()
|
||||
let aYearAgo = today - global.ONE_YEAR_IN_MILISECONDS
|
||||
let aYearFromNow = today + global.ONE_YEAR_IN_MILISECONDS
|
||||
let aYearAgo = today - TS.projects.superalgos.globals.timeConstants.ONE_YEAR_IN_MILISECONDS
|
||||
let aYearFromNow = today + TS.projects.superalgos.globals.timeConstants.ONE_YEAR_IN_MILISECONDS
|
||||
switch (bot.LEARNING_SESSION.type) {
|
||||
case 'Backtesting Session': {
|
||||
useDefaultDatetimes(aYearAgo, today)
|
||||
|
||||
@@ -113,7 +113,7 @@ exports.newTradingEpisode = function newTradingEpisode(bot, logger, tradingEngin
|
||||
tradingEngine.current.episode.episodeStatistics.days.value =
|
||||
tradingEngine.current.episode.episodeCounters.periods.value *
|
||||
sessionParameters.timeFrame.config.value /
|
||||
global.ONE_DAY_IN_MILISECONDS
|
||||
TS.projects.superalgos.globals.timeConstants.ONE_DAY_IN_MILISECONDS
|
||||
}
|
||||
|
||||
function cycleBasedStatistics() {
|
||||
|
||||
@@ -1036,7 +1036,7 @@ exports.newTradingOrders = function newTradingOrders(bot, logger, tradingEngineM
|
||||
}
|
||||
|
||||
function updateStatistics(tradingEngineOrder) {
|
||||
tradingEngineOrder.orderStatistics.days.value = tradingEngineOrder.orderCounters.periods.value * sessionParameters.timeFrame.config.value / global.ONE_DAY_IN_MILISECONDS
|
||||
tradingEngineOrder.orderStatistics.days.value = tradingEngineOrder.orderCounters.periods.value * sessionParameters.timeFrame.config.value / TS.projects.superalgos.globals.timeConstants.ONE_DAY_IN_MILISECONDS
|
||||
tradingEngineOrder.orderStatistics.days.value = global.PRECISE(tradingEngineOrder.orderStatistics.days.value, 10)
|
||||
}
|
||||
|
||||
|
||||
@@ -411,7 +411,7 @@ exports.newTradingPosition = function newTradingPosition(bot, logger, tradingEng
|
||||
/* Days Calculation */
|
||||
tradingEngine.current.position.positionStatistics.days.value =
|
||||
tradingEngine.current.position.positionCounters.periods.value *
|
||||
sessionParameters.timeFrame.config.value / global.ONE_DAY_IN_MILISECONDS
|
||||
sessionParameters.timeFrame.config.value / TS.projects.superalgos.globals.timeConstants.ONE_DAY_IN_MILISECONDS
|
||||
|
||||
tradingEngine.current.position.positionStatistics.days.value = global.PRECISE(tradingEngine.current.position.positionStatistics.days.value, 10)
|
||||
}
|
||||
|
||||
@@ -648,7 +648,7 @@
|
||||
async function writeDataRange(productCodeName) {
|
||||
let dataRange = {
|
||||
begin: contextVariables.dateBeginOfMarket.valueOf(),
|
||||
end: tradingProcessDate.valueOf() + global.ONE_DAY_IN_MILISECONDS
|
||||
end: tradingProcessDate.valueOf() + TS.projects.superalgos.globals.timeConstants.ONE_DAY_IN_MILISECONDS
|
||||
}
|
||||
|
||||
let fileContent = JSON.stringify(dataRange);
|
||||
|
||||
@@ -258,7 +258,7 @@ exports.newTradingSimulation = function newTradingSimulation(bot, logger, tradin
|
||||
if (sessionParameters.heartbeats.config.date === true || sessionParameters.heartbeats.config.candleIndex === true) {
|
||||
/* We will produce a simulation level heartbeat in order to inform the user this is running. */
|
||||
|
||||
heartBeatDate = new Date(Math.trunc(tradingEngine.current.episode.candle.begin.value / global.ONE_DAY_IN_MILISECONDS) * global.ONE_DAY_IN_MILISECONDS)
|
||||
heartBeatDate = new Date(Math.trunc(tradingEngine.current.episode.candle.begin.value / TS.projects.superalgos.globals.timeConstants.ONE_DAY_IN_MILISECONDS) * TS.projects.superalgos.globals.timeConstants.ONE_DAY_IN_MILISECONDS)
|
||||
|
||||
let fromDate = new Date(sessionParameters.timeRange.config.initialDatetime)
|
||||
let lastDate = new Date(sessionParameters.timeRange.config.finalDatetime)
|
||||
@@ -424,7 +424,7 @@ exports.newTradingSimulation = function newTradingSimulation(bot, logger, tradin
|
||||
the day, we will advance current process day one day. By doing so, during the next execution, the
|
||||
simulation will receive the candles and indicators files of the next day.
|
||||
*/
|
||||
let candlesPerDay = global.ONE_DAY_IN_MILISECONDS / sessionParameters.timeFrame.config.value
|
||||
let candlesPerDay = TS.projects.superalgos.globals.timeConstants.ONE_DAY_IN_MILISECONDS / sessionParameters.timeFrame.config.value
|
||||
if (
|
||||
bot.processingDailyFiles &&
|
||||
tradingEngine.current.episode.candle.index.value + 1 + 1 === candlesPerDay
|
||||
@@ -438,7 +438,7 @@ exports.newTradingSimulation = function newTradingSimulation(bot, logger, tradin
|
||||
*/
|
||||
tradingEngine.current.episode.candle.index.value = 0
|
||||
tradingEngine.current.episode.processDate.value =
|
||||
tradingEngine.current.episode.processDate.value + global.ONE_DAY_IN_MILISECONDS
|
||||
tradingEngine.current.episode.processDate.value + TS.projects.superalgos.globals.timeConstants.ONE_DAY_IN_MILISECONDS
|
||||
return false
|
||||
}
|
||||
|
||||
|
||||
@@ -221,15 +221,15 @@
|
||||
let n;
|
||||
let botNeverRan = true;
|
||||
|
||||
bot.multiPeriodDailyProcessDatetime = new Date(contextVariables.lastFile.valueOf() - ONE_DAY_IN_MILISECONDS) // Go back one day to start well when we advance time at the begining of the loop.
|
||||
bot.multiPeriodDailyProcessDatetime = new Date(contextVariables.lastFile.valueOf() - TS.projects.superalgos.globals.timeConstants.ONE_DAY_IN_MILISECONDS) // Go back one day to start well when we advance time at the begining of the loop.
|
||||
let fromDate = new Date(bot.multiPeriodDailyProcessDatetime.valueOf())
|
||||
let lastDate = new Date()
|
||||
|
||||
advanceTime()
|
||||
|
||||
function advanceTime() {
|
||||
bot.multiPeriodDailyProcessDatetime = new Date(bot.multiPeriodDailyProcessDatetime.valueOf() + ONE_DAY_IN_MILISECONDS)
|
||||
previousDay = new Date(bot.multiPeriodDailyProcessDatetime.valueOf() - ONE_DAY_IN_MILISECONDS)
|
||||
bot.multiPeriodDailyProcessDatetime = new Date(bot.multiPeriodDailyProcessDatetime.valueOf() + TS.projects.superalgos.globals.timeConstants.ONE_DAY_IN_MILISECONDS)
|
||||
previousDay = new Date(bot.multiPeriodDailyProcessDatetime.valueOf() - TS.projects.superalgos.globals.timeConstants.ONE_DAY_IN_MILISECONDS)
|
||||
|
||||
logger.write(MODULE_NAME, "[INFO] start -> processTimeFrames -> advanceTime -> bot.multiPeriodDailyProcessDatetime = " + bot.multiPeriodDailyProcessDatetime)
|
||||
logger.write(MODULE_NAME, "[INFO] start -> processTimeFrames -> advanceTime -> previousDay = " + previousDay)
|
||||
@@ -489,7 +489,7 @@
|
||||
function writeDataRange(pBegin, pEnd, productCodeName, callBack) {
|
||||
let dataRange = {
|
||||
begin: pBegin.valueOf(),
|
||||
end: pEnd.valueOf() + ONE_DAY_IN_MILISECONDS
|
||||
end: pEnd.valueOf() + TS.projects.superalgos.globals.timeConstants.ONE_DAY_IN_MILISECONDS
|
||||
};
|
||||
let fileContent = JSON.stringify(dataRange)
|
||||
let fileName = '/Data.Range.json';
|
||||
|
||||
@@ -648,7 +648,7 @@ exports.newLearningProcess = function newLearningProcess(bot, logger, UTILITIES)
|
||||
async function writeDataRange(productCodeName) {
|
||||
let dataRange = {
|
||||
begin: contextVariables.dateBeginOfMarket.valueOf(),
|
||||
end: LearningProcessDate.valueOf() + global.ONE_DAY_IN_MILISECONDS
|
||||
end: LearningProcessDate.valueOf() + TS.projects.superalgos.globals.timeConstants.ONE_DAY_IN_MILISECONDS
|
||||
}
|
||||
|
||||
let fileContent = JSON.stringify(dataRange);
|
||||
|
||||
@@ -196,7 +196,7 @@
|
||||
type: 'Time Range',
|
||||
config: {
|
||||
initialDatetime: (new Date()).valueOf(),
|
||||
finalDatetime: (new Date()).valueOf() + global.ONE_YEAR_IN_MILISECONDS
|
||||
finalDatetime: (new Date()).valueOf() + TS.projects.superalgos.globals.timeConstants.ONE_YEAR_IN_MILISECONDS
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@@ -219,8 +219,8 @@
|
||||
|
||||
/* Session Type Forced Values */
|
||||
let today = (new Date()).valueOf()
|
||||
let aYearAgo = today - global.ONE_YEAR_IN_MILISECONDS
|
||||
let aYearFromNow = today + global.ONE_YEAR_IN_MILISECONDS
|
||||
let aYearAgo = today - TS.projects.superalgos.globals.timeConstants.ONE_YEAR_IN_MILISECONDS
|
||||
let aYearFromNow = today + TS.projects.superalgos.globals.timeConstants.ONE_YEAR_IN_MILISECONDS
|
||||
switch (bot.TRADING_SESSION.type) {
|
||||
case 'Backtesting Session': {
|
||||
useDefaultDatetimes(aYearAgo, today)
|
||||
|
||||
Reference in new issue
Block a user