Toggle navigation
Toggle navigation
This project
Loading...
Sign in
박하늘
/
stock_chatbot
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
진주성
2021-06-08 19:28:36 +0000
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
37ee1c4fc97bf4acf1f846e09593fa3e1bb5f28e
37ee1c4f
1 parent
88e42710
node js modified(메세지 추가 및 케이스 다양화)
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
224 additions
and
50 deletions
server/app.js
server/basic.py
server/optimizer.py
server/src/test.png
server/app.js
View file @
37ee1c4
var
express
=
require
(
'express'
);
const
request
=
require
(
'request'
);
const
TARGET_URL
=
'https://api.line.me/v2/bot/message/reply'
const
TOKEN
=
'OVIxKODBqM8Pn2dpFtFeSLsDbBvApfTu88rh8wFGOzfvgvPjmBH0A4XKii97VxIDO9shYyTix4qGq32vwvL895Rbss5VSVEiU/XG5lOdyTLgECkSQKOdObSetZwcVHbGmzZJ+0Cz5vZrB5KuImOwrwdB04t89/1O/w1cDnyilFU='
const
TOKEN
=
"sGB5EZq14+Lu4sc6Gt6NJ1Sx/rDtE1BsTyfZeNX42XVVjcgX1kk6/Uj1H40IQ1X3y8MzJLvKGifhioNCJLWQkWH2i95EtNDQyGn7Iqu6MnQRE7pg/z7klGgswS9974s0EKX90FcCfAIndNSYAG+d5gdB04t89/1O/w1cDnyilFU="
const
fs
=
require
(
'fs'
);
const
path
=
require
(
'path'
);
const
HTTPS
=
require
(
'https'
);
const
domain
=
"201
7103989
.oss2021.tk"
const
domain
=
"201
6100990
.oss2021.tk"
const
sslport
=
23023
;
const
bodyParser
=
require
(
'body-parser'
);
var
app
=
express
();
var
stockarr
=
[];
var
pastreply
=
""
;
var
tatic
=
""
;
app
.
use
(
'/simages'
,
express
.
static
(
__dirname
+
'/src'
));
app
.
use
(
bodyParser
.
json
());
app
.
post
(
'/hook'
,
function
(
req
,
res
)
{
...
...
@@ -25,33 +26,154 @@ app.post('/hook', function (req, res) {
console
.
log
(
'[request message]'
,
eventObj
.
message
);
if
(
eventObj
.
type
==
'postback'
)
{
if
(
eventObj
.
postback
.
data
==
'action=datetemp&selectId=1'
)
if
(
eventObj
.
postback
.
data
==
'action=datetemp&selectId=1'
&&
pastreply
==
"비중 추천"
){
console
.
log
(
stockarr
);
weight_recommend
(
eventObj
.
replyToken
,
eventObj
.
postback
.
params
.
date
)
tatic
=
""
pastreply
=
""
}
else
{
optimizer
(
eventObj
.
replyToken
,
eventObj
.
postback
.
params
.
date
)
stockarr
.
splice
(
0
,
stockarr
.
length
);
}
}
else
{
{
console
.
log
(
eventObj
.
message
.
text
)
console
.
log
(
pastreply
)
if
(
eventObj
.
message
.
text
==
'도움말'
||
eventObj
.
message
.
text
==
'주가 도움말'
||
eventObj
.
message
.
text
==
'비중 추천 도움말'
||
eventObj
.
message
.
text
==
'백테스트 도움말'
)
{
printhelp
(
eventObj
.
replyToken
,
eventObj
.
message
.
text
)
}
else
if
(
eventObj
.
message
.
text
.
indexOf
(
' '
)
!=
-
1
)
else
if
(
eventObj
.
message
.
text
==
'백테스트'
)
{
date
(
eventObj
.
replyToken
,
eventObj
.
message
.
text
)
}
else
else
if
(
eventObj
.
message
.
text
==
'주가'
)
{
basicinform_pre
(
eventObj
.
replyToken
,
eventObj
.
message
.
text
)
pastreply
=
'주가'
console
.
log
(
pastreply
);
}
else
if
(
pastreply
==
'주가'
&&
eventObj
.
message
.
text
.
indexOf
(
' '
)
==
-
1
){
basicinform
(
eventObj
.
replyToken
,
eventObj
.
message
.
text
)
}
else
if
(
eventObj
.
message
.
text
==
'비중 추천'
){
weight_1
(
eventObj
.
replyToken
,
eventObj
.
message
.
text
)
pastreply
=
'비중 추천'
}
else
if
(
pastreply
=
'비중 추천'
&&
eventObj
.
message
.
text
.
indexOf
(
' '
)
!=
-
1
){
var
holder
=
eventObj
.
message
.
text
.
split
(
' '
)
console
.
log
(
"holder"
,
holder
)
var
i
;
for
(
i
=
0
;
i
<
holder
.
length
;
i
++
)
{
stockarr
[
i
]
=
holder
[
i
];
}
weight_2
(
eventObj
.
replyToken
,
eventObj
.
message
.
text
);
pastreply
=
"전략"
}
else
if
(
pastreply
=
"전략"
&&
(
eventObj
.
message
.
text
==
'gmv'
||
eventObj
.
message
.
text
==
'ms'
)
||
eventObj
.
message
.
text
==
'rp'
){
tatic
=
eventObj
.
message
.
text
pastreply
=
"비중 추천"
date
(
eventObj
.
replyToken
,
eventObj
.
message
.
text
)
}
else
{
errormessage
(
eventObj
.
replyToken
,
eventObj
.
message
.
text
);
pastreply
=
''
}
}
res
.
sendStatus
(
200
);
});
function
errormessage
(
replyToken
,
message
){
request
.
post
(
{
url
:
TARGET_URL
,
headers
:
{
'Authorization'
:
`Bearer
${
TOKEN
}
`
},
json
:
{
"replyToken"
:
replyToken
,
"messages"
:[
{
"type"
:
"text"
,
"text"
:
"정해진 양식대로 입력하지 않으셨어요. \n 처음부터 다시 진행해주세요 :)"
}
]
}
},(
error
,
response
,
body
)
=>
{
console
.
log
(
body
)
});
}
function
weight_1
(
replyToken
,
message
){
request
.
post
(
{
url
:
TARGET_URL
,
headers
:
{
'Authorization'
:
`Bearer
${
TOKEN
}
`
},
json
:
{
"replyToken"
:
replyToken
,
"messages"
:[
{
"type"
:
"text"
,
"text"
:
"포트폴리오에 넣을 종목을 입력해주세요. \n 두 종목 이상을 띄어쓰기로 구분해서 입력해주세요!"
}
]
}
},(
error
,
response
,
body
)
=>
{
console
.
log
(
body
)
});
}
function
weight_2
(
replyToken
,
message
){
request
.
post
(
{
url
:
TARGET_URL
,
headers
:
{
'Authorization'
:
`Bearer
${
TOKEN
}
`
},
json
:
{
"replyToken"
:
replyToken
,
"messages"
:[
{
"type"
:
"text"
,
"text"
:
"전략을 입력해주세요 \n gmv, ms, rp 중 하나를 정확히 입력해주세요!"
}
]
}
},(
error
,
response
,
body
)
=>
{
console
.
log
(
body
)
});
}
function
basicinform_pre
(
replyToken
,
message
){
request
.
post
(
{
url
:
TARGET_URL
,
headers
:
{
'Authorization'
:
`Bearer
${
TOKEN
}
`
},
json
:
{
"replyToken"
:
replyToken
,
"messages"
:[
{
"type"
:
"text"
,
"text"
:
"종목명을 입력해주세요!"
}
]
}
},(
error
,
response
,
body
)
=>
{
console
.
log
(
body
)
});
}
function
printhelp
(
replyToken
,
message
){
if
(
message
==
'도움말'
){
request
.
post
(
...
...
@@ -195,7 +317,7 @@ function basicinform(replyToken, message) {
const
Callback
=
(
data
)
=>
{
pystring
=
data
.
toString
();
if
(
pystring
[
0
]
==
'1'
)
{
{
pastreply
=
""
pystring
=
pystring
.
replace
(
'1현'
,
'현'
);
request
.
post
(
{
...
...
@@ -209,11 +331,6 @@ function basicinform(replyToken, message) {
{
"type"
:
"text"
,
"text"
:
pystring
},
{
"type"
:
"image"
,
"originalContentUrl"
:
"https://2017103989.oss2021.tk:23023/simages/test.png"
,
"previewImageUrl"
:
"https://2017103989.oss2021.tk:23023/simages/test.png"
}
]
}
...
...
@@ -274,6 +391,7 @@ function basicinform(replyToken, message) {
}
};
process
.
stdout
.
on
(
"data"
,
Callback
);
}
function
optimizer
(
replyToken
,
sdate
)
{
...
...
@@ -317,13 +435,59 @@ function optimizer(replyToken, sdate) {
process
.
stdout
.
on
(
"data"
,
Callback
);
}
function
weight_recommend
(
replyToken
,
sdate
)
{
sdate
=
sdate
.
toString
();
var
pystring
=
''
var
i
;
for
(
i
=
0
;
i
<
stockarr
.
length
;
i
++
)
{
pystring
+=
stockarr
[
i
];
pystring
+=
','
}
pystring
+=
sdate
;
console
.
log
(
pystring
);
const
spawn
=
require
(
"child_process"
).
spawn
;
const
process
=
spawn
(
"python"
,
[
"optimizer.py"
,
pystring
,
"weight"
,
tatic
]);
const
Callback
=
(
data
)
=>
{
pystring
=
data
.
toString
();
pystring
=
pystring
.
slice
(
1
,
-
2
)
pastreply
==
""
request
.
post
(
{
url
:
TARGET_URL
,
headers
:
{
'Authorization'
:
`Bearer
${
TOKEN
}
`
},
json
:
{
"replyToken"
:
replyToken
,
"messages"
:[
{
"type"
:
"text"
,
"text"
:
"비중 추천 결과입니다!"
},
{
"type"
:
"text"
,
"text"
:
pystring
}
]
}
},(
error
,
response
,
body
)
=>
{
console
.
log
(
body
)
});
}
process
.
stdout
.
on
(
"data"
,
Callback
);
}
function
date
(
replyToken
,
message
)
{
/*
var holder = message.split(' ')
var i;
for(i = 0; i < holder.length; i++)
{
stockarr[i] = holder[i];
}
*/
var
today
=
new
Date
();
var
year
=
today
.
getFullYear
();
var
month
=
today
.
getMonth
()
+
1
;
...
...
server/basic.py
View file @
37ee1c4
...
...
@@ -10,12 +10,8 @@ def get_matches(query, choices, limit=3):
return
result
def
basicinform
(
input
):
<<<<<<<
HEAD
stocks
=
pd
.
read_csv
(
'stockcodename.csv'
,
index_col
=
0
)
=======
stocks
=
pd
.
read_csv
(
'stockcodename.csv'
,
names
=
[
'Symbol'
,
'Market'
,
'Name'
,
'Sector'
,
'Industry'
,
'ListingDate'
,
'SettleMonth'
,
'Represetitive'
,
'HomePage'
,
'Region'
],
index_col
=
0
)
>>>>>>>
f1c2d34f3272bc7cfebf6e887b72493185c4c57c
symbol
=
''
for
i
in
enumerate
(
stocks
.
Name
):
...
...
@@ -50,10 +46,7 @@ def basicinform(input):
return
value
<<<<<<<
HEAD
=======
# print(basicinform('호텔신라'))
>>>>>>>
f1c2d34f3272bc7cfebf6e887b72493185c4c57c
args
=
sys
.
argv
print
(
basicinform
(
args
[
0
]))
print
(
basicinform
(
args
[
1
]))
...
...
server/optimizer.py
View file @
37ee1c4
...
...
@@ -583,42 +583,59 @@ class back_test:
# print(back_test().backtest_data(['삼성전자','LG전자'],[0.9,0.1],'2010-01-01', '2021-01-01',10000000,3, 'monthly', 'gmv')['pfo_return'][0]['acc_return_ratio'])
# print(back_test().backtest_data(['삼성전자','LG전자'],[0.9,0.1],'2018-01-01', '2021-01-01',10000000,6, 'monthly', 'gmv'))
args
=
sys
.
argv
[
1
]
.
split
(
","
)
assets
=
[]
gravity
=
[]
for
i
in
range
(
len
(
args
)
-
1
):
if
(
sys
.
argv
[
2
]
==
"weight"
):
args
=
sys
.
argv
[
1
]
.
split
(
","
)
assets
=
[]
gravity
=
[]
for
i
in
range
(
len
(
args
)
-
1
):
assets
.
append
(
args
[
i
])
gravity
.
append
(
0
)
data
=
back_test
()
.
backtest_data
(
assets
,
gravity
,
args
[
-
1
],
'2021-01-02'
,
10000000
,
6
,
'monthly'
,
'gmv'
)
if
(
sys
.
argv
[
3
]
==
'gmv'
):
print
(
c_Models
(
assets
,
gravity
,
args
[
-
1
],
'2021-06-01'
)
.
gmv_opt
())
elif
(
sys
.
argv
[
3
]
==
'ms'
):
print
(
c_Models
(
assets
,
gravity
,
args
[
-
1
],
'2021-06-01'
)
.
ms_opt
())
elif
(
sys
.
argv
[
3
]
==
'rp'
):
print
(
c_Models
(
assets
,
gravity
,
args
[
-
1
],
'2021-06-01'
)
.
rp_opt
())
else
:
args
=
sys
.
argv
[
1
]
.
split
(
","
)
assets
=
[]
gravity
=
[]
for
i
in
range
(
len
(
args
)
-
1
):
assets
.
append
(
args
[
i
])
gravity
.
append
(
0
)
data
=
back_test
()
.
backtest_data
(
assets
,
gravity
,
args
[
-
1
],
'2021-06-01'
,
10000000
,
6
,
'monthly'
,
'gmv'
)
#data = back_test().backtest_data(['삼성전자','LG전자','호텔신라'],[0.1,0.1,0.8],'2020-01-01', '2021-01-02',10000000,6, 'monthly', 'gmv')
# data = back_test().backtest_data(['삼성전자','LG전자'],[0.1,0.1],'2020-01-01', '2021-01-02',10000000,6, 'monthly', 'gmv')
x
=
data
[
'pfo_return'
][
0
][
'Date'
]
y
=
data
[
'pfo_return'
][
0
][
'acc_return ratio'
]
y2
=
data
[
'bench'
][
0
][
'KOSPI_acc_return'
]
y3
=
data
[
'bench'
][
0
][
'S&P500_acc_return'
]
x_ticks
=
[]
for
i
,
j
in
enumerate
(
x
):
#data = back_test().backtest_data(['삼성전자','LG전자','호텔신라'],[0.1,0.1,0.8],'2020-01-01', '2021-01-02',10000000,6, 'monthly', 'gmv')
# data = back_test().backtest_data(['삼성전자','LG전자'],[0.1,0.1],'2020-01-01', '2021-01-02',10000000,6, 'monthly', 'gmv')
x
=
data
[
'pfo_return'
][
0
][
'Date'
]
y
=
data
[
'pfo_return'
][
0
][
'acc_return ratio'
]
y2
=
data
[
'bench'
][
0
][
'KOSPI_acc_return'
]
y3
=
data
[
'bench'
][
0
][
'S&P500_acc_return'
]
x_ticks
=
[]
for
i
,
j
in
enumerate
(
x
):
if
(
i
%
6
)
==
0
:
x_ticks
.
append
(
j
)
else
:
x_ticks
.
append
(
''
)
x_ticks
[
-
1
]
=
x
[
-
1
]
plt
.
figure
(
figsize
=
(
10
,
5
))
ax
=
plt
.
gca
()
ax
.
xaxis
.
set_major_locator
(
ticker
.
MultipleLocator
(
12
))
plt
.
plot
(
x
,
y
,
label
=
'gmv result'
)
plt
.
plot
(
x
,
y2
,
label
=
'kospi result'
)
plt
.
plot
(
x
,
y3
,
label
=
's&p500 result'
)
plt
.
xticks
(
x_ticks
,
rotation
=
60
)
plt
.
xlabel
(
'Date'
)
plt
.
ylabel
(
'Return'
)
plt
.
title
(
'result'
)
plt
.
legend
()
plt
.
show
()
plt
.
savefig
(
"./src/test.png"
,
dpi
=
100
)
print
(
"end"
)
x_ticks
[
-
1
]
=
x
[
-
1
]
plt
.
figure
(
figsize
=
(
10
,
5
))
ax
=
plt
.
gca
()
ax
.
xaxis
.
set_major_locator
(
ticker
.
MultipleLocator
(
12
))
plt
.
plot
(
x
,
y
,
label
=
'gmv result'
)
plt
.
plot
(
x
,
y2
,
label
=
'kospi result'
)
plt
.
plot
(
x
,
y3
,
label
=
's&p500 result'
)
plt
.
xticks
(
x_ticks
,
rotation
=
60
)
plt
.
xlabel
(
'Date'
)
plt
.
ylabel
(
'Return'
)
plt
.
title
(
'result'
)
plt
.
legend
()
plt
.
show
()
plt
.
savefig
(
"./src/test.png"
,
dpi
=
100
)
print
(
"end"
)
...
...
server/src/test.png
0 → 100644
View file @
37ee1c4
45 KB
Please
register
or
login
to post a comment