Commit 8bc75bc0 authored by Ahmad Nemati's avatar Ahmad Nemati

init

parent 7a99f950
let moment = require('moment-timezone')
let plus = 'plus'
let zarib = 'zarib'
let plus='plus'
let zarib='zarib'
function run(data,config) {
function run(data, config) {
let commision = config.commision
let money = config.base
let total = 0
......@@ -18,22 +15,21 @@ let zarib='zarib'
// console.log(data)
let step = 0
let reserv=0
let profit=0
let lastCom=0
let reserv = 0
let profit = 0
let lastCom = 0
for (let i = 0; i < data.length; i++) {
if (step === 0)
money = config.base
else
{
if (config.type ===zarib)
else {
if (config.type === zarib)
money = config.base * config.param * step
else if (config.type ===plus)
money = config.base +(config.param * step)
else if (config.type === plus)
money = config.base + (config.param * step)
}
let d = inlineCheck(money, commision, data[i],profit,lastCom)
let d = inlineCheck(money, commision, data[i], profit, lastCom)
if (Math.abs(d.reserve) > Math.abs(maxReserve))
......@@ -41,54 +37,70 @@ let zarib='zarib'
if (money > maxAllocatedMoney)
maxAllocatedMoney = money
// console.log(data[i])
// console.log( 'step->'+step)
// console.log(d)
// console.log(data[i])
// console.log( 'step->'+step)
// console.log(d)
if (step>maxLevel)
maxLevel=step
if (step > maxLevel)
maxLevel = step
if (d.done === true) {
step = 0
reserv=0
profit=0
lastCom=0
reserv = 0
profit = 0
lastCom = 0
total++
} else {
step++
profit=profit+d.profit
lastCom=lastCom+d.com
profit = profit + d.profit
lastCom = lastCom + d.com
}
}
let percentage=maxReserve+total
percentage=maxAllocatedMoney/percentage
let minus=0
if (percentage<0) {
minus=percentage
let dur = getMinDiff(data[0].openDate, data[data.length - 1].closeDate)
let newT=total/dur
let percentage = maxReserve + total
percentage = maxAllocatedMoney / percentage
let minus = 0
if (percentage < 0) {
minus = percentage
percentage = null
}
// let percentage2 = maxReserve + newT
// percentage2 = maxAllocatedMoney / percentage2
// let minus2 = 0
// if (percentage2 < 0) {
// minus2 = percentage2
// percentage2 = null
// }
let opt = {
platform: data[0].signal,
type:config.type +' param:'+config.param+' base:'+config.base,
type: config.type + ' param:' + config.param + ' base:' + config.base,
total: total,
avgLevel: maxLevel/total,
avgLevel: maxLevel / total,
maxLevel: maxLevel,
dur:dur,
maxAllocatedMoney: maxAllocatedMoney,
avgAllocatedMoney: maxAllocatedMoney/total,
avgAllocatedMoney: maxAllocatedMoney / total,
maxReseve: maxReserve,
avgReserve: maxReserve/total,
percentage:percentage,
minus:minus
avgReserve: maxReserve / total,
percentage: percentage,
avgProfitPerDay:newT,
minus: minus,
}
}
return opt
......@@ -98,27 +110,27 @@ let zarib='zarib'
}
function inlineCheck(money, com, data,profit,lastCom) {
function inlineCheck(money, com, data, profit, lastCom) {
// console.log(profit)
com = com * money
let target = money +Math.abs(profit)+ com+lastCom + 1
let target = money + Math.abs(profit) + com + lastCom + 1
let reserve = percentage(money, data.drawDown)
let profitMoney = percentageMinus(money, data.profit)
let diff=reserve - money
diff=diff-com-lastCom+profit
let diff = reserve - money
diff = diff - com - lastCom + profit
// console.log('reserve->'+reserve + ' money->'+money +' com->'+com +' lastCom->'+lastCom + 'profit->'+profit +' diff->'+diff)
if (percentage(money,data.runUp) > target)
if (percentage(money, data.runUp) > target)
return {done: true, reserve: diff}
else
return {done: false, reserve: diff,profit:profitMoney,com:com}
return {done: false, reserve: diff, profit: profitMoney, com: com}
}
......@@ -146,12 +158,21 @@ function percentageMinus(base, per) {
return temp
}
function getMinDiff(start, closed) {
//2019-05-25T05:34:27+04:30
var now = moment(moment(closed).tz('Asia/Tehran').format());
var end = moment.duration(now.diff(moment(start).tz('Asia/Tehran')));
// console.log(parseInt(end.asDays()))
return parseInt(end.asDays())
}
module.exports =
{
run:run,
run: run,
}
\ No newline at end of file
......@@ -5,7 +5,7 @@ let _ = require('lodash')
test()
async function test() {
let configs = await fs.readFileSync('./config.json', 'utf8')
let configs = await fs.readFileSync('./configs.json', 'utf8')
configs = JSON.parse(configs)
let arr = []
let files = await fs.readdirSync('./work')
......@@ -44,7 +44,7 @@ function createfile(data) {
async function test2() {
let configs = await fs.readFileSync('./config.json', 'utf8')
let configs = await fs.readFileSync('./configTemp.json', 'utf8')
configs = JSON.parse(configs)
console.log(configs)
}
......
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