Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
F
forex
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
forex
Commits
69c4141a
Commit
69c4141a
authored
Dec 08, 2021
by
Ahmad Nemati
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
init
parent
448a5dc4
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
48 additions
and
51 deletions
+48
-51
ai.js
ai.js
+42
-45
csv.js
csv.js
+4
-4
generate.js
generate.js
+1
-1
run.js
run.js
+1
-1
No files found.
ai.js
View file @
69c4141a
...
@@ -6,7 +6,7 @@ let zarib = 'zarib'
...
@@ -6,7 +6,7 @@ let zarib = 'zarib'
let
base
=
'
base
'
let
base
=
'
base
'
function
run
(
data
,
config
,
risk
,
pfTrade
)
{
function
run
(
data
,
config
,
risk
,
pfTrade
,
riskFreeLevel
)
{
let
commision
=
config
.
commision
let
commision
=
config
.
commision
let
money
=
config
.
base
let
money
=
config
.
base
let
total
=
0
let
total
=
0
...
@@ -20,12 +20,12 @@ function run(data, config,risk,pfTrade) {
...
@@ -20,12 +20,12 @@ function run(data, config,risk,pfTrade) {
let
profit
=
0
let
profit
=
0
let
lastCom
=
0
let
lastCom
=
0
let
lastMoney
=
0
let
lastMoney
=
0
let
levels
=
[]
let
levels
=
[]
let
dur
=
getMinDiff
(
data
[
0
].
openDate
,
data
[
data
.
length
-
1
].
closeDate
)
let
dur
=
getMinDiff
(
data
[
0
].
openDate
,
data
[
data
.
length
-
1
].
closeDate
)
let
newP
=
dur
/
data
.
length
let
newP
=
dur
/
data
.
length
// console.log(data.length)
// console.log(data.length)
// console.log(newP)
// console.log(newP)
if
(
pfTrade
<
newP
)
if
(
pfTrade
<
newP
)
return
null
return
null
for
(
let
i
=
0
;
i
<
data
.
length
;
i
++
)
{
for
(
let
i
=
0
;
i
<
data
.
length
;
i
++
)
{
...
@@ -39,8 +39,10 @@ function run(data, config,risk,pfTrade) {
...
@@ -39,8 +39,10 @@ function run(data, config,risk,pfTrade) {
else
if
(
config
.
type
===
plus
)
else
if
(
config
.
type
===
plus
)
money
=
config
.
base
*
(
step
+
1
)
money
=
config
.
base
*
(
step
+
1
)
}
}
let
riskfree
=
false
let
d
=
inlineCheck
(
money
,
commision
,
data
[
i
],
profit
,
lastCom
,
config
.
target
)
if
(
step
>
riskFreeLevel
)
riskfree
=
true
let
d
=
inlineCheck
(
money
,
commision
,
data
[
i
],
profit
,
lastCom
,
config
.
target
,
riskfree
)
if
(
Math
.
abs
(
d
.
reserve
)
>
Math
.
abs
(
maxReserve
))
if
(
Math
.
abs
(
d
.
reserve
)
>
Math
.
abs
(
maxReserve
))
...
@@ -73,41 +75,34 @@ function run(data, config,risk,pfTrade) {
...
@@ -73,41 +75,34 @@ function run(data, config,risk,pfTrade) {
}
}
}
}
let
firstMaxAllocatedMoney
=
maxAllocatedMoney
let
firstMaxAllocatedMoney
=
maxAllocatedMoney
if
(
config
.
param
!==
0
)
if
(
config
.
param
!==
0
)
{
{
for
(
let
i
=
0
;
i
<
risk
;
i
++
)
for
(
let
i
=
0
;
i
<
risk
;
i
++
)
maxAllocatedMoney
=
maxAllocatedMoney
*
config
.
param
maxAllocatedMoney
=
maxAllocatedMoney
*
config
.
param
}
}
let
newLevel
=
[]
let
newLevel
=
[]
let
newLevelText
=
''
let
newLevelText
=
''
for
(
let
i
=
0
;
i
<
(
maxLevel
+
1
);
i
++
)
for
(
let
i
=
0
;
i
<
(
maxLevel
+
1
);
i
++
)
{
{
let
count
=
counter
(
i
,
levels
)
let
count
=
counter
(
i
,
levels
)
// newLevel.push({level:i,count:count})
// newLevel.push({level:i,count:count})
let
per
=
parseFloat
((
count
/
total
)
*
100
).
toFixed
(
1
)
let
per
=
parseFloat
((
count
/
total
)
*
100
).
toFixed
(
1
)
newLevelText
=
newLevelText
+
i
+
'
:
'
+
count
+
'
:
'
+
per
+
'
%
'
+
'
,
'
if
((
i
+
2
)
%
12
===
0
)
{
newLevelText
=
newLevelText
+
i
+
'
:
'
+
count
+
'
:
'
+
per
+
'
%
'
+
'
,
'
newLevelText
+
newLevelText
+
'
\\
n
'
if
((
i
+
2
)
%
12
===
0
)
{
newLevelText
+
newLevelText
+
'
\\
n
'
}
}
}
}
// console.log(newLevelText)
// console.log(newLevelText)
// for (let i=0;i<newLevel)
// for (let i=0;i<newLevel)
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
...
@@ -136,7 +131,7 @@ function run(data, config,risk,pfTrade) {
...
@@ -136,7 +131,7 @@ function run(data, config,risk,pfTrade) {
for
(
let
i
=
0
;
i
<
total
;
i
++
)
for
(
let
i
=
0
;
i
<
total
;
i
++
)
sum
=
sum
+
(
sum
*
perp
)
sum
=
sum
+
(
sum
*
perp
)
sum
=
sum
-
Math
.
abs
(
maxAllocatedMoney
)
sum
=
sum
-
Math
.
abs
(
maxAllocatedMoney
)
let
newCompund
=
sum
/
dur
let
newCompund
=
sum
/
dur
let
compoundPerMonth
=
(
newCompund
*
30
*
100
)
/
Math
.
abs
(
maxAllocatedMoney
)
let
compoundPerMonth
=
(
newCompund
*
30
*
100
)
/
Math
.
abs
(
maxAllocatedMoney
)
...
@@ -154,23 +149,23 @@ function run(data, config,risk,pfTrade) {
...
@@ -154,23 +149,23 @@ function run(data, config,risk,pfTrade) {
profitPerMonth
:
Math
.
abs
(
profitPerMonth
),
profitPerMonth
:
Math
.
abs
(
profitPerMonth
),
compoundPerMonth
:
compoundPerMonth
,
compoundPerMonth
:
compoundPerMonth
,
firstMaxAllocatedMoney
:
firstMaxAllocatedMoney
,
firstMaxAllocatedMoney
:
firstMaxAllocatedMoney
,
maxAllocatedMoney
:
maxAllocatedMoney
,
maxAllocatedMoney
:
maxAllocatedMoney
,
avgAllocatedMoney
:
maxAllocatedMoney
/
total
,
avgAllocatedMoney
:
maxAllocatedMoney
/
total
,
drawDown
:
drawDown
,
drawDown
:
drawDown
,
CompoundPerMonthDrawDown
:
compoundPerMonth
/
drawDown
,
CompoundPerMonthDrawDown
:
compoundPerMonth
/
drawDown
,
profitPerMonthDrawDown
:
Math
.
abs
(
profitPerMonth
)
/
drawDown
,
profitPerMonthDrawDown
:
Math
.
abs
(
profitPerMonth
)
/
drawDown
,
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
,
risk
:
risk
,
risk
:
risk
,
levels
:
newLevelText
,
levels
:
newLevelText
,
pftrade
:
newP
,
pftrade
:
newP
,
countOfTrade
:
data
.
length
countOfTrade
:
data
.
length
}
}
...
@@ -183,10 +178,9 @@ function run(data, config,risk,pfTrade) {
...
@@ -183,10 +178,9 @@ function run(data, config,risk,pfTrade) {
}
}
function
counter
(
count
,
array
)
function
counter
(
count
,
array
)
{
{
let
sum
=
0
let
sum
=
0
for
(
let
i
=
0
;
i
<
array
.
length
;
i
++
)
for
(
let
i
=
0
;
i
<
array
.
length
;
i
++
)
if
(
array
[
i
]
===
count
)
if
(
array
[
i
]
===
count
)
sum
++
sum
++
...
@@ -204,12 +198,15 @@ function percentage2(base, per) {
...
@@ -204,12 +198,15 @@ function percentage2(base, per) {
}
}
function
inlineCheck
(
money
,
com
,
data
,
profit
,
lastCom
,
tar
)
{
function
inlineCheck
(
money
,
com
,
data
,
profit
,
lastCom
,
tar
,
riskFree
)
{
// console.log(profit)
// console.log(profit)
com
=
com
*
money
com
=
com
*
money
let
target
=
money
+
Math
.
abs
(
profit
)
+
com
+
lastCom
+
tar
let
target
=
money
+
Math
.
abs
(
profit
)
+
com
+
lastCom
if
(
!
riskFree
)
target
=
target
+
tar
let
reserve
=
percentage
(
money
,
data
.
drawDown
)
let
reserve
=
percentage
(
money
,
data
.
drawDown
)
...
...
csv.js
View file @
69c4141a
...
@@ -6,7 +6,7 @@ let moment = require('moment-timezone')
...
@@ -6,7 +6,7 @@ let moment = require('moment-timezone')
let
ai
=
require
(
'
./ai
'
)
let
ai
=
require
(
'
./ai
'
)
async
function
parse
(
directory
,
name
,
configs
,
risk
,
pfTrade
,
side
)
{
async
function
parse
(
directory
,
name
,
configs
,
risk
,
pfTrade
,
side
,
riskFreeLevel
)
{
return
new
Promise
(
function
(
resolve
,
reject
)
{
return
new
Promise
(
function
(
resolve
,
reject
)
{
let
arr
=
[]
let
arr
=
[]
// console.log(name)
// console.log(name)
...
@@ -14,12 +14,12 @@ async function parse(directory, name, configs, risk, pfTrade, side) {
...
@@ -14,12 +14,12 @@ async function parse(directory, name, configs, risk, pfTrade, side) {
.
pipe
(
csv
.
parse
({
headers
:
true
}))
.
pipe
(
csv
.
parse
({
headers
:
true
}))
.
on
(
'
error
'
,
error
=>
reject
(
error
))
.
on
(
'
error
'
,
error
=>
reject
(
error
))
.
on
(
'
data
'
,
row
=>
arr
.
push
(
row
))
.
on
(
'
data
'
,
row
=>
arr
.
push
(
row
))
.
on
(
'
end
'
,
rowCount
=>
resolve
(
initData
(
arr
,
configs
,
name
,
risk
,
pfTrade
,
side
)));
.
on
(
'
end
'
,
rowCount
=>
resolve
(
initData
(
arr
,
configs
,
name
,
risk
,
pfTrade
,
side
,
riskFreeLevel
)));
});
});
}
}
function
initData
(
data
,
config
,
name
,
risk
,
pfTrade
,
side
)
{
function
initData
(
data
,
config
,
name
,
risk
,
pfTrade
,
side
,
riskFreeLevel
)
{
data
=
JSON
.
stringify
(
data
)
data
=
JSON
.
stringify
(
data
)
...
@@ -107,7 +107,7 @@ function initData(data, config, name, risk, pfTrade, side) {
...
@@ -107,7 +107,7 @@ function initData(data, config, name, risk, pfTrade, side) {
let
cz
=
[]
let
cz
=
[]
for
(
let
i
=
0
;
i
<
config
.
length
;
i
++
)
{
for
(
let
i
=
0
;
i
<
config
.
length
;
i
++
)
{
cz
.
push
(
ai
.
run
(
arr
,
config
[
i
],
risk
,
pfTrade
))
cz
.
push
(
ai
.
run
(
arr
,
config
[
i
],
risk
,
pfTrade
,
riskFreeLevel
))
}
}
return
cz
return
cz
...
...
generate.js
View file @
69c4141a
...
@@ -20,7 +20,7 @@ run()
...
@@ -20,7 +20,7 @@ run()
async
function
run
()
async
function
run
()
{
{
let
obj
=
{
sort
:
'
profitPerMonthDrawDown
'
,
alocatedReserve
:
3
,
alocatedReserveCompound
:
3
,
risk
:
0
,
start
:
10000
,
pfTrade
:
2
,
side
:
'
both
'
}
let
obj
=
{
sort
:
'
profitPerMonthDrawDown
'
,
alocatedReserve
:
3
,
alocatedReserveCompound
:
3
,
risk
:
0
,
start
:
10000
,
pfTrade
:
2
,
side
:
'
both
'
,
riskFreeLevel
:
5
}
let
all
=
[]
let
all
=
[]
for
(
let
i
=
0
;
i
<
arr
.
length
;
i
++
)
for
(
let
i
=
0
;
i
<
arr
.
length
;
i
++
)
all
.
push
(
add
(
arr
[
i
]))
all
.
push
(
add
(
arr
[
i
]))
...
...
run.js
View file @
69c4141a
...
@@ -20,7 +20,7 @@ async function run() {
...
@@ -20,7 +20,7 @@ async function run() {
for
(
let
i
=
0
;
i
<
files
.
length
;
i
++
)
for
(
let
i
=
0
;
i
<
files
.
length
;
i
++
)
if
(
files
[
i
].
includes
(
'
.csv
'
))
{
if
(
files
[
i
].
includes
(
'
.csv
'
))
{
csvFile
=
files
[
i
]
csvFile
=
files
[
i
]
arr
.
push
(
csv
.
parse
(
directory
,
files
[
i
],
configs
.
data
,
configs
.
risk
,
configs
.
pfTrade
,
configs
.
side
))
arr
.
push
(
csv
.
parse
(
directory
,
files
[
i
],
configs
.
data
,
configs
.
risk
,
configs
.
pfTrade
,
configs
.
side
,
configs
.
riskFreeLevel
))
}
}
arr
=
await
Promise
.
all
(
arr
)
arr
=
await
Promise
.
all
(
arr
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment