Changing configuration

This commit is contained in:
Matias Benitez committed 2018-06-04 22:21:43 -03:00
1 parent fbe86ab8e5
commit 854331b50b
3 files changed
+83 -184

No files matched your search

-112
View File
@@ -1,112 +0,0 @@
/*
* Linear regression curve.
*/
//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];
}
module.exports = LRCIndicator;
+13 -11
View File
@@ -29,6 +29,7 @@
let key = "AAVikings-AAGauss-LRC-Points-Multi-Period-Daily-dataSet.V1";
gaussStorage = assistant.dataDependencies.dataSets.get(key);
callBackFunction(global.DEFAULT_OK_RESPONSE);
} catch (err) {
logger.write("[ERROR] initialize -> onDone -> err = " + err.message);
@@ -40,6 +41,7 @@
try {
if (LOG_INFO === true) { logger.write("[INFO] start -> Entering function."); }
let market = global.MARKET;
/*
This trading bot will use an strategy based on the interpretation of the Linear Regression Curve Channel.
@@ -128,9 +130,7 @@
if (LOG_INFO === true) { logger.write("[INFO] start -> createBuyPosition -> There is not enough available balance to buy. Available balance: " + assetABalance ); }
callBack(global.DEFAULT_OK_RESPONSE);
}
}
}
function createSellPosition(callBack) {
@@ -180,7 +180,7 @@
getLRCPointsFile(queryDate, onLRCPointsFileReceived);
function onLRCPointsFileReceived(err, lrcPointsFile) {
if (LOG_INFO === true) { logger.write("[INFO] start -> getChannelTilt -> onDailyFileReceived."); }
if (LOG_INFO === true) { logger.write("[INFO] start -> getChannelTilt -> onLRCPointsFileReceived."); }
for (let i = 0; i < lrcPointsFile.length; i++) {
@@ -210,13 +210,15 @@
getLRCPointsFile(queryDate, onPreviousLRCPointsFileReceived);
}
break;
return;
}
}
callBack(global.DEFAULT_OK_RESPONSE, NO_CHANNEL);
}
function onLRCPointsFileReceived(err, lrcPointsFile) {
if (LOG_INFO === true) { logger.write("[INFO] start -> getChannelTilt -> onDailyFileReceived."); }
function onPreviousLRCPointsFileReceived(err, lrcPointsFile) {
if (LOG_INFO === true) { logger.write("[INFO] start -> getChannelTilt -> onLRCPointsFileReceived."); }
let previous = lrcPointsFile.length - 2;
previousLRCPoint = {
@@ -270,23 +272,23 @@
}
}
function getLRCPointsFile(dateTime, onDailyFileReceived) {
function getLRCPointsFile(dateTime, callback) {
try {
if (FULL_LOG === true) { logger.write("[INFO] start -> getChannelTilt -> getLRCPointsFile -> Entering function."); }
let periodName = "30-min";
let datePath = dateTime.getUTCFullYear() + "/" + pad(dateTime.getUTCMonth() + 1, 2) + "/" + pad(dateTime.getUTCDate(), 2);
let filePath = "AAVikings/AAGauss.1.0/AACloud.1.1/Poloniex/dataSet.V1/Output/LRC-Points/Multi-Period-Daily/" + periodName + "/" + datePath;
let filePath = "LRC-Points/Multi-Period-Daily/" + periodName + "/" + datePath;
let fileName = market.assetA + '_' + market.assetB + ".json"
gaussStorage.getTextFile(pFilePath, pFileName, onFileReceived);
gaussStorage.getTextFile(filePath, fileName, onFileReceived);
function onFileReceived(err, text) {
if (err.result === global.DEFAULT_OK_RESPONSE.result) {
if (FULL_LOG === true) { logger.write("[INFO] start -> getChannelTilt -> getLRCPointsFile -> onFileReceived > Entering Function."); }
let lrcPointsFile = JSON.parse(text);
onDailyFileReceived(global.DEFAULT_OK_RESPONSE, lrcPointsFile);
callback(global.DEFAULT_OK_RESPONSE, lrcPointsFile);
} else {
logger.write("[ERROR] start -> getChannelTilt -> getLRCPointsFile -> onFileReceived -> Failed to get the file. Will abort the process and request a retry.");
callBackFunction(global.DEFAULT_RETRY_RESPONSE);