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
Hide 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'
let
base
=
'
base
'
function
run
(
data
,
config
,
risk
,
pfTrade
)
{
function
run
(
data
,
config
,
risk
,
pfTrade
,
riskFreeLevel
)
{
let
commision
=
config
.
commision
let
money
=
config
.
base
let
total
=
0
...
...
@@ -20,12 +20,12 @@ function run(data, config,risk,pfTrade) {
let
profit
=
0
let
lastCom
=
0
let
lastMoney
=
0
let
levels
=
[]
let
levels
=
[]
let
dur
=
getMinDiff
(
data
[
0
].
openDate
,
data
[
data
.
length
-
1
].
closeDate
)
let
newP
=
dur
/
data
.
length
// console.log(data.length)
// console.log(newP)
if
(
pfTrade
<
newP
)
let
newP
=
dur
/
data
.
length
// console.log(data.length)
// console.log(newP)
if
(
pfTrade
<
newP
)
return
null
for
(
let
i
=
0
;
i
<
data
.
length
;
i
++
)
{
...
...
@@ -39,8 +39,10 @@ function run(data, config,risk,pfTrade) {
else
if
(
config
.
type
===
plus
)
money
=
config
.
base
*
(
step
+
1
)
}
let
d
=
inlineCheck
(
money
,
commision
,
data
[
i
],
profit
,
lastCom
,
config
.
target
)
let
riskfree
=
false
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
))
...
...
@@ -73,39 +75,32 @@ function run(data, config,risk,pfTrade) {
}
}
let
firstMaxAllocatedMoney
=
maxAllocatedMoney
if
(
config
.
param
!==
0
)
{
for
(
let
i
=
0
;
i
<
risk
;
i
++
)
maxAllocatedMoney
=
maxAllocatedMoney
*
config
.
param
let
firstMaxAllocatedMoney
=
maxAllocatedMoney
if
(
config
.
param
!==
0
)
{
for
(
let
i
=
0
;
i
<
risk
;
i
++
)
maxAllocatedMoney
=
maxAllocatedMoney
*
config
.
param
}
let
newLevel
=
[]
let
newLevelText
=
''
for
(
let
i
=
0
;
i
<
(
maxLevel
+
1
);
i
++
)
{
let
count
=
counter
(
i
,
levels
)
// newLevel.push({level:i,count:count})
let
per
=
parseFloat
((
count
/
total
)
*
100
).
toFixed
(
1
)
let
newLevel
=
[]
let
newLevelText
=
''
for
(
let
i
=
0
;
i
<
(
maxLevel
+
1
);
i
++
)
{
let
count
=
counter
(
i
,
levels
)
// newLevel.push({level:i,count:count})
let
per
=
parseFloat
((
count
/
total
)
*
100
).
toFixed
(
1
)
newLevelText
=
newLevelText
+
i
+
'
:
'
+
count
+
'
:
'
+
per
+
'
%
'
+
'
,
'
if
((
i
+
2
)
%
12
===
0
)
{
newLevelText
+
newLevelText
+
'
\\
n
'
newLevelText
=
newLevelText
+
i
+
'
:
'
+
count
+
'
:
'
+
per
+
'
%
'
+
'
,
'
if
((
i
+
2
)
%
12
===
0
)
{
}
newLevelText
+
newLevelText
+
'
\\
n
'
}
}
// console.log(newLevelText)
// for (let i=0;i<newLevel)
// console.log(newLevelText)
// for (let i=0;i<newLevel)
let
totalFinal
=
total
*
config
.
target
...
...
@@ -136,7 +131,7 @@ function run(data, config,risk,pfTrade) {
for
(
let
i
=
0
;
i
<
total
;
i
++
)
sum
=
sum
+
(
sum
*
perp
)
sum
=
sum
-
Math
.
abs
(
maxAllocatedMoney
)
sum
=
sum
-
Math
.
abs
(
maxAllocatedMoney
)
let
newCompund
=
sum
/
dur
let
compoundPerMonth
=
(
newCompund
*
30
*
100
)
/
Math
.
abs
(
maxAllocatedMoney
)
...
...
@@ -154,23 +149,23 @@ function run(data, config,risk,pfTrade) {
profitPerMonth
:
Math
.
abs
(
profitPerMonth
),
compoundPerMonth
:
compoundPerMonth
,
firstMaxAllocatedMoney
:
firstMaxAllocatedMoney
,
firstMaxAllocatedMoney
:
firstMaxAllocatedMoney
,
maxAllocatedMoney
:
maxAllocatedMoney
,
avgAllocatedMoney
:
maxAllocatedMoney
/
total
,
drawDown
:
drawDown
,
CompoundPerMonthDrawDown
:
compoundPerMonth
/
drawDown
,
profitPerMonthDrawDown
:
Math
.
abs
(
profitPerMonth
)
/
drawDown
,
CompoundPerMonthDrawDown
:
compoundPerMonth
/
drawDown
,
profitPerMonthDrawDown
:
Math
.
abs
(
profitPerMonth
)
/
drawDown
,
maxReseve
:
maxReserve
,
avgReserve
:
maxReserve
/
total
,
percentage
:
percentage
,
avgProfitPerDay
:
newT
,
allocatedReserve
:
(
maxAllocatedMoney
)
/
Math
.
abs
(
maxReserve
),
minus
:
minus
,
risk
:
risk
,
levels
:
newLevelText
,
pftrade
:
newP
,
countOfTrade
:
data
.
length
risk
:
risk
,
levels
:
newLevelText
,
pftrade
:
newP
,
countOfTrade
:
data
.
length
}
...
...
@@ -183,10 +178,9 @@ function run(data, config,risk,pfTrade) {
}
function
counter
(
count
,
array
)
{
let
sum
=
0
for
(
let
i
=
0
;
i
<
array
.
length
;
i
++
)
function
counter
(
count
,
array
)
{
let
sum
=
0
for
(
let
i
=
0
;
i
<
array
.
length
;
i
++
)
if
(
array
[
i
]
===
count
)
sum
++
...
...
@@ -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)
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
)
...
...
csv.js
View file @
69c4141a
...
...
@@ -6,7 +6,7 @@ let moment = require('moment-timezone')
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
)
{
let
arr
=
[]
// console.log(name)
...
...
@@ -14,12 +14,12 @@ async function parse(directory, name, configs, risk, pfTrade, side) {
.
pipe
(
csv
.
parse
({
headers
:
true
}))
.
on
(
'
error
'
,
error
=>
reject
(
error
))
.
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
)
...
...
@@ -107,7 +107,7 @@ function initData(data, config, name, risk, pfTrade, side) {
let
cz
=
[]
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
...
...
generate.js
View file @
69c4141a
...
...
@@ -20,7 +20,7 @@ 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
=
[]
for
(
let
i
=
0
;
i
<
arr
.
length
;
i
++
)
all
.
push
(
add
(
arr
[
i
]))
...
...
run.js
View file @
69c4141a
...
...
@@ -20,7 +20,7 @@ async function run() {
for
(
let
i
=
0
;
i
<
files
.
length
;
i
++
)
if
(
files
[
i
].
includes
(
'
.csv
'
))
{
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
)
...
...
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