Commit a910328e authored by Ahmad Nemati's avatar Ahmad Nemati

init

parent 39a99808
let fs = require('fs')
let _ = require('lodash')
let drawDown=[30,40,50]
let sort = 'profitPerMonth'
let alocatedReserve = 3
let alocatedReserveCompound = 3
......@@ -30,16 +30,29 @@ async function work() {
let timestamp = Date.now()
try {
await fs.mkdirSync('last1000/' + timestamp)
await fs.mkdirSync('last1000/' + timestamp+'/default')
for (let z=0;i<drawDown.length;z++)
await fs.mkdirSync('last1000/' + timestamp+'/drawDown'+drawDown[z])
} catch (e) {
}
run('profitPerMonth1000', arr, timestamp)
run('default','compound1000', arr, timestamp)
run('default','compound1000Start', arr, timestamp)
run('default','profitPerMonth1000', arr, timestamp)
generateByDrawDown(timestamp,arr)
await run('default','profitPerMonth1000Start', arr, timestamp)
// run('percentage1000', arr, timestamp)
run('compound1000', arr, timestamp)
run('profitPerMonth1000Start', arr, timestamp)
await run('compound1000Start', arr, timestamp)
// run('profitPerMonth1000', arr, timestamp)
//
//
// // run('percentage1000', arr, timestamp)
// run('compound1000', arr, timestamp)
// run('profitPerMonth1000Start', arr, timestamp)
// await run('compound1000Start', arr, timestamp)
// run('allocatedReservePerMonthUnder2', arr, timestamp)
// await run('allocatedReserveCompoundUnder2', arr, timestamp)
}
......@@ -48,17 +61,30 @@ async function work() {
}
}
async function run(name, directory, timestamp) {
async function generateByDrawDown(timestamp,arr)
{
for (let i=0;i<drawDown.length;i++)
{
run('drawDown'+drawDown[i],'compound1000DrawDown'+drawDown[i], arr, timestamp)
run('drawDown'+drawDown[i],'compound1000StartDrawDown'+drawDown[i], arr, timestamp)
run('drawDown'+drawDown[i],'profitPerMonth1000DrawDown'+drawDown[i], arr, timestamp)
await run('drawDown'+drawDown[i],'profitPerMonth1000StartDrawDown'+drawDown[i], arr, timestamp)
}
}
async function run(root,name, directory, timestamp) {
// let directory = await fs.readdirSync('result')
let arr2 = []
let arrFinal = []
let last = []
console.log(directory)
// console.log(directory)
for (let f = 0; f < directory.length; f++) {
if (typeof directory[f] === "undefined")
continue
console.log(directory[f])
arrFinal.push(readFile(name, directory[f]))
arrFinal.push(readFile(root,name, directory[f]))
}
......@@ -77,14 +103,14 @@ async function run(name, directory, timestamp) {
// console.log(arr2)
if (name === 'profitPerMonth1000' || name === 'allocatedReservePerMonthUnder3' || name === 'allocatedReservePerMonthUnder2' || name === 'profitPerMonth1000Start')
let t=name.toLowerCase()
if (t.includes('per') || name === 'profitPerMonth1000' || name === 'allocatedReservePerMonthUnder3' || name === 'allocatedReservePerMonthUnder2' || name === 'profitPerMonth1000Start')
last = _.orderBy(arr2, ['profitPerMonthDrawDown'], ['desc']);
// if (name === 'percentage1000')
// last = _.orderBy(arr2, ['percentage'], ['asc']);
if (name === 'compound1000' || name === 'allocatedReserveCompoundUnder3' || name === 'allocatedReserveCompoundUnder2' || name === 'compound1000Start')
if (t.includes('compound') || name === 'compound1000' || name === 'allocatedReserveCompoundUnder3' || name === 'allocatedReserveCompoundUnder2' || name === 'compound1000Start')
last = _.orderBy(arr2, ['CompoundPerMonthDrawDown'], ['desc']);
......@@ -127,15 +153,15 @@ async function run(name, directory, timestamp) {
}
createfileADV(timestamp, name, JSON.stringify(las, null, 2))
createfileADV(root,timestamp, name, JSON.stringify(las, null, 2))
last = []
}
async function readFile(name, directory) {
async function readFile(root,name, directory) {
let sortByProfit = []
let file = await fs.readFileSync('./result/' + directory + '/' + name + '.json', 'utf8')
let file = await fs.readFileSync('./result/' + directory + '/'+root+'/' + name + '.json', 'utf8')
file = JSON.parse(file)
// file = _.orderBy(file, sort, ['desc']);
......@@ -151,9 +177,9 @@ async function readFile(name, directory) {
return file
}
function createfileADV(timestamp, filename, data) {
function createfileADV(root,timestamp, filename, data) {
return new Promise(function (resolve, reject) {
fs.writeFile('last1000/' + timestamp + '/' + filename + '.json', data, 'utf8', function (err) {
fs.writeFile('last1000/' + timestamp + '/'+root+'/' + filename + '.json', data, 'utf8', function (err) {
if (err) reject(err);
else resolve(data);
});
......
let fs = require('fs')
let _ = require('lodash')
let drawDown=[30,40,50]
let sort = 'profitPerMonth'
let alocatedReserve = 3
let alocatedReserveCompound = 3
......@@ -30,43 +30,70 @@ async function work() {
let timestamp = Date.now()
try {
await fs.mkdirSync('final1000/' + timestamp)
await fs.mkdirSync('final1000/' + timestamp+'/default')
for (let z=0;i<drawDown.length;z++)
await fs.mkdirSync('final1000/' + timestamp+'/drawDown'+drawDown[z])
} catch (e) {
}
run('profitPerMonth1000', arr, timestamp)
// run('percentage1000', arr, timestamp)
run('compound1000', arr, timestamp)
run('profitPerMonth1000Start', arr, timestamp)
await run('compound1000Start', arr, timestamp)
// run('allocatedReservePerMonthUnder3', arr, timestamp)
// run('allocatedReserveCompoundUnder3', arr, timestamp)
// run('allocatedReservePerMonthUnder2', arr, timestamp)
// await run('allocatedReserveCompoundUnder2', arr, timestamp)
run('default','compound1000', arr, timestamp)
run('default','compound1000Start', arr, timestamp)
run('default','profitPerMonth1000', arr, timestamp)
generateByDrawDown(timestamp,arr)
await run('default','profitPerMonth1000Start', arr, timestamp)
// run('profitPerMonth1000', arr, timestamp)
//
//
// // run('percentage1000', arr, timestamp)
// run('compound1000', arr, timestamp)
// run('profitPerMonth1000Start', arr, timestamp)
// await run('compound1000Start', arr, timestamp)
// run('allocatedReservePerMonthUnder2', arr, timestamp)
// await run('allocatedReserveCompoundUnder2', arr, timestamp)
}
}
}
async function run(name, directory, timestamp) {
// let directory = await fs.readdirSync('result')
async function generateByDrawDown(timestamp,arr)
{
for (let i=0;i<drawDown.length;i++)
{
run('drawDown'+drawDown[i],'compound1000DrawDown'+drawDown[i], arr, timestamp)
run('drawDown'+drawDown[i],'compound1000StartDrawDown'+drawDown[i], arr, timestamp)
run('drawDown'+drawDown[i],'profitPerMonth1000DrawDown'+drawDown[i], arr, timestamp)
await run('drawDown'+drawDown[i],'profitPerMonth1000StartDrawDown'+drawDown[i], arr, timestamp)
}
}
async function run(root,name, directory, timestamp) {
// let directory = await fs.readdirSync('last1000')
let arr2 = []
let arrFinal = []
let last = []
console.log(directory)
// console.log(directory)
for (let f = 0; f < directory.length; f++) {
if (typeof directory[f] === "undefined")
continue
console.log(directory[f])
arrFinal.push(readFile(name, directory[f]))
// console.log(directory[f])
arrFinal.push(readFile(root,name, directory[f]))
}
arrFinal = await Promise.all(arrFinal)
for (let i = 0; i < arrFinal.length; i++) {
let inline = arrFinal[i]
// console.log(inline)
for (let z = 0; z < inline.length; z++)
......@@ -74,15 +101,20 @@ async function run(name, directory, timestamp) {
}
if (name === 'profitPerMonth1000' || name === 'allocatedReservePerMonthUnder3' || name === 'allocatedReservePerMonthUnder2' || name === 'profitPerMonth1000Start')
// console.log(arr2)
let t=name.toLowerCase()
if (t.includes('per') || name === 'profitPerMonth1000' || name === 'allocatedReservePerMonthUnder3' || name === 'allocatedReservePerMonthUnder2' || name === 'profitPerMonth1000Start')
last = _.orderBy(arr2, ['profitPerMonthDrawDown'], ['desc']);
// if (name === 'percentage1000')
// last = _.orderBy(arr2, ['percentage'], ['asc']);
if (name === 'compound1000' || name === 'allocatedReserveCompoundUnder3' || name === 'allocatedReserveCompoundUnder2' || name === 'compound1000Start')
if (t.includes('compound') || name === 'compound1000' || name === 'allocatedReserveCompoundUnder3' || name === 'allocatedReserveCompoundUnder2' || name === 'compound1000Start')
last = _.orderBy(arr2, ['CompoundPerMonthDrawDown'], ['desc']);
// if (name === 'allocatedReservePerMonthUnder2' || name === 'allocatedReservePerMonthUnder3') {
// let arr20Max = []
// for (let i = 0; i < last.length; i++) {
......@@ -112,7 +144,7 @@ async function run(name, directory, timestamp) {
//
// last = arr20Max
// }
//
let las = []
for (let i = 0; i < 1000; i++) {
......@@ -121,42 +153,33 @@ async function run(name, directory, timestamp) {
}
createfileADV(timestamp, name, JSON.stringify(las, null, 2))
createfileADV(root,timestamp, name, JSON.stringify(las, null, 2))
last = []
}
async function readFile(name, directory) {
async function readFile(root,name, directory) {
let sortByProfit = []
let file = await fs.readFileSync('./last1000/' + directory + '/' + name + '.json', 'utf8')
let file = await fs.readFileSync('./last1000/' + directory + '/'+root+'/' + name + '.json', 'utf8')
file = JSON.parse(file)
// file = _.orderBy(file, sort, ['desc']);
for (let j = 0; j < file.length; j++) {
sortByProfit.push(file[j])
}
// let sortByPercentage = []
// file = _.orderBy(file, ['percentage'], ['asc']);
// for (let j = 0; j < file.length; j++) {
//
// sortByPercentage.push(file[j])
// }
//
// let sortByCompound = []
// file =_.orderBy(file, ['compoundPerMonth'], ['desc']);
// for (let j = 0; j < file.length; j++) {
//
// sortByCompound.push(file[j])
// }
return file
}
function createfileADV(timestamp, filename, data) {
function createfileADV(root,timestamp, filename, data) {
return new Promise(function (resolve, reject) {
fs.writeFile('final1000/' + timestamp + '/' + filename + '.json', data, 'utf8', function (err) {
fs.writeFile('final1000/' + timestamp + '/'+root+'/' + filename + '.json', data, 'utf8', function (err) {
if (err) reject(err);
else resolve(data);
});
......
let target = 20
let maxReserve = 300
let total = 2
let fs = require('fs')
let _ = require('lodash')
let perp = (target * 100) / Math.abs(maxReserve)
perp=perp/100
let drawDown=[30,40,50]
let sort = 'profitPerMonth'
let alocatedReserve = 3
let alocatedReserveCompound = 3
let sum = Math.abs(maxReserve)
for (let i = 0; i < total; i++)
sum = sum + (sum* perp)
work()
console.log(sum)
async function work() {
let directory = await fs.readdirSync('last1000')
for (let i = 0; i < directory.length; i = i + 1000) {
// console.log('hi')
let arr = []
for (let j = 0; j < 1000; j++) {
try {
if ((j + i) < directory.length)
arr.push(directory[j + i])
} catch (e) {
function percentage2(base, per) {
}
base = parseFloat(base)
per = parseFloat(per)
let percentager = per / 100
let temp = base * percentager
return base + temp
}
if (arr.length !== 0) {
let timestamp = Date.now()
try {
await fs.mkdirSync('final1000/' + timestamp)
await fs.mkdirSync('final1000/' + timestamp+'/default')
for (let z=0;i<drawDown.length;z++)
await fs.mkdirSync('final1000/' + timestamp+'/drawDown'+drawDown[z])
} catch (e) {
}
run('default','compound1000', arr, timestamp)
run('default','compound1000Start', arr, timestamp)
run('default','profitPerMonth1000', arr, timestamp)
generateByDrawDown(timestamp,arr)
await run('default','profitPerMonth1000Start', arr, timestamp)
// run('profitPerMonth1000', arr, timestamp)
//
//
// // run('percentage1000', arr, timestamp)
// run('compound1000', arr, timestamp)
// run('profitPerMonth1000Start', arr, timestamp)
// await run('compound1000Start', arr, timestamp)
// run('allocatedReservePerMonthUnder2', arr, timestamp)
// await run('allocatedReserveCompoundUnder2', arr, timestamp)
}
}
}
async function generateByDrawDown(timestamp,arr)
{
for (let i=0;i<drawDown.length;i++)
{
run('drawDown'+drawDown[i],'compound1000DrawDown'+drawDown[i], arr, timestamp)
run('drawDown'+drawDown[i],'compound1000StartDrawDown'+drawDown[i], arr, timestamp)
run('drawDown'+drawDown[i],'profitPerMonth1000DrawDown'+drawDown[i], arr, timestamp)
await run('drawDown'+drawDown[i],'profitPerMonth1000StartDrawDown'+drawDown[i], arr, timestamp)
}
}
async function run(root,name, directory, timestamp) {
// let directory = await fs.readdirSync('last1000')
let arr2 = []
let arrFinal = []
let last = []
// console.log(directory)
for (let f = 0; f < directory.length; f++) {
if (typeof directory[f] === "undefined")
continue
console.log(directory[f])
arrFinal.push(readFile(root,name, directory[f]))
}
arrFinal = await Promise.all(arrFinal)
for (let i = 0; i < arrFinal.length; i++) {
let inline = arrFinal[i]
// console.log(inline)
for (let z = 0; z < inline.length; z++)
arr2.push(inline[z])
}
// console.log(arr2)
let t=name.toLowerCase()
if (t.includes('per') || name === 'profitPerMonth1000' || name === 'allocatedReservePerMonthUnder3' || name === 'allocatedReservePerMonthUnder2' || name === 'profitPerMonth1000Start')
last = _.orderBy(arr2, ['profitPerMonthDrawDown'], ['desc']);
// if (name === 'percentage1000')
// last = _.orderBy(arr2, ['percentage'], ['asc']);
if (t.includes('compound') || name === 'compound1000' || name === 'allocatedReserveCompoundUnder3' || name === 'allocatedReserveCompoundUnder2' || name === 'compound1000Start')
last = _.orderBy(arr2, ['CompoundPerMonthDrawDown'], ['desc']);
// if (name === 'allocatedReservePerMonthUnder2' || name === 'allocatedReservePerMonthUnder3') {
// let arr20Max = []
// for (let i = 0; i < last.length; i++) {
// if (name === 'allocatedReservePerMonthUnder2')
// alocatedReserve = 2
// else
// alocatedReserve = 3
//
// if (last[i].allocatedReserve < alocatedReserve)
// arr20Max.push(last[i])
// }
//
// last = arr20Max
// }
//
// if (name === 'allocatedReserveCompoundUnder2' || name === 'allocatedReserveCompoundUnder3') {
// let arr20Max = []
// for (let i = 0; i < last.length; i++) {
// if (name === 'allocatedReserveCompoundUnder2')
// alocatedReserve = 2
// else
// alocatedReserve = 3
//
// if (last[i].allocatedReserve < alocatedReserve)
// arr20Max.push(last[i])
// }
//
// last = arr20Max
// }
//
let las = []
for (let i = 0; i < 1000; i++) {
if (i < last.length)
las.push(last[i])
}
createfileADV(root,timestamp, name, JSON.stringify(las, null, 2))
last = []
}
async function readFile(root,name, directory) {
let sortByProfit = []
let file = await fs.readFileSync('./last1000/' + directory + '/'+root+'/' + name + '.json', 'utf8')
file = JSON.parse(file)
// file = _.orderBy(file, sort, ['desc']);
for (let j = 0; j < file.length; j++) {
sortByProfit.push(file[j])
}
return file
}
function createfileADV(root,timestamp, filename, data) {
return new Promise(function (resolve, reject) {
fs.writeFile('final1000/' + timestamp + '/'+root+'/' + filename + '.json', data, 'utf8', function (err) {
if (err) reject(err);
else resolve(data);
});
});
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment