Merge branch 'master' of https://github.com/AAMasters/AAGauss-Indicator-Bot
This commit is contained in:
commit
bf7f7367dc
3 files changed
+157
No files matched your search
@@ -105,6 +105,9 @@ LRCIndicator.prototype.calculate = function (price) {
|
||||
|
||||
exports.newUserBot = function newUserBot(BOT, COMMONS, UTILITIES, DEBUG_MODULE, BLOB_STORAGE) {
|
||||
const FULL_LOG = true;
|
||||
=======
|
||||
const FULL_LOG = false;
|
||||
>>>>>>> efa5470188c576eca370cc465a9a63946bdb4e8d
|
||||
const LOG_FILE_CONTENT = false;
|
||||
const USE_PARTIAL_LAST_CANDLE = true; // When running live the last candle generated is a partial candle.
|
||||
|
||||
@@ -289,7 +292,11 @@ exports.newUserBot = function newUserBot(BOT, COMMONS, UTILITIES, DEBUG_MODULE,
|
||||
|
||||
if (FULL_LOG === true) { logger.write("[INFO] start -> buildLRCPoints -> advanceTime -> Entering function."); }
|
||||
|
||||
<<<<<<< HEAD
|
||||
executionTime = new Date(lastCandles[2] + (ONE_MIN_IN_MILISECONDS*30));
|
||||
=======
|
||||
executionTime = new Date(lastCandles[10] + ONE_MIN_IN_MILISECONDS);
|
||||
>>>>>>> efa5470188c576eca370cc465a9a63946bdb4e8d
|
||||
|
||||
if (FULL_LOG === true) { logger.write("[INFO] start -> buildLRCPoints -> advanceTime -> New processing time @ " + executionTime.toISOString()); }
|
||||
|
||||
@@ -324,7 +331,11 @@ exports.newUserBot = function newUserBot(BOT, COMMONS, UTILITIES, DEBUG_MODULE,
|
||||
isTimeToRun();
|
||||
|
||||
function isTimeToRun() {
|
||||
<<<<<<< HEAD
|
||||
let nextExecution = lastCandles[2] + outputPeriod;
|
||||
=======
|
||||
let nextExecution = lastCandles[n] + outputPeriod;
|
||||
>>>>>>> efa5470188c576eca370cc465a9a63946bdb4e8d
|
||||
if (executionTime.valueOf() >= nextExecution) {
|
||||
getLRCPoints();
|
||||
} else {
|
||||
@@ -597,7 +608,11 @@ exports.newUserBot = function newUserBot(BOT, COMMONS, UTILITIES, DEBUG_MODULE,
|
||||
}
|
||||
|
||||
// We keep a record of the last candle used for the time period
|
||||
<<<<<<< HEAD
|
||||
lastCandles[2] = lrcPoint[0];
|
||||
=======
|
||||
lastCandles[n] = lrcPoint[0];
|
||||
>>>>>>> efa5470188c576eca370cc465a9a63946bdb4e8d
|
||||
|
||||
controlLoop();
|
||||
}
|
||||
@@ -626,7 +641,11 @@ exports.newUserBot = function newUserBot(BOT, COMMONS, UTILITIES, DEBUG_MODULE,
|
||||
}
|
||||
|
||||
// We keep a record of the last candle used for the time period
|
||||
<<<<<<< HEAD
|
||||
lastCandles[2] = lrcPoint[0];
|
||||
=======
|
||||
lastCandles[n] = lrcPoint[0];
|
||||
>>>>>>> efa5470188c576eca370cc465a9a63946bdb4e8d
|
||||
|
||||
controlLoop();
|
||||
}
|
||||
@@ -650,7 +669,11 @@ exports.newUserBot = function newUserBot(BOT, COMMONS, UTILITIES, DEBUG_MODULE,
|
||||
loopBody();
|
||||
|
||||
} else {
|
||||
<<<<<<< HEAD
|
||||
let lastOneMinuteCandle = lastCandles[2];
|
||||
=======
|
||||
let lastOneMinuteCandle = lastCandles[10];
|
||||
>>>>>>> efa5470188c576eca370cc465a9a63946bdb4e8d
|
||||
writeDataRange(lastOneMinuteCandle, onWritten);
|
||||
|
||||
function onWritten(err) {
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
<<<<<<< HEAD
|
||||
var LRCIndicator = function (settings) {
|
||||
this.input = 'price';
|
||||
this.depth = settings;
|
||||
@@ -104,6 +105,9 @@ LRCIndicator.prototype.calculate = function (price) {
|
||||
}
|
||||
|
||||
exports.newUserBot = function newUserBot(BOT, COMMONS, UTILITIES, DEBUG_MODULE, BLOB_STORAGE) {
|
||||
=======
|
||||
exports.newUserBot = function newUserBot(BOT, COMMONS, UTILITIES, DEBUG_MODULE, BLOB_STORAGE) {
|
||||
>>>>>>> efa5470188c576eca370cc465a9a63946bdb4e8d
|
||||
const FULL_LOG = true;
|
||||
const LOG_FILE_CONTENT = false;
|
||||
const USE_PARTIAL_LAST_CANDLE = true; // When running live the last candle generated is a partial candle.
|
||||
@@ -519,9 +523,16 @@ exports.newUserBot = function newUserBot(BOT, COMMONS, UTILITIES, DEBUG_MODULE,
|
||||
|
||||
try {
|
||||
|
||||
<<<<<<< HEAD
|
||||
if (FULL_LOG === true) { logger.write("[INFO] start -> savePoint -> Entering function."); }
|
||||
|
||||
let filePath = bot.filePathRoot + "/Output/LRC-Points/Multi-Period-Market/" + folderName;
|
||||
=======
|
||||
if (FULL_LOG === true) { logger.write("[INFO] start -> saveChannel -> Entering function."); }
|
||||
let fileContent;
|
||||
let datePath = executionTime.getUTCFullYear() + "/" + utilities.pad(executionTime.getUTCMonth() + 1, 2) + "/" + utilities.pad(executionTime.getUTCDate(), 2);
|
||||
let filePath = bot.filePathRoot + "/Output/LRC-Points/Multi-Period-Daily/" + folderName + "/" + datePath;
|
||||
>>>>>>> efa5470188c576eca370cc465a9a63946bdb4e8d
|
||||
let fileName = market.assetA + '_' + market.assetB + ".json"
|
||||
|
||||
if (FULL_LOG === true) { logger.write("[INFO] start -> buildLRCPoints -> periodsLoop -> loopBody -> getCurrentContent -> fileName = " + fileName); }
|
||||
@@ -712,3 +723,114 @@ exports.newUserBot = function newUserBot(BOT, COMMONS, UTILITIES, DEBUG_MODULE,
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
/*
|
||||
* Linear regression curve. SRC: Gekko
|
||||
*/
|
||||
|
||||
//var log = require('../../core/log');
|
||||
|
||||
var LRCIndicator = function (settings) {
|
||||
this.input = 'price';
|
||||
this.depth = settings;
|
||||
this.result = false;
|
||||
this.age = 0;
|
||||
this.history = [];
|
||||
this.x = [];
|
||||
/*
|
||||
* Do not use array(depth) as it might not be implemented
|
||||
*/
|
||||
for (var i = 0; i < this.depth; i++) {
|
||||
this.history.push(0.0);
|
||||
this.x.push(i);
|
||||
}
|
||||
|
||||
// log.debug("Created LRC indicator with h: ", this.depth);
|
||||
}
|
||||
|
||||
LRCIndicator.prototype.update = function (price) {
|
||||
// We need sufficient history to get the right result.
|
||||
if (this.result === false && this.age < this.depth) {
|
||||
|
||||
this.history[this.age] = price;
|
||||
this.age++;
|
||||
this.result = false;
|
||||
// log.debug("Waiting for sufficient age: ", this.age, " out of ", this.depth);
|
||||
return;
|
||||
}
|
||||
|
||||
this.age++;
|
||||
// shift history
|
||||
for (var i = 0; i < (this.depth - 1); i++) {
|
||||
this.history[i] = this.history[i + 1];
|
||||
}
|
||||
this.history[this.depth - 1] = price;
|
||||
|
||||
this.calculate(price);
|
||||
|
||||
// log.debug("Checking LRC: ", this.result.toFixed(8), "\tH: ", this.age);
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* Least squares linear regression fitting.
|
||||
*/
|
||||
function linreg(values_x, values_y) {
|
||||
var sum_x = 0;
|
||||
var sum_y = 0;
|
||||
var sum_xy = 0;
|
||||
var sum_xx = 0;
|
||||
var count = 0;
|
||||
|
||||
/*
|
||||
* We'll use those variables for faster read/write access.
|
||||
*/
|
||||
var x = 0;
|
||||
var y = 0;
|
||||
var values_length = values_x.length;
|
||||
|
||||
if (values_length != values_y.length) {
|
||||
throw new Error('The parameters values_x and values_y need to have same size!');
|
||||
}
|
||||
|
||||
/*
|
||||
* Nothing to do.
|
||||
*/
|
||||
if (values_length === 0) {
|
||||
return [[], []];
|
||||
}
|
||||
|
||||
/*
|
||||
* Calculate the sum for each of the parts necessary.
|
||||
*/
|
||||
for (var v = 0; v < values_length; v++) {
|
||||
x = values_x[v];
|
||||
y = values_y[v];
|
||||
sum_x += x;
|
||||
sum_y += y;
|
||||
sum_xx += x * x;
|
||||
sum_xy += x * y;
|
||||
count++;
|
||||
}
|
||||
|
||||
/*
|
||||
* Calculate m and b for the formula: y = x * m + b
|
||||
*
|
||||
*/
|
||||
var m = (count * sum_xy - sum_x * sum_y) / (count * sum_xx - sum_x * sum_x);
|
||||
var b = (sum_y / count) - (m * sum_x) / count;
|
||||
|
||||
return [m, b];
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Handle calculations
|
||||
*/
|
||||
LRCIndicator.prototype.calculate = function (price) {
|
||||
// get the reg
|
||||
var reg = linreg(this.x, this.history);
|
||||
|
||||
// y = a * x + b
|
||||
this.result = ((this.depth - 1) * reg[0]) + reg[1];
|
||||
}
|
||||
@@ -11,8 +11,13 @@
|
||||
"dataSetVersion": "dataSet.V1",
|
||||
"processes": [
|
||||
{
|
||||
<<<<<<< HEAD
|
||||
"name": "Multi-Period-Market",
|
||||
"description": "Produces files with the LRC Points for the entire market.",
|
||||
=======
|
||||
"name": "Multi-Period-Daily",
|
||||
"description": "Produces files with the LRC Points on a daily format.",
|
||||
>>>>>>> efa5470188c576eca370cc465a9a63946bdb4e8d
|
||||
"startMode": {
|
||||
"allMonths": {
|
||||
"run": "false",
|
||||
@@ -39,6 +44,7 @@
|
||||
"statusDependencies": [
|
||||
{
|
||||
"devTeam": "AAVikings",
|
||||
<<<<<<< HEAD
|
||||
"bot": "AAGauss",
|
||||
"botVersion": {
|
||||
"major": 1,
|
||||
@@ -88,6 +94,8 @@
|
||||
"statusDependencies": [
|
||||
{
|
||||
"devTeam": "AAVikings",
|
||||
=======
|
||||
>>>>>>> efa5470188c576eca370cc465a9a63946bdb4e8d
|
||||
"bot": "AAGauss",
|
||||
"botVersion": {
|
||||
"major": 1,
|
||||
@@ -126,7 +134,11 @@
|
||||
{
|
||||
"codeName": "Multi-Period-Daily",
|
||||
"type": "Daily Files",
|
||||
<<<<<<< HEAD
|
||||
"validPeriods": [ "30-min" ],
|
||||
=======
|
||||
"validPeriods": [ "45-min", "40-min", "30-min", "20-min", "15-min", "10-min", "05-min", "04-min", "03-min", "02-min", "01-min" ],
|
||||
>>>>>>> efa5470188c576eca370cc465a9a63946bdb4e8d
|
||||
"filePath": "AAVikings/AAGauss.1.0/AACloud.1.1/@Exchange/dataSet.V1/Output/LRC-Points/Multi-Period-Daily/@Period/@Year/@Month/@Day",
|
||||
"fileName": "@AssetA_@AssetB.json",
|
||||
"dataRange": {
|
||||
|
||||
Reference in new issue
Block a user