jsonifyDataFile implemented
This commit is contained in:
1 parent
18323d526d
commit
fcbb893123
3 files changed
+86
-9
No files matched your search
+59
-8
@@ -8,8 +8,8 @@
|
||||
const ONE_DAY_IN_MILISECONDS = 24 * 60 * 60 * 1000;
|
||||
|
||||
let thisObject = {
|
||||
buildBandsArray: buildBandsArray,
|
||||
buildChannels: buildChannels,
|
||||
jsonifyDataFile: jsonifyDataFile,
|
||||
calculationsProcedure: calculationsProcedure,
|
||||
buildStandardChannels: buildStandardChannels,
|
||||
buildSubChannels: buildSubChannels,
|
||||
buildStandardSubChannels: buildStandardSubChannels,
|
||||
@@ -18,24 +18,75 @@
|
||||
|
||||
return thisObject;
|
||||
|
||||
function buildDependecyArray(dataFile, recordDefinition) {
|
||||
function jsonifyDataFile(dataFile, recordDefinition) {
|
||||
|
||||
let dependecyArray = []
|
||||
/*
|
||||
This function has as an input the raw data on files and creates with it an array of JSON objects
|
||||
with not calculated properties for later being consumed by Formulas
|
||||
*/
|
||||
|
||||
let jsonifiedArray = []
|
||||
|
||||
for (let i = 0; i < dataFile.length; i++) {
|
||||
|
||||
let record = {}
|
||||
for (let j = 0; j < recordDefinition.length; j++) {
|
||||
let property = recordDefinition[j]
|
||||
record[property.name] = dataFile[i][j]
|
||||
for (let j = 0; j < recordDefinition.properties.length; j++) {
|
||||
let property = recordDefinition.properties[j]
|
||||
record[property.code.codeName] = dataFile[i][j]
|
||||
}
|
||||
|
||||
dependecyArray.push(record);
|
||||
jsonifiedArray.push(record);
|
||||
}
|
||||
|
||||
return jsonifiedArray
|
||||
}
|
||||
|
||||
function calculationsProcedure(dependencyArray, variableName, timePeriod) {
|
||||
|
||||
/*
|
||||
This function has as an input an array of JSON objects, and it adds calculated properties to
|
||||
complete the set of properties that will be available for Formulas.
|
||||
*/
|
||||
|
||||
let dependecyArray = []
|
||||
|
||||
/* This is Initialization Code */
|
||||
let lastMovingAverage = 0;
|
||||
const SIDE_TOLERANCE = 0.5 * timePeriod / ONE_DAY_IN_MILISECONDS;
|
||||
const SMALL_SLOPE = 1.0 * timePeriod / ONE_DAY_IN_MILISECONDS;
|
||||
const MEDIUM_SLOPE = 2.0 * timePeriod / ONE_DAY_IN_MILISECONDS;
|
||||
const HIGH_SLOPE = 4.0 * timePeriod / ONE_DAY_IN_MILISECONDS;
|
||||
/* This is Initialization Code */
|
||||
|
||||
for (let i = 0; i < dataFile.length; i++) {
|
||||
|
||||
let indicator = {}
|
||||
indicator[variableName] = dataFile[i]
|
||||
|
||||
/* This is Add Properties Code */
|
||||
if (lastMovingAverage > indicator.bollingerBand.movingAverage) { indicator.bollingerBand.direction = 'Down'; }
|
||||
if (lastMovingAverage < indicator.bollingerBand.movingAverage) { indicator.bollingerBand.direction = 'Up'; }
|
||||
if (lastMovingAverage === indicator.bollingerBand.movingAverage) { indicator.bollingerBand.direction = 'Side'; }
|
||||
|
||||
let delta = Math.abs(indicator.bollingerBand.movingAverage - lastMovingAverage);
|
||||
|
||||
indicator.bollingerBand.slope = 'Extreme';
|
||||
if (delta < indicator.bollingerBand.movingAverage * HIGH_SLOPE / 100) { indicator.bollingerBand.slope = 'Steep'; }
|
||||
if (delta < indicator.bollingerBand.movingAverage * MEDIUM_SLOPE / 100) { indicator.bollingerBand.slope = 'Medium'; }
|
||||
if (delta < indicator.bollingerBand.movingAverage * SMALL_SLOPE / 100) { indicator.bollingerBand.slope = 'Gentle'; }
|
||||
if (delta < indicator.bollingerBand.movingAverage * SIDE_TOLERANCE / 100) { indicator.bollingerBand.slope = 'Side'; }
|
||||
|
||||
lastMovingAverage = indicator.bollingerBand.movingAverage;
|
||||
/* This is Add Properties Code */
|
||||
|
||||
dependecyArray.push(indicator.bollingerBand);
|
||||
}
|
||||
|
||||
return dependecyArray
|
||||
}
|
||||
|
||||
|
||||
|
||||
function addCalculatedProperties(dependencyArray, variableName, timePeriod) {
|
||||
|
||||
let dependecyArray = []
|
||||
|
||||
@@ -48,6 +48,31 @@
|
||||
if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> Entering function."); }
|
||||
|
||||
let market = global.MARKET;
|
||||
|
||||
let dataDependencies = bot.processNode.referenceParent.processDependencies.dataDependencies
|
||||
for (let i = 0; i < dataDependencies.length; i++) {
|
||||
let dataset = dataDependencies[i].referenceParent
|
||||
/*
|
||||
For each dataset in our data dependencies, we should have da dataFile containing the records needed as an imput for this process.
|
||||
What we need to do first is transform those records into JSON objects that can be used by user-defined formulas.
|
||||
*/
|
||||
if (dataset.parentNode.record === undefined) {
|
||||
logger.write(MODULE_NAME, "[ERROR] start -> Product Definition without a Record Definition. Product Definition = " + JSON.stringify(dataset.parentNode));
|
||||
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
|
||||
return
|
||||
}
|
||||
dataset.inputData = commons.jsonifyDataFile(dataFiles[i], dataset.parentNode.record)
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
let dataFile;
|
||||
|
||||
let bands = [];
|
||||
|
||||
@@ -73,7 +73,8 @@ if (global.TASK_NODE !== undefined) {
|
||||
}
|
||||
else { // I use this section to debug in standalone mode.
|
||||
let argument
|
||||
argument = '{"type":"Task","name":"Generates Bollinger Channels & Sub-Channels","bot":{"type":"Indicator Bot Instance","name":"Paula","code":{"team":"AAMasters","bot":"AAPaula","repo":"AAChris-Indicator-Bot"},"processes":[{"type":"Process Instance","subType":"Indicator Process Instance","name":"Market","code":{"process":"Multi-Period-Market"},"id":"6ddd81e2-d6db-4814-9c6c-96538a74824c","referenceParent":{"type":"Process Definition","name":"Multi-Period-Market","code":{"codeName":"Multi-Period-Market","description":"Produces for each market two files with bollinger channels respectively.","startMode":{"allMonths":{"run":"false","minYear":"","maxYear":""},"oneMonth":{"run":"false","year":"","month":""},"noTime":{"run":"true"},"fixedInterval":{"run":"false","interval":0}},"deadWaitTime":0,"normalWaitTime":0,"retryWaitTime":10000,"sleepWaitTime":3600000,"comaWaitTime":86400000,"framework":{"name":"Multi-Period-Market","startDate":{},"endDate":{}}},"id":"28be432d-80ca-46b3-859a-55541e24b2b4","processOutput":{"type":"Process Output","name":"New Process Output","outputDatasets":[{"type":"Output Dataset","name":"Bollinger Channels","id":"d804e799-7c12-42f5-8de2-52a3a7d5daa4","referenceParent":{"type":"Dataset Definition","name":"Market","code":{"codeName":"Multi-Period-Market","type":"Market Files","validPeriods":["24-hs","12-hs","08-hs","06-hs","04-hs","03-hs","02-hs","01-hs"],"filePath":"AAMasters/AAPaula.1.0/AACloud.1.1/@Exchange/dataSet.V1/Output/Bollinger-Channels/Multi-Period-Market/@Period","fileName":"@AssetA_@AssetB.json"},"parentNode":{"type":"Product Definition","name":"Bollinger Channels","code":{"codeName":"Bollinger-Channels","displayName":"Bollinger-Channels","description":"Two sets of files per period that contains Bollinger-Bands-Channels-Patterns.","shareWith":"Public"},"datasets":[],"parentNode":{"type":"Indicator Bot","name":"Paula","code":{"codeName":"AAPaula"},"processes":[],"products":[],"parentNode":{"type":"Team","name":"Masters","code":{"codeName":"AAMasters"},"sensorBots":[],"indicatorBots":[],"tradingBots":[],"plotters":[],"id":"35be7b1c-a0f7-4b5f-9ee1-8fb51595e959"},"id":"bd0f325d-6f98-468b-8b7b-99a42a175d80"},"id":"1f111f72-624f-4166-9f99-ab8d785d5267"},"id":"610cd062-ab88-4892-b711-0fb430305c61"}},{"type":"Output Dataset","name":"Bollinger Standard Channels","id":"e524685d-8da0-41f6-839d-9a4100e6e3fe","referenceParent":{"type":"Dataset Definition","name":"Market","code":{"codeName":"Multi-Period-Market","type":"Market Files","validPeriods":["24-hs","12-hs","08-hs","06-hs","04-hs","03-hs","02-hs","01-hs"],"filePath":"AAMasters/AAPaula.1.0/AACloud.1.1/@Exchange/dataSet.V1/Output/Bollinger-Standard-Channels/Multi-Period-Market/@Period","fileName":"@AssetA_@AssetB.json"},"parentNode":{"type":"Product Definition","name":"Bollinger Standard Channels","code":{"codeName":"Bollinger-Standard-Channels","displayName":"Bollinger-Standard-Channels","description":"","shareWith":"Public"},"datasets":[],"parentNode":{"type":"Indicator Bot","name":"Paula","code":{"codeName":"AAPaula"},"processes":[],"products":[],"parentNode":{"type":"Team","name":"Masters","code":{"codeName":"AAMasters"},"sensorBots":[],"indicatorBots":[],"tradingBots":[],"plotters":[],"id":"35be7b1c-a0f7-4b5f-9ee1-8fb51595e959"},"id":"bd0f325d-6f98-468b-8b7b-99a42a175d80"},"id":"94bc3958-cc85-43a1-a178-103e84f42910"},"id":"22c1f2c6-3838-4657-add8-2e01d7056917"}},{"type":"Output Dataset","name":"Bollinger Sub-Channels","id":"eb0e7947-95e4-4f4a-87ea-1fb430b8b503","referenceParent":{"type":"Dataset Definition","name":"Market","code":{"codeName":"Multi-Period-Market","type":"Market Files","validPeriods":["24-hs","12-hs","08-hs","06-hs","04-hs","03-hs","02-hs","01-hs"],"filePath":"AAMasters/AAPaula.1.0/AACloud.1.1/@Exchange/dataSet.V1/Output/Bollinger-Sub-Channels/Multi-Period-Market/@Period","fileName":"@AssetA_@AssetB.json"},"parentNode":{"type":"Product Definition","name":"Bollinger Sub-Channels","code":{"codeName":"Bollinger-Sub-Channels","displayName":"Bollinger-Sub-Channels","description":"Bollinger Sub Channels with slope.","shareWith":"Public"},"datasets":[],"parentNode":{"type":"Indicator Bot","name":"Paula","code":{"codeName":"AAPaula"},"processes":[],"products":[],"parentNode":{"type":"Team","name":"Masters","code":{"codeName":"AAMasters"},"sensorBots":[],"indicatorBots":[],"tradingBots":[],"plotters":[],"id":"35be7b1c-a0f7-4b5f-9ee1-8fb51595e959"},"id":"bd0f325d-6f98-468b-8b7b-99a42a175d80"},"id":"080c87fc-4546-4482-ab11-180a33f6d9ab"},"id":"869f615e-0cc0-44fd-8648-4a951c23a410"}},{"type":"Output Dataset","name":"Bollinger Standard Sub-Channels","id":"dc96b9ac-f8d5-4bf8-a135-45cd5d6369f1","referenceParent":{"type":"Dataset Definition","name":"Market","code":{"codeName":"Multi-Period-Market","type":"Market Files","validPeriods":["24-hs","12-hs","08-hs","06-hs","04-hs","03-hs","02-hs","01-hs"],"filePath":"AAMasters/AAPaula.1.0/AACloud.1.1/@Exchange/dataSet.V1/Output/Bollinger-Standard-Sub-Channels/Multi-Period-Market/@PeriLine truncated
|
||||
argument = ' {"type":"Task","name":"Generates Bollinger Channels & Sub-Channels","bot":{"type":"Indicator Bot Instance","name":"Paula","code":{"team":"AAMasters","bot":"AAPaula","repo":"AAPaula-Indicator-Bot"},"processes":[{"type":"Process Instance","subType":"Indicator Process Instance","name":"Market","code":{"process":"Multi-Period-Market"},"id":"6ddd81e2-d6db-4814-9c6c-96538a74824c","referenceParent":{"type":"Process Definition","name":"Multi-Period-Market","code":{"codeName":"Multi-Period-Market","description":"Produces for each market two files with bollinger channels respectively.","startMode":{"allMonths":{"run":"false","minYear":"","maxYear":""},"oneMonth":{"run":"false","year":"","month":""},"noTime":{"run":"true"},"fixedInterval":{"run":"false","interval":0}},"deadWaitTime":0,"normalWaitTime":0,"retryWaitTime":10000,"sleepWaitTime":3600000,"comaWaitTime":86400000,"framework":{"name":"Multi-Period-Market","startDate":{},"endDate":{}}},"id":"28be432d-80ca-46b3-859a-55541e24b2b4","processOutput":{"type":"Process Output","name":"New Process Output","outputDatasets":[{"type":"Output Dataset","name":"Bollinger Channels","id":"d804e799-7c12-42f5-8de2-52a3a7d5daa4","referenceParent":{"type":"Dataset Definition","name":"Market","code":{"codeName":"Multi-Period-Market","type":"Market Files","validPeriods":["24-hs","12-hs","08-hs","06-hs","04-hs","03-hs","02-hs","01-hs"],"filePath":"AAMasters/AAPaula.1.0/AACloud.1.1/@Exchange/dataSet.V1/Output/Bollinger-Channels/Multi-Period-Market/@Period","fileName":"@AssetA_@AssetB.json"},"parentNode":{"type":"Product Definition","name":"Bollinger Channels","code":{"codeName":"Bollinger-Channels","displayName":"Bollinger-Channels","description":"Two sets of files per period that contains Bollinger-Bands-Channels-Patterns.","shareWith":"Public"},"datasets":[],"record":{"type":"Record Definition","name":"New Record Definition","properties":[{"type":"Record Property","name":"Begin","code":{"codeName":"begin","isNumeric":true},"formula":{"type":"Formula","code":"// Write your formula here","id":"caf8122c-3a07-4263-a56f-ffb05df281d6"},"id":"06edb099-ff64-4528-b8c6-599154bc2ddf"},{"type":"Record Property","name":"End","code":{"codeName":"end","isNumeric":true},"formula":{"type":"Formula","code":"// Write your formula here","id":"c8ec0868-8413-468c-88d5-3e43169395e0"},"id":"94656d1f-508a-4e94-a8d2-013690aac596"},{"type":"Record Property","name":"Direction","code":{"codeName":"direction","isNumeric":false},"formula":{"type":"Formula","code":"// Write your formula here","id":"e913afe9-b610-4777-bc9e-6349d436a90a"},"id":"edc0f697-f5e2-446f-bae8-8db7adf91d23"},{"type":"Record Property","name":"Period","code":{"codeName":"period","isNumeric":true},"formula":{"type":"Formula","code":"// Write your formula here","id":"83fce657-a0bb-41ee-80d1-9e2ab980c472"},"id":"eb733f85-6cf5-485e-9bd3-2bf78733c492"},{"type":"Record Property","name":"First Moving Average","code":{"codeName":"firstMovingAverage","isNumeric":true},"formula":{"type":"Formula","code":"// Write your formula here","id":"52490460-35e3-469a-824f-5b139571d4a0"},"id":"a67a15ee-6f7f-48bd-9d55-82c57efc993b"},{"type":"Record Property","name":"Last Moving Average","code":{"codeName":"lastMovingAverage","isNumeric":true},"formula":{"type":"Formula","code":"// Write your formula here","id":"41edc1ef-293a-4ceb-bf67-8042e8fdc4eb"},"id":"0f05bffe-d668-4d25-ab67-d55a4a7c8f5d"},{"type":"Record Property","name":"First Deviation","code":{"codeName":"firstDeviation","isNumeric":true},"formula":{"type":"Formula","code":"// Write your formula here","id":"5af02103-9bc9-4e6c-9684-5a612adfa495"},"id":"eae84509-b689-4a76-9277-eed72af491dd"},{"type":"Record Property","name":"Last Deviation","code":{"codeName":"lastDeviation","isNumeric":true},"formula":{"type":"Formula","code":"// Write your formula here","id":"bc82d292-e71a-4367-9b07-a0e3982ad60d"},"id":"d5c32d1f-9e3c-48e8-8025-a17d57c0812e"}],"id":"6c3e68b0-b781-4c53-9ff7-67c3f747ac8a"},"parentNode":{"type":"Indicator Bot","name":"Paula","code":{"codeName":"AAPaula"},"processes":[],"products":[],"parentNode":{"type":"Team","name":"Masters","code":{"codeName":"AAMasters"},"sensorBots":[],"indicatorBots":[],"tradingBots":[],"plotters":[],"id":"35be7b1c-a0f7-4b5f-9ee1-8fb51595e959"},"id":"bd0f325d-6f98-468b-8b7b-99a42a175d80"},"id":"1f111f72-624f-4166-9f99-ab8d785d5267"},"id":"610cd062-ab88-4892-b711-0fb430305c61"}},{"type":"Output Dataset","name":"Bollinger Standard Channels","id":"e524685d-8da0-41f6-839d-9a4100e6e3fe","referenceParent":{"type":"Dataset Definition","name":"Market","code":{"codeName":"Multi-Period-Market","type":"Market Files","validPeriods":["24-hs","12-hs","08-hs","06-hs","04-hs","03-hs","02-hs","01-hs"],"filePath":"AAMasters/AAPaula.1.0/AACloud.1.1/@Exchange/dataSet.V1/Output/Bollinger-Standard-Channels/Multi-Period-Market/@Period","fileName":"@AssetA_@AssetB.json"},"parentNode":{"type":"Product Definition","name":"Bollinger Standard Channels","code":{"codeName":"Bollinger-SLine truncated
|
||||
|
||||
|
||||
try {
|
||||
global.TASK_NODE = JSON.parse(argument)
|
||||
|
||||
Reference in new issue
Block a user