Commit 8587bc21 authored by Ahmad Nemati's avatar Ahmad Nemati

git pull

parent 3b03a34c
{"bad":2}
\ No newline at end of file
{"maxReserve":-12.310000000000004,"profit":2404.2,"bad":-195.30463038180332}
\ No newline at end of file
......@@ -71,9 +71,9 @@ let fs = require('fs')
// let arr=[]
// arr.push(t)
// arr.push(t)
// console.log(JSON.stringify(arr))
console.log(JSON.stringify({bad:1}))
test()
//test()
async function test()
{
let las = await fs.readFileSync('t.json', 'utf8');
......
......@@ -65,7 +65,7 @@ async function lastCheck(param1,param2,param3,arr5) {
if (param3<base)
{
let z={maxReserve:param1,profit:param2,bad:param3}
await createfileADV(JSON.stringify(z))
// await createfileADV(JSON.stringify(z))
await createfileTorob(param3.toString(),JSON.stringify(arr5, null, 2))
}
......@@ -89,9 +89,9 @@ async function run()
balance=lastBalance
arr=[]
for (let i = 0; i < size; i++) {
let closeDate = com[i].c.split('_')
let profits = com[i].p.split('_')
let side = com[i].s.split('_')
let closeDate = com[i].closeDate.split('_')
let profits = com[i].profitLossString.split('_')
let side = com[i].sideString.split('_')
for (let j = 0; j < closeDate.length - 1; j++)
add(closeDate[j], parseFloat(profits[j])-0.1,side[j])
......@@ -130,6 +130,7 @@ async function run()
// dates=_.orderBy(dates,['profit'])
let arrDate=[]
// console.log(dates)
for (let i = 0; i < dates.length; i++) {
let sums = 0
for (let j = i + 1; j < dates.length ; j++) {
......@@ -176,7 +177,7 @@ async function run()
balance=balance+arr2[i].profit
arr2[i].balance=balance
}
createfileADV(JSON.stringify(arr2, null, 2))
//createfileADV(JSON.stringify(arr2, null, 2))
let index=arrNew[0].index
arrNew=[]
......@@ -205,7 +206,7 @@ function add(date, profit,side) {
arr[i].profit = arr[i].profit + profit
arr[i].count++
if ( side ==='L') {
if ( side ==='LONG') {
arr[i].longCount++
arr[i].longProfit= arr[i].longProfit+profit
}
......
......@@ -5,128 +5,160 @@ const uuid = require('uniqid')
let pair = 'BNB'
let res
let arr = []
let lastBalance=5000
let size=50
let balance =lastBalance
let lastBalance = 5000
let size = 50
let balance = lastBalance
init()
let base=1
let base = 1
let com
//profitLossString
//drawDownString
let year = ['2017', '2018', '2019', '2020', '2021', '2022']
let month = ['01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12']
let dates = []
async function init() {
try {
await fs.mkdirSync('torob')
}
catch (e)
{
} catch (e) {
}
com = await fs.readFileSync('t.json', 'utf8');
let bad = await fs.readFileSync('bad.txt', 'utf8');
bad=JSON.parse(bad)
com = await fs.readFileSync('t.json', 'utf8');
let bad = await fs.readFileSync('bad.txt', 'utf8');
bad = JSON.parse(bad)
base=parseFloat(bad.bad)
console.log(bad)
base = parseFloat(bad.bad)
//console.log(bad)
com = JSON.parse(com)
run()
run()
}
async function lastCheck(param1, param2, param3, arr5) {
let bad = await fs.readFileSync('bad.txt', 'utf8');
bad = JSON.parse(bad)
base = parseFloat(bad.bad)
async function lastCheck(param1,param2,param3,arr5) {
let bad = await fs.readFileSync('bad.txt', 'utf8');
bad=JSON.parse(bad)
base=parseFloat(bad.bad)
if (param3<base)
{
let z={maxReserve:param1,profit:param2,bad:param3}
if (param3 < base) {
let z = {maxReserve: param1, profit: param2, bad: param3}
await createfileADV(JSON.stringify(z))
await createfileTorob(param3.toString(),JSON.stringify(arr5, null, 2))
await createfileTorob(param3.toString(), JSON.stringify(arr5, null, 2))
}
}
function resetDates() {
dates = []
for (let i = 0; i < year.length; i++) {
for (let j = 0; j < month.length; j++) {
let t = year[i] + '-' + month[j]
if (!(t === '2017-01' || t === '2017-02' || t === '2017-03' || t === '2017-04' || t === '2017-05' || t === '2017-06' || t === '2017-07' || t === '2022-05' || t === '2022-06' || t === '2022-07' || t === '2022-08' || t === '2022-09' || t === '2022-10' || t === '2022-11' || t === '2022-12'))
dates.push({date: t, profit: 0, count: 0, longCount: 0, shortCount: 0, longProfit: 0, shortProfit: 0})
}
}
}
async function sleep(millis) {
return new Promise(resolve => setTimeout(resolve, millis));
}
async function run()
{
com=_.shuffle(com)
balance=lastBalance
arr=[]
async function run() {
com = _.shuffle(com)
balance = lastBalance
arr = []
resetDates()
for (let i = 0; i < size; i++) {
let closeDate = com[i].c.split('_')
let profits = com[i].p.split('_')
let side = com[i].s.split('_')
let closeDate = com[i].closeDate.split('_')
let profits = com[i].profitLossString.split('_')
let side = com[i].sideString.split('_')
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++)
{
balance=balance+arr[i].profit
arr[i].balance=balance
for (let i = 0; i < arr.length; i++) {
balance = balance + arr[i].profit
arr[i].balance = balance
}
let arrNew=[]
let arrNew = []
for (let i = 0; i < arr.length; i++) {
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)
if (arrNew.length ===0)
arrNew.push({sum: sums, index: i,startDate:arr[i+1].date,date:arr[j].date})
else if (arrNew[arrNew.length-1].sum > sums)
arrNew.push({sum: sums, index: i,startDate:arr[i+1].date,date:arr[j].date})
if (arrNew.length === 0)
arrNew.push({sum: sums, index: i, startDate: arr[i + 1].date, date: arr[j].date})
else if (arrNew[arrNew.length - 1].sum > sums)
arrNew.push({sum: sums, index: i, startDate: arr[i + 1].date, date: arr[j].date})
}
}
arrNew = _.orderBy(arrNew, ['sum'])
for (let i=0;i<arr.length;i++)
addDate(arr[i])
let arrDate=[]
for (let i = 0; i < dates.length; i++) {
let sums = 0
for (let j = i + 1; j < dates.length ; j++) {
sums = sums + parseFloat(dates[j].profit)
if (arrDate.length ===0)
arrDate.push({sum: sums, index: i,startDate:dates[i+1].date,date:dates[j].date})
else if (arrDate[arrDate.length-1].sum > sums)
arrDate.push({sum: sums, index: i,startDate:dates[i+1].date,date:dates[j].date})
}
}
arrDate = _.orderBy(arrDate, ['sum'])
balance=lastBalance
for (let i = 0; i < dates.length; i++) {
balance = balance + dates[i].profit
dates[i].balance = balance
}
// console.log(arr)
// console.log('Balance ->',balance)
// console.log('Worth ->',arrNew[0])
// console.log('Balance ->',balance)
// console.log('Worth ->',arrNew[0])
let worth=(balance-lastBalance)/(arrNew[0].sum)
if (worth < base) {
base=worth
console.log(arrNew[0].sum,balance-lastBalance,worth)
let arr5=[]
for (let f = 0; f < size; f++) {
arr5.push(com[f])
let worth = (balance - lastBalance) / (arrDate[0].sum)
if (worth < base) {
base = worth
console.log(arrDate[0].sum, balance - lastBalance, worth)
let arr5 = []
for (let f = 0; f < size; f++) {
arr5.push(com[f])
}
// let z={maxReserve:arrNew[0].sum,balance:balance,bad:base}
//
// await createfileADV(JSON.stringify(z))
await lastCheck(arrDate[0].sum, balance - lastBalance, base, arr5)
}
// let z={maxReserve:arrNew[0].sum,balance:balance,bad:base}
//
// await createfileADV(JSON.stringify(z))
await lastCheck(arrNew[0].sum,balance-lastBalance,base,arr5)
}
// let start=false
// let arr2=[]
// for (let i=0;i<arr.length;i++)
......@@ -173,28 +205,62 @@ if (worth < base) {
return run()
}
function addDate(data) {
for (let i = 0; i < dates.length; i++)
if (data.date.includes(dates[i].date)) {
dates[i].profit = dates[i].profit + data.profit
function add(date, profit,side) {
dates[i].count=dates[i].count+data.count
dates[i].longCount=dates[i].longCount+data.longCount
dates[i].longProfit= dates[i].longProfit+data.longProfit
dates[i].shortCount=dates[i].shortCount+data.shortCount
dates[i].shortProfit= dates[i].shortProfit+data.shortProfit
return
}
}
function add(date, profit, side) {
for (let i = 0; i < arr.length; i++)
if (arr[i].date === date) {
arr[i].profit = arr[i].profit + profit
arr[i].count++
if ( side ==='L') {
if (side === 'LONG') {
arr[i].longCount++
arr[i].longProfit= arr[i].longProfit+profit
}
else {
arr[i].longProfit = arr[i].longProfit + profit
} else {
arr[i].shortCount++
arr[i].shortProfit= arr[i].shortProfit+profit
arr[i].shortProfit = arr[i].shortProfit + profit
}
return
}
if ( side ==='LONG')
arr.push({date: date, profit: profit,count:1,longCount:1,shortCount:0,longProfit:profit,shortProfit:0})
if (side === 'LONG')
arr.push({
date: date,
profit: profit,
count: 1,
longCount: 1,
shortCount: 0,
longProfit: profit,
shortProfit: 0
})
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
})
}
......@@ -205,7 +271,6 @@ function get(date) {
}
}
function createfileADV(data) {
......@@ -218,10 +283,10 @@ function createfileADV(data) {
});
}
function createfileTorob(name,data) {
function createfileTorob(name, data) {
// console.log(data)
return new Promise(function (resolve, reject) {
fs.writeFile('torob/'+name+'.json', data, 'utf8', function (err) {
fs.writeFile('torob/' + name + '.json', data, 'utf8', function (err) {
if (err) reject(err);
else resolve(data);
});
......
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