Commit 0d69cb93 authored by Ahmad Nemati's avatar Ahmad Nemati

git pull

parent 18567aac
...@@ -5,7 +5,7 @@ const uuid = require('uniqid') ...@@ -5,7 +5,7 @@ const uuid = require('uniqid')
let pair = 'BNB' let pair = 'BNB'
let res let res
let arr = [] let arr = []
let balance =10000 let balance = 10000
init() init()
//profitLossString //profitLossString
...@@ -19,96 +19,114 @@ async function init() { ...@@ -19,96 +19,114 @@ async function init() {
let profits = com[i].profitLossString.split('_') let profits = com[i].profitLossString.split('_')
let side = com[i].sideString.split('_') let side = com[i].sideString.split('_')
for (let j = 0; j < closeDate.length - 1; j++) for (let j = 0; j < closeDate.length - 1; j++)
add(closeDate[j], parseFloat(profits[j])-0.1,side[j]) add(closeDate[j], parseFloat(profits[j]) - 0.1, side[j])
} }
arr=_.orderBy(arr,['date']) arr = _.orderBy(arr, ['date'])
for (let i=0;i<arr.length;i++) for (let i = 0; i < arr.length; i++) {
{ balance = balance + arr[i].profit
balance=balance+arr[i].profit arr[i].balance = balance
arr[i].balance=balance
} }
let arrNew=[] let arrNew = []
for (let i = 0; i < arr.length; i++) { for (let i = 0; i < arr.length; i++) {
let sums = 0 let sums = 0
for (let j = i + 1; j < arr.length ; j++) { for (let j = i + 1; j < arr.length; j++) {
sums = sums + parseFloat(arr[j].profit) sums = sums + parseFloat(arr[j].profit)
if (arrNew.length ===0) if (arrNew.length === 0)
arrNew.push({sum: sums, index: i,date:arr[j].date}) arrNew.push({sum: sums, index: i, date: arr[j].date})
else if (arrNew[arrNew.length-1].sum > sums) else if (arrNew[arrNew.length - 1].sum > sums)
arrNew.push({sum: sums, index: i,date:arr[j].date}) arrNew.push({sum: sums, index: i, date: arr[j].date})
} }
} }
arrNew = _.orderBy(arrNew, ['sum']) arrNew = _.orderBy(arrNew, ['sum'])
// console.log(arr) // console.log(arr)
console.log('Balance ->',balance) console.log('Balance ->', balance)
console.log('Worth ->',arrNew[0]) console.log('Worth ->', arrNew[0])
let worth=arrNew[0].sum let worth = arrNew[0].date
console.log('Detail ->',get(arrNew[0].date)) console.log('Detail ->', get(arrNew[0].date))
let index=arrNew[0].index let index = arrNew[0].index
console.log('index',index) console.log('index', index)
arrNew=[] arrNew = []
let sums = 0 let sums = 0
for (let i = index; i < arr.length; i++) { let start = false
if (i ===index) for (let i = 0; i < arr.length; i++) {
console.log(arr[i]) if (arr[i].date === worth)
start = true
else {
if (!start)
continue
}
sums = sums + parseFloat(arr[i].profit) sums = sums + parseFloat(arr[i].profit)
// if (arrNew.length ===0) // if (arrNew.length ===0)
// arrNew.push({sum: sums, index: i,date:arr[j].date}) // arrNew.push({sum: sums, index: i,date:arr[j].date})
// else if (arrNew[arrNew.length-1].sum > sums) // else if (arrNew[arrNew.length-1].sum > sums)
arrNew.push({sum: sums, index: i,date:arr[i].date}) arrNew.push({sum: sums, index: i, date: arr[i].date})
} }
let t='' let t = ''
for (let i=0;i<arrNew.length;i++) for (let i = 0; i < arrNew.length; i++) {
{ let det = get(arrNew[i].date)
let det=get(arrNew[i].date)
if (worth ===arrNew[i].sum) if (worth === arrNew[i].sum)
t='****Worth**** ->' t = '****Worth**** ->'
t=t+arrNew[i].date t = t + arrNew[i].date
t=t+' '+' Profits-> '+arrNew[i].sum +' Count-> '+det.count +' Longs-> '+det.longCount+' Long Profit-> '+det.longProfit+' Shorts-> '+det.shortCount+' Short Profit=> '+det.shortProfit+'\n' t = t + ' ' + ' Profits-> ' + arrNew[i].sum + ' Count-> ' + det.count + ' Longs-> ' + det.longCount + ' Long Profit-> ' + det.longProfit + ' Shorts-> ' + det.shortCount + ' Short Profit=> ' + det.shortProfit + '\n'
} }
createRunResfileADV(t) createRunResfileADV(t)
// console.log(arrNew) // console.log(arrNew)
} }
function add(date, profit,side) { function add(date, profit, side) {
for (let i = 0; i < arr.length; i++) for (let i = 0; i < arr.length; i++)
if (arr[i].date === date) { if (arr[i].date === date) {
arr[i].profit = arr[i].profit + profit arr[i].profit = arr[i].profit + profit
arr[i].count++ arr[i].count++
if ( side ==='LONG') { if (side === 'LONG') {
arr[i].longCount++ arr[i].longCount++
arr[i].longProfit= arr[i].longProfit+profit arr[i].longProfit = arr[i].longProfit + profit
} } else {
else {
arr[i].shortCount++ arr[i].shortCount++
arr[i].shortProfit= arr[i].shortProfit+profit arr[i].shortProfit = arr[i].shortProfit + profit
} }
return return
} }
if ( side ==='LONG') if (side === 'LONG')
arr.push({date: date, profit: profit,count:1,longCount:1,shortCount:0,longProfit:profit,shortProfit:0}) arr.push({
date: date,
profit: profit,
count: 1,
longCount: 1,
shortCount: 0,
longProfit: profit,
shortProfit: 0
})
else else
arr.push({date: date, profit: profit,count:1,longCount:1,shortCount:1,longProfit:0,shortProfit:profit}) arr.push({
date: date,
profit: profit,
count: 1,
longCount: 1,
shortCount: 1,
longProfit: 0,
shortProfit: profit
})
} }
...@@ -119,7 +137,6 @@ function get(date) { ...@@ -119,7 +137,6 @@ function get(date) {
} }
} }
......
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