Trading Algorithm Implementation
This commit is contained in:
1 parent
af81aff87e
commit
42b8225b5e
5 files changed
+184
-3
No files matched your search
@@ -845,6 +845,15 @@
|
||||
"fileName": "LearningSystem.js",
|
||||
"folderName": "Learning-Bot/Low-Frequency-Learning"
|
||||
}
|
||||
],
|
||||
"algorithmModules": [
|
||||
{
|
||||
"name": "Time Series Forcasting Tensor Flow JS",
|
||||
"propertyName": "timeSeriesForcastingTensorFlowJS",
|
||||
"functionName": "newSuperalgosAlgorithmModulesTimeSeriesForcastingTensorFlowJS",
|
||||
"fileName": "LearningAlgorithm.js",
|
||||
"folderName": "Learning-Bot/Low-Frequency-Learning/Time-Series-Forcasting/Tensor-Flow-JS"
|
||||
}
|
||||
]
|
||||
},
|
||||
"CL": {}
|
||||
|
||||
@@ -10441,7 +10441,7 @@
|
||||
}
|
||||
],
|
||||
"initialValues": {
|
||||
"config": "{ \n\"codeName\": \"\"\n}"
|
||||
"config": "{ \n\"codeName\": \"Time Series Forcasting Tensor Flow JS\"\n}"
|
||||
},
|
||||
"addLeftIcons": true,
|
||||
"editors": {
|
||||
|
||||
+56
-1
@@ -26,6 +26,29 @@ exports.newSuperalgosBotModulesLearningSystem = function (processIndex) {
|
||||
let sessionParameters
|
||||
let dynamicIndicators
|
||||
|
||||
let learningAlgorithmName = TS.projects.superalgos.globals.processConstants.CONSTANTS_BY_PROCESS_INDEX_MAP.get(processIndex).SESSION_NODE.learningParameters.learningAlgorithmModuleObject.config.codeName
|
||||
let learningAlgorithmModuleObject
|
||||
/*
|
||||
We will scan the project schema until we find the module that will run the algorithm
|
||||
defined by the user at the UI / Session Parameters.
|
||||
*/
|
||||
for (let i = 0; i < TS.projects.superalgos.globals.taskConstants.PROJECTS_SCHEMA.length; i++) {
|
||||
let project = TS.projects.superalgos.globals.taskConstants.PROJECTS_SCHEMA[i]
|
||||
if (project.name !== TS.projects.superalgos.globals.taskConstants.PROJECT_DEFINITION_NODE.config.codeName) { continue }
|
||||
for (let j = 0; j < project.TS.algorithmModules.length; j++) {
|
||||
algorithmModuleDefinition = project.TS.algorithmModules[j]
|
||||
if (algorithmModuleDefinition.name === learningAlgorithmName) {
|
||||
|
||||
TS.projects.superalgos.globals.processVariables.TOTAL_PROCESS_INSTANCES_CREATED++
|
||||
let project = TS.projects[TS.projects.superalgos.globals.taskConstants.PROJECT_DEFINITION_NODE.config.codeName.toLowerCase()]
|
||||
let botModule = project.algorithmModules[algorithmModuleDefinition.propertyName]
|
||||
let moduleFunction = botModule[algorithmModuleDefinition.functionName]
|
||||
learningAlgorithmModuleObject = moduleFunction(processIndex)
|
||||
}
|
||||
}
|
||||
}
|
||||
let learningAlgorithmModuleObject = TS.projects.superalgos.botModules.tradingStages.newSuperalgosBotModulesTradingStages(processIndex)
|
||||
|
||||
return thisObject
|
||||
|
||||
function initialize() {
|
||||
@@ -98,6 +121,19 @@ exports.newSuperalgosBotModulesLearningSystem = function (processIndex) {
|
||||
learningSystem.infos.push(infoDataArray)
|
||||
}
|
||||
|
||||
/*
|
||||
Initialize the Learning Algorithm
|
||||
*/
|
||||
learningAlgorithmModuleObject.initialize(onInitializeReady)
|
||||
|
||||
function onInitializeReady(err) {
|
||||
if (err.result === TS.projects.superalgos.globals.standardResponses.DEFAULT_OK_RESPONSE.result) {
|
||||
|
||||
} else {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
function isItInside(elementWithTimestamp, elementWithBeginEnd) {
|
||||
/*
|
||||
The function is to allow in Conditions and Formulas to easily
|
||||
@@ -115,6 +151,9 @@ exports.newSuperalgosBotModulesLearningSystem = function (processIndex) {
|
||||
|
||||
function finalize() {
|
||||
|
||||
learningAlgorithmModuleObject.finalize()
|
||||
learningAlgorithmModuleObject = undefined
|
||||
|
||||
chart = undefined
|
||||
exchange = undefined
|
||||
market = undefined
|
||||
@@ -137,10 +176,11 @@ exports.newSuperalgosBotModulesLearningSystem = function (processIndex) {
|
||||
}
|
||||
|
||||
function mantain() {
|
||||
|
||||
learningAlgorithmModuleObject.mantain()
|
||||
}
|
||||
|
||||
function reset() {
|
||||
learningAlgorithmModuleObject.reset()
|
||||
|
||||
learningSystem.highlights = []
|
||||
learningSystem.errors = []
|
||||
@@ -161,6 +201,8 @@ exports.newSuperalgosBotModulesLearningSystem = function (processIndex) {
|
||||
chart = pChart
|
||||
exchange = pExchange
|
||||
market = pMarket
|
||||
|
||||
learningAlgorithmModuleObject.updateChart(pChart, pExchange, pMarket)
|
||||
}
|
||||
|
||||
function buildDynamicIndicators() {
|
||||
@@ -183,6 +225,19 @@ exports.newSuperalgosBotModulesLearningSystem = function (processIndex) {
|
||||
/* Dynamic Indicators */
|
||||
buildDynamicIndicators()
|
||||
|
||||
/*
|
||||
Initialize the Learning Algorithm
|
||||
*/
|
||||
learningAlgorithmModuleObject.run(onRun)
|
||||
|
||||
function onRun(err) {
|
||||
if (err.result === TS.projects.superalgos.globals.standardResponses.DEFAULT_OK_RESPONSE.result) {
|
||||
|
||||
} else {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
} catch (err) {
|
||||
/*
|
||||
If an error ocurred during execution, it was alreeady logged and
|
||||
|
||||
+105
@@ -0,0 +1,105 @@
|
||||
exports.newSuperalgosAlgorithmModulesTimeSeriesForcastingTensorFlowJS = function (processIndex) {
|
||||
/*
|
||||
This module implements a learning algorithm based on Time Series Forcasting with Tensor Flow js,
|
||||
as described at the folliwing web page:
|
||||
|
||||
https://jinglescode.github.io/time-series-forecasting-tensorflowjs/
|
||||
*/
|
||||
const MODULE_NAME = 'Time Series Forcasting Tensor Flow JS Learning Algorithm'
|
||||
let thisObject = {
|
||||
updateChart: updateChart,
|
||||
mantain: mantain,
|
||||
reset: reset,
|
||||
run: run,
|
||||
initialize: initialize,
|
||||
finalize: finalize
|
||||
}
|
||||
|
||||
let learningEngine
|
||||
let learningSystem
|
||||
let sessionParameters
|
||||
|
||||
/*
|
||||
These 3 are the main data structures available to users
|
||||
when writing conditions and formulas.
|
||||
*/
|
||||
let chart
|
||||
let exchange
|
||||
let market
|
||||
|
||||
return thisObject
|
||||
|
||||
function initialize(callbackFunction) {
|
||||
learningSystem = TS.projects.superalgos.globals.processVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).SIMULATION_STATE.learningSystem
|
||||
learningEngine = TS.projects.superalgos.globals.processVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).SIMULATION_STATE.learningEngine
|
||||
sessionParameters = TS.projects.superalgos.globals.processConstants.CONSTANTS_BY_PROCESS_INDEX_MAP.get(processIndex).SESSION_NODE.learningParameters
|
||||
|
||||
callbackFunction(TS.projects.superalgos.globals.standardResponses.DEFAULT_OK_RESPONSE)
|
||||
}
|
||||
|
||||
function finalize() {
|
||||
learningEngine = undefined
|
||||
learningSystem = undefined
|
||||
sessionParameters = undefined
|
||||
|
||||
chart = undefined
|
||||
exchange = undefined
|
||||
market = undefined
|
||||
}
|
||||
|
||||
function updateChart(pChart, pExchange, pMarket) {
|
||||
/*
|
||||
We need these 3 data structures to be a local objects
|
||||
accessible while evaluating conditions and formulas.
|
||||
*/
|
||||
chart = pChart
|
||||
exchange = pExchange
|
||||
market = pMarket
|
||||
}
|
||||
|
||||
function mantain() {
|
||||
updateCounters()
|
||||
updateEnds()
|
||||
}
|
||||
|
||||
function reset() {
|
||||
}
|
||||
|
||||
function run(callbackFunction) {
|
||||
/*
|
||||
Do your magic here...
|
||||
*/
|
||||
|
||||
/*
|
||||
if all is good, return this...
|
||||
*/
|
||||
callbackFunction(TS.projects.superalgos.globals.standardResponses.DEFAULT_OK_RESPONSE)
|
||||
|
||||
/*
|
||||
if something is bad, return this...
|
||||
*/
|
||||
//callbackFunction(TS.projects.superalgos.globals.standardResponses.DEFAULT_FAIL_RESPONSE)
|
||||
|
||||
}
|
||||
|
||||
function badDefinitionUnhandledException(err, message, node) {
|
||||
|
||||
let docs = {
|
||||
project: 'Superalgos',
|
||||
category: 'Topic',
|
||||
type: 'TS LF Learning Bot Error - ' + message,
|
||||
placeholder: {}
|
||||
}
|
||||
|
||||
learningSystem.addError([node.id, message, docs])
|
||||
|
||||
TS.projects.superalgos.globals.loggerVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).BOT_MAIN_LOOP_LOGGER_MODULE_OBJECT.write(MODULE_NAME, "[ERROR] -> " + message);
|
||||
TS.projects.superalgos.globals.loggerVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).BOT_MAIN_LOOP_LOGGER_MODULE_OBJECT.write(MODULE_NAME, "[ERROR] -> node.name = " + node.name);
|
||||
TS.projects.superalgos.globals.loggerVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).BOT_MAIN_LOOP_LOGGER_MODULE_OBJECT.write(MODULE_NAME, "[ERROR] -> node.type = " + node.type);
|
||||
TS.projects.superalgos.globals.loggerVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).BOT_MAIN_LOOP_LOGGER_MODULE_OBJECT.write(MODULE_NAME, "[ERROR] -> node.config = " + JSON.stringify(node.config));
|
||||
if (err !== undefined) {
|
||||
TS.projects.superalgos.globals.loggerVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).BOT_MAIN_LOOP_LOGGER_MODULE_OBJECT.write(MODULE_NAME, "[ERROR] -> err.stack = " + err.stack);
|
||||
}
|
||||
throw 'Error Already Recorded'
|
||||
}
|
||||
}
|
||||
@@ -30,6 +30,7 @@ exports.newMultiProject = function () {
|
||||
projectInstance.taskModules = {}
|
||||
projectInstance.processModules = {}
|
||||
projectInstance.botModules = {}
|
||||
projectInstance.algorithmModules = {}
|
||||
|
||||
/* Set up Utilities of this Project */
|
||||
if (projectDefinition.TS.utilities !== undefined) {
|
||||
@@ -93,12 +94,23 @@ exports.newMultiProject = function () {
|
||||
if (projectDefinition.TS.botModules !== undefined) {
|
||||
for (let j = 0; j < projectDefinition.TS.botModules.length; j++) {
|
||||
let botModuleDefinition = projectDefinition.TS.botModules[j]
|
||||
let path = global.env.PATH_TO_PROJECTS_REQUIRED + '/' + projectDefinition.name + '/' + 'TS' + '/' + 'Bot-Modules' + '/' + botModuleDefinition.folderName + '/' + botModuleDefinition.fileName
|
||||
let path = global.env.PATH_TO_PROJECTS_REQUIRED + '/' + projectDefinition.name + '/' + 'TS' + '/' + 'Bot-Modules' + '/' + botModuleDefinition.folderName + '/' + botModuleDefinition.fileName
|
||||
|
||||
let requiredObject = require(path)
|
||||
projectInstance.botModules[botModuleDefinition.propertyName] = requiredObject
|
||||
}
|
||||
}
|
||||
|
||||
/* Set up Algorithm Modules for this Project */
|
||||
if (projectDefinition.TS.algorithmModules !== undefined) {
|
||||
for (let j = 0; j < projectDefinition.TS.algorithmModules.length; j++) {
|
||||
let algorithmModuleDefinition = projectDefinition.TS.algorithmModules[j]
|
||||
let path = global.env.PATH_TO_PROJECTS_REQUIRED + '/' + projectDefinition.name + '/' + 'TS' + '/' + 'Bot-Modules' + '/' + algorithmModuleDefinition.folderName + '/' + algorithmModuleDefinition.fileName
|
||||
|
||||
let requiredObject = require(path)
|
||||
projectInstance.algorithmModules[algorithmModuleDefinition.propertyName] = requiredObject
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TS.projects.superalgos.globals.taskConstants.PROJECTS_SCHEMA = PROJECTS_SCHEMA
|
||||
|
||||
Reference in new issue
Block a user