Commit a59e3c7d authored by Ahmad Nemati's avatar Ahmad Nemati

init

parent d395f94c
......@@ -3,7 +3,7 @@ let moment = require('moment-timezone')
let plus = 'plus'
let zarib = 'zarib'
let base='base'
let base = 'base'
function run(data, config) {
......@@ -19,27 +19,27 @@ function run(data, config) {
let reserv = 0
let profit = 0
let lastCom = 0
let lastMoney=0
let lastMoney = 0
for (let i = 0; i < data.length; i++) {
if (step === 0)
money = config.base
else {
if (config.type === zarib)
money=lastMoney * config.param
if (config.type === zarib)
money = lastMoney * config.param
if (config.type === base)
money = config.base * config.param * step
else if (config.type === plus)
money = config.base *(step+1)
money = config.base * (step + 1)
}
let d = inlineCheck(money, commision, data[i], profit, lastCom,config.target)
let d = inlineCheck(money, commision, data[i], profit, lastCom, config.target)
if (Math.abs(d.reserve) > Math.abs(maxReserve))
maxReserve = d.reserve
// console.log(maxAllocatedMoney)
// console.log(maxAllocatedMoney)
if (money > maxAllocatedMoney)
maxAllocatedMoney = money
......@@ -54,76 +54,73 @@ function run(data, config) {
reserv = 0
profit = 0
lastCom = 0
lastMoney=0
lastMoney = 0
total++
} else {
step++
profit = profit + d.profit
lastMoney=d.lastMoney
lastMoney = d.lastMoney
lastCom = lastCom + d.com
}
}
let dur = getMinDiff(data[0].openDate, data[data.length - 1].closeDate)
let totalFinal=total* config.target
let newT=totalFinal/dur
let totalFinal = total * config.target
let newT = totalFinal / dur
let percentage = maxReserve + totalFinal
percentage = maxAllocatedMoney / percentage
percentage = maxAllocatedMoney / percentage
let minus = 0
if (percentage < 0) {
minus = percentage
percentage = null
}
let profitPerMonth=(newT * 30 * 100)/maxAllocatedMoney
let profitPerMonth = (newT * 30 * 100) / maxAllocatedMoney
// let percentage2 = maxReserve + newT
// percentage2 = maxAllocatedMoney / percentage2
// let minus2 = 0
// if (percentage2 < 0) {
// minus2 = percentage2
// percentage2 = null
// }
// let percentage2 = maxReserve + newT
// percentage2 = maxAllocatedMoney / percentage2
// let minus2 = 0
// if (percentage2 < 0) {
// minus2 = percentage2
// percentage2 = null
// }
let perp=(config.target * 100)/Math.abs(maxAllocatedMoney)
perp=perp/100
let sum=Math.abs(maxAllocatedMoney)
for (let i=0;i<total;i++)
sum = sum + (sum* perp)
let newCompund=sum/dur
let perp = (config.target * 100) / Math.abs(maxAllocatedMoney)
perp = perp / 100
let sum = Math.abs(maxAllocatedMoney)
for (let i = 0; i < total; i++)
sum = sum + (sum * perp)
let newCompund = sum / dur
let compoundPerMonth=(newCompund * 30 * 100)/Math.abs(maxAllocatedMoney)
let compoundPerMonth = (newCompund * 30 * 100) / Math.abs(maxAllocatedMoney)
let opt = {
platform: data[0].signal,
type: config.type + ' param:' + config.param + ' base:' + config.base +' target:'+config.target,
type: config.type + ' param:' + config.param + ' base:' + config.base + ' target:' + config.target,
total: total,
avgLevel: maxLevel / total,
maxLevel: maxLevel,
dur:dur,
totalFinal:totalFinal,
totalCompound:sum,
profitPerMonth:Math.abs(profitPerMonth),
compoundPerMonth:compoundPerMonth,
dur: dur,
totalFinal: totalFinal,
totalCompound: sum,
profitPerMonth: Math.abs(profitPerMonth),
compoundPerMonth: compoundPerMonth,
maxAllocatedMoney: maxAllocatedMoney,
avgAllocatedMoney: maxAllocatedMoney / total,
drawDown: Math.abs(((maxReserve * 100) / maxAllocatedMoney)),
maxReseve: maxReserve,
avgReserve: maxReserve / total,
percentage: percentage,
avgProfitPerDay:newT,
allocatedReserve:(maxAllocatedMoney)/Math.abs(maxReserve),
avgProfitPerDay: newT,
allocatedReserve: (maxAllocatedMoney) / Math.abs(maxReserve),
minus: minus,
}
......@@ -143,7 +140,7 @@ function percentage2(base, per) {
}
function inlineCheck(money, com, data, profit, lastCom,tar) {
function inlineCheck(money, com, data, profit, lastCom, tar) {
// console.log(profit)
com = com * money
......@@ -163,7 +160,7 @@ function inlineCheck(money, com, data, profit, lastCom,tar) {
if (percentage(money, data.runUp) > target)
return {done: true, reserve: diff}
else
return {done: false, reserve: diff, profit: profitMoney, com: com,lastMoney:money}
return {done: false, reserve: diff, profit: profitMoney, com: com, lastMoney: money}
}
......
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