Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
R
robo-dividend
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
wenwen.tang
robo-dividend
Commits
1eff3e20
Commit
1eff3e20
authored
Apr 02, 2024
by
wenwen.tang
😕
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
https://www.tapd.cn/59187493/documents/show/1159187493001000730
依照文档进行模型优化
parent
3153ede2
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
3 deletions
+14
-3
utils.py
portfolios/utils.py
+14
-3
No files found.
portfolios/utils.py
View file @
1eff3e20
...
...
@@ -3,9 +3,20 @@ from py_jftech import autowired
from
api
import
DatumType
,
Datum
risk_dict
=
{}
@
autowired
def
format_weight
(
weight
:
dict
,
to
=
1
,
datum
:
Datum
=
None
)
->
dict
:
def
build_risk_dict
(
datum
:
Datum
=
None
):
global
risk_dict
if
risk_dict
:
pass
else
:
funds
=
datum
.
get_datums
(
type
=
DatumType
.
FUND
)
risk_dict
=
{
fund
[
'id'
]:
fund
[
'risk'
]
for
fund
in
funds
}
def
format_weight
(
weight
:
dict
,
to
=
1
)
->
dict
:
"""
对权重的小数点进行截取,到指定权重
@param datum:
...
...
@@ -13,19 +24,19 @@ def format_weight(weight: dict, to=1, datum: Datum = None) -> dict:
@param to: 指定权重
@return:
"""
# funds = datum.get_datums(type=DatumType.FUND)
# risk_dict = {fund['id']: fund['risk'] for fund in funds}
# risk = 0
# for k, v in weight.items():
# risk += risk_dict.get(int(k)) * v
# print(risk)
build_risk_dict
()
weight_series
=
pd
.
Series
(
weight
)
weight_series
=
weight_series
.
fillna
(
0
)
weight_series
=
weight_series
.
apply
(
lambda
x
:
round
(
x
,
2
))
if
weight_series
.
sum
()
==
to
:
return
dict
(
weight_series
)
funds
=
datum
.
get_datums
(
type
=
DatumType
.
FUND
)
risk_dict
=
{
fund
[
'id'
]:
fund
[
'risk'
]
for
fund
in
funds
}
id_sort
=
sorted
(
weight_series
.
to_dict
()
.
keys
(),
key
=
lambda
x
:
risk_dict
.
get
(
int
(
x
)))
# 低风险
minidx
=
id_sort
[
0
]
...
...
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