dynamic start date and end date

This commit is contained in:
Luis Fernando Molina committed 2019-03-18 15:44:03 +01:00
1 parent 3c733dace8
commit 9b6a8073bd
4 files changed
+157 -14

No files matched your search

+131 -5
View File
@@ -1,4 +1,7 @@
exports.newCommons = function newCommons(bot, logger, UTILITIES) {
const axios = require('axios')
const auth = require('./utils/auth')
exports.newCommons = function newCommons(bot, logger, UTILITIES) {
const FULL_LOG = true;
const LOG_FILE_CONTENT = false;
@@ -41,12 +44,14 @@
candles = [];
}
function runSimulation(
async function runSimulation(
recordsArray,
conditionsArray,
lastObjectsArray,
simulationLogic,
timePeriod,
startDate,
endDate,
callback) {
try {
@@ -55,7 +60,7 @@
/* Initial Values */
let initialDate = new Date("2015-07-01");
let initialDate = startDate;
let initialBalanceA = 1;
let minimunBalanceA = 0.5;
@@ -106,6 +111,9 @@
let initialBuffer = 3;
simulationLogic.strategies = await getStrategy();
/*
simulationLogic.strategies = [
{
name: "Trend Following",
@@ -460,7 +468,7 @@
}
}
];
*/
/* Main Simulation Loop: We go thourgh all the candles at this time period. */
for (let i = 0 + initialBuffer; i < candles.length; i++) {
@@ -1242,4 +1250,122 @@
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
}
}
};
async function getStrategy() {
try {
const accessToken = await auth.authenticate()
const strategizerResponse = await axios({
url: process.env.GATEWAY_ENDPOINT,
method: 'post',
data: {
query: `
query($fbSlug: String!){
strategizer_StrategyByFb(fbSlug: $fbSlug){
subStrategies{
name
entryPoint{
situations{
name
conditions{
name
code
}
}
}
exitPoint{
situations{
name
conditions{
name
code
}
}
}
sellPoint{
situations{
name
conditions{
name
code
}
}
}
buyPoint{
situations{
name
conditions{
name
code
}
}
}
stopLoss{
phases{
name
code
situations{
name
conditions{
name
code
}
}
}
}
buyOrder{
phases{
name
code
situations{
name
conditions{
name
code
}
}
}
}
sellOrder{
phases{
name
code
situations{
name
conditions{
name
code
}
}
}
}
}
}
}
`,
variables: {
fbSlug: bot.codeName
},
},
headers: {
authorization: 'Bearer ' + accessToken
}
})
if (strategizerResponse.data.errors)
throw new Error(strategizerResponse.data.errors[0].message)
return strategizerResponse.data.data.strategizer_StrategyByFb.subStrategies;
} catch (error) {
throw new Error('There has been an error getting the strategy to run on the simulator. Error: ' + error)
}
}
};
+3 -1
View File
@@ -54,7 +54,7 @@
}
}
function start(dataFiles, timePeriod, outputPeriodLabel, currentDay, callBackFunction) {
function start(dataFiles, timePeriod, outputPeriodLabel, currentDay, startDate, endDate, callBackFunction) {
try {
@@ -111,6 +111,8 @@
lastObjectsArray,
simulationLogic,
timePeriod,
startDate,
endDate,
writeRecordsFile)
function writeRecordsFile() {
+3 -1
View File
@@ -54,7 +54,7 @@
}
}
function start(dataFiles, timePeriod, outputPeriodLabel, callBackFunction) {
function start(dataFiles, timePeriod, outputPeriodLabel, startDate, endDate, callBackFunction) {
try {
@@ -111,6 +111,8 @@
lastObjectsArray,
simulationLogic,
timePeriod,
startDate,
endDate,
writeRecordsFile)
function writeRecordsFile() {
+20 -7
View File
@@ -37,6 +37,14 @@
"retryWaitTime": 10000,
"sleepWaitTime": 3600000,
"comaWaitTime": 86400000,
"framework": {
"name": "Multi-Period-Market",
"startDate": {
"fixedDate": "2018-07-01"
},
"endDate": {
}
},
"statusDependencies": [
{
"devTeam": "AAMasters",
@@ -116,8 +124,7 @@
"dataSetVersion": "dataSet.V1",
"dataSet": "Multi-Period-Market"
}
],
"framework": "Multi-Period-Market"
]
},
{
"name": "Multi-Period-Daily",
@@ -145,6 +152,15 @@
"retryWaitTime": 10000,
"sleepWaitTime": 3600000,
"comaWaitTime": 86400000,
"framework": {
"name": "Multi-Period-Daily",
"startDate": {
"fixedDate": "2018-07-01"
},
"endDate": {
"takeItFromStatusDependency": 1
}
},
"statusDependencies": [
{
"devTeam": "AAMasters",
@@ -177,8 +193,6 @@
"dataSetVersion": "dataSet.V1"
}
],
"statusDependenciesIndexBegingOfMarket": 0,
"statusDependenciesIndexEndOfMarket": 1,
"dataDependencies": [
{
"devTeam": "AAVikings",
@@ -246,8 +260,7 @@
"dataSetVersion": "dataSet.V1",
"dataSet": "Multi-Period-Market"
}
],
"framework": "Multi-Period-Daily"
]
}
],
"products": [
@@ -288,7 +301,7 @@
}
},
{
"codeName": "SimulationConditions",
"codeName": "Simulation-Conditions",
"displayName": "Simulation Conditions",
"description": "Simulation Conditions",
"storageAccount": "aajason",