Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
F
fof
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
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
Dr.李
fof
Commits
cc5d32ca
Commit
cc5d32ca
authored
Oct 29, 2021
by
Dr.李
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update
parent
98ba1063
Changes
3
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
71 additions
and
0 deletions
+71
-0
.gitignore
.gitignore
+4
-0
030 债券型基金.ipynb
030 债券型基金.ipynb
+0
-0
utility.py
utility.py
+67
-0
No files found.
.gitignore
0 → 100644
View file @
cc5d32ca
.ipynb_checkpoints
__pycache__
*.pyc
.virtual_documents
\ No newline at end of file
030 债券型基金.ipynb
0 → 100644
View file @
cc5d32ca
This diff is collapsed.
Click to expand it.
utility.py
0 → 100644
View file @
cc5d32ca
import
datetime
as
dt
import
calendar
import
sqlalchemy
as
sa
import
pandas
as
pd
CONN
=
"mssql+pymssql://readdnds:reader
%402021
@121.37.138.1:14331/dnds"
def
read_sql
(
query
):
engine
=
sa
.
create_engine
(
CONN
,
connect_args
=
{
"charset"
:
"GBK"
})
return
pd
.
read_sql
(
query
,
con
=
engine
)
def
nearest_report_date
(
date
):
if
len
(
date
)
==
10
:
date
=
date
.
replace
(
"-"
,
""
)
mm
=
int
(
date
[
4
:
6
])
year
=
int
(
date
[
0
:
4
])
last_year
=
year
q
=
(
mm
//
3
+
1
)
*
3
last
=
calendar
.
monthrange
(
last_year
,
q
)[
1
]
return
dt
.
date
(
last_year
,
q
,
last
)
.
strftime
(
"
%
Y
%
m
%
d"
)
def
fd_basicinfo
(
security_ids
,
trade_dt
=
None
):
if
not
trade_dt
:
trade_dt
=
dt
.
datetime
.
today
()
.
strftime
(
"
%
Y
%
m
%
d"
)
else
:
trade_dt
=
trade_dt
.
replace
(
"-"
,
""
)
if
isinstance
(
security_ids
,
str
):
sec_id_strs
=
security_ids
.
split
(
","
)
else
:
sec_id_strs
=
","
.
join
([
"'"
+
s
+
"'"
for
s
in
security_ids
])
engine
=
sa
.
create_engine
(
CONN
,
connect_args
=
{
"charset"
:
"GBK"
})
query
=
f
"""
select SECURITYID, FDNAME, SNAMECOMP, FSYMBOL from TQ_FD_BASICINFO
WHERE
ISVALID = 1 AND
SECURITYID in ({sec_id_strs}) AND
(LIQUENDDATE >= '{trade_dt}' or LIQUENDDATE = '19000101')
"""
return
pd
.
read_sql
(
query
,
con
=
engine
)
def
fd_typeclass
(
security_ids
,
trade_dt
=
None
):
if
not
trade_dt
:
trade_dt
=
dt
.
datetime
.
today
()
.
strftime
(
"
%
Y
%
m
%
d"
)
else
:
trade_dt
=
trade_dt
.
replace
(
"-"
,
""
)
if
isinstance
(
security_ids
,
str
):
sec_id_strs
=
security_ids
.
split
(
","
)
else
:
sec_id_strs
=
","
.
join
([
"'"
+
s
+
"'"
for
s
in
security_ids
])
engine
=
sa
.
create_engine
(
CONN
,
connect_args
=
{
"charset"
:
"GBK"
})
query
=
f
"""
select SECURITYID, L1CODE, L1NAME, L2CODE, L2NAME from TQ_FD_TYPECLASS
WHERE
ISVALID = 1 AND
SECURITYID in ({sec_id_strs})
"""
return
pd
.
read_sql
(
query
,
con
=
engine
)
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