Commit a59e3c7d authored by Ahmad Nemati's avatar Ahmad Nemati

init

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