Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
bitcoin-trade-bot
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Recolic
bitcoin-trade-bot
Commits
d2415902
There was an error fetching the commit references. Please try again later.
Commit
d2415902
authored
3 years ago
by
Recolic K
Browse files
Options
Downloads
Patches
Plain Diff
fix issues
parent
ae8d4a86
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
longterm_baseline.py
+31
-16
31 additions, 16 deletions
longterm_baseline.py
with
31 additions
and
16 deletions
longterm_baseline.py
+
31
−
16
View file @
d2415902
...
...
@@ -2,14 +2,7 @@ import torch
import
torch.nn
as
nn
import
torch.nn.functional
as
F
import
torch.optim
as
optim
import
pickle
# [(Snapshot_Time, [(buy_price1, amount1), ...] , [(sell_price1, amount1), ...]), ...]
# [(1620457034392, [(56000, 0.01), (55900, 1), (55700, 30), ...] , [(57000, 0.01), (57100, 1), ...] ), (1620457034394, [...]), ...]
# The snapshots should has almost identical time-interval. Good for LSTM.
# Time axis: [history, older, newer, ..., latest]
realtime_shortterm_dataset_depth
=
[]
realtime_shortterm_dataset_depth_size
=
1024
import
pickle
,
numpy
,
math
# [(Trade_Time, PRICE, AMOUNT), ...]
# [(1620457034392, 56000, 0.5), (1620457034394, 56001, 0.05), ...]
...
...
@@ -18,6 +11,13 @@ realtime_shortterm_dataset_depth_size = 1024
realtime_shortterm_dataset_aggtrade
=
[]
realtime_shortterm_dataset_aggtrade_size
=
1024
*
1024
# [(Snapshot_Time, [(buy_price1, amount1), ...] , [(sell_price1, amount1), ...]), ...]
# [(1620457034392, [(56000, 0.01), (55900, 1), (55700, 30), ...] , [(57000, 0.01), (57100, 1), ...] ), (1620457034394, [...]), ...]
# The snapshots should has almost identical time-interval. Good for LSTM.
# Time axis: [history, older, newer, ..., latest]
realtime_shortterm_dataset_depth
=
[]
realtime_shortterm_dataset_depth_size
=
1024
# The trading thread would not start working, before finish analysing longterm dataset.
# Time-interval for longterm dataset is 1 minute.
longterm_dataset
=
[]
...
...
@@ -35,7 +35,7 @@ def load_realtime_dataset_on_start():
class
LSTM_Shortterm_Predictor
(
nn
.
Module
):
def
__init__
(
self
,
input_dim
):
super
(
LSTM_Shortterm_Predictor
,
self
).
__init__
()
self
.
lstm_idim
=
1
6
self
.
lstm_idim
=
1
0
# this is the length of depth_to_impulsive_score_vector()
self
.
lstm_odim
=
128
# The input would be a tuple containing complex information.
...
...
@@ -51,7 +51,7 @@ class LSTM_Shortterm_Predictor(nn.Module):
self
.
out
=
nn
.
Linear
(
self
.
lstm_odim
,
1
)
def
forward
(
self
,
sample_seq
):
input_seq
=
sample_seq
.
view
(
len
(
sample_seq
),
1
,
lstm_idim
)
input_seq
=
sample_seq
.
view
(
len
(
sample_seq
),
1
,
self
.
lstm_idim
)
lstm_in
=
self
.
serializer
(
input_seq
)
lstm_out
,
_
=
self
.
lstm
(
lstm_in
)
predict_shortterm_trend
=
self
.
out
(
torch
.
tanh
(
lstm_out
[
-
1
:]))
...
...
@@ -82,18 +82,33 @@ def learn_once(depth_seq, trend_answer_score):
i
=
torch
.
tensor
(
input_seq
,
dtype
=
torch
.
float
)
o
=
model
(
i
)
loss
=
torch
.
square
(
o
-
trend_answer_score
)
loss
=
abs
(
o
-
trend_answer_score
)
loss
.
backward
(
retain_graph
=
True
)
optimizer
.
step
()
return
lo
ss
.
to_list
()[
0
]
return
f
lo
at
(
loss
)
load_realtime_dataset_on_start
()
for
i
in
range
(
300
):
print
(
"
DEBUG: l=
"
,
realtime_shortterm_dataset_depth
[
i
+
256
])
answer
=
realtime_shortterm_dataset_depth
[
i
+
256
][
1
][
0
][
0
]
-
realtime_shortterm_dataset_depth
[
i
][
1
][
0
][
0
]
losses
=
[]
for
i
in
range
(
2000
):
answer
=
numpy
.
average
([
realtime_shortterm_dataset_depth
[
i
+
di
][
1
][
0
][
0
]
for
di
in
(
256
,
512
,
768
,
1024
,
2000
,
5000
)])
-
realtime_shortterm_dataset_depth
[
i
][
1
][
0
][
0
]
print
(
"
answer=
"
,
answer
)
loss
=
learn_once
(
realtime_shortterm_dataset_depth
[
i
],
answer
)
loss
=
learn_once
(
realtime_shortterm_dataset_depth
[
i
:
i
+
128
],
answer
)
print
(
"
Loss=
"
,
loss
)
losses
+=
[
loss
]
#####################
import
matplotlib.pyplot
as
plt
import
matplotlib.cm
as
cm
import
numpy
as
np
x
=
numpy
.
arange
(
len
(
losses
))
colors
=
cm
.
rainbow
(
np
.
linspace
(
0
,
1
,
10
))
for
index
,
y
in
enumerate
(
losses
):
plt
.
scatter
(
index
,
y
,
color
=
colors
[
1
])
#for x, y in guess_xy:
# plt.scatter(x, y, color=colors[6])
plt
.
show
()
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment