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
b2d66be7
Commit
b2d66be7
authored
Apr 03, 2024
by
wenwen.tang
😕
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
https://www.tapd.cn/59187493/documents/show/1159187493001000730
依照文档进行模型优化
parent
1647ce65
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
6 additions
and
6 deletions
+6
-6
solver.py
portfolios/solver.py
+0
-2
utils.py
portfolios/utils.py
+6
-4
No files found.
portfolios/solver.py
View file @
b2d66be7
...
@@ -452,8 +452,6 @@ class PRRSolver(ARCSolver):
...
@@ -452,8 +452,6 @@ class PRRSolver(ARCSolver):
model
.
cons_RR_LE_TRR
=
Constraint
(
model
.
cons_RR_LE_TRR
=
Constraint
(
expr
=
sum
([
model
.
w
[
i
]
*
RR_LE_TRR
[
i
]
for
i
in
model
.
indices
])
>=
minRRweightWithinTRR
)
expr
=
sum
([
model
.
w
[
i
]
*
RR_LE_TRR
[
i
]
for
i
in
model
.
indices
])
>=
minRRweightWithinTRR
)
# todo trr<指定值
# model.cons_LE_TRR = Constraint(expr=sum([model.w[i] * RR[i] for i in model.indices]) <= TRR)
if
TRR
<
5
:
if
TRR
<
5
:
model
.
cons_RR_in_1_5
=
Constraint
(
model
.
cons_RR_in_1_5
=
Constraint
(
expr
=
sum
([
model
.
z
[
i
]
*
(
RR_in_1_5
[
i
]
*
self
.
max_count
-
RR_EQ_5
[
i
])
for
i
in
model
.
indices
])
>=
0
)
expr
=
sum
([
model
.
z
[
i
]
*
(
RR_in_1_5
[
i
]
*
self
.
max_count
-
RR_EQ_5
[
i
])
for
i
in
model
.
indices
])
>=
0
)
...
...
portfolios/utils.py
View file @
b2d66be7
import
pandas
as
pd
import
pandas
as
pd
from
py_jftech
import
autowired
from
py_jftech
import
autowired
,
get_config
from
api
import
DatumType
,
Datum
from
api
import
DatumType
,
Datum
...
@@ -38,10 +38,12 @@ def format_weight(weight: dict, to=1) -> dict:
...
@@ -38,10 +38,12 @@ def format_weight(weight: dict, to=1) -> dict:
if
weight_series
.
sum
()
==
to
:
if
weight_series
.
sum
()
==
to
:
return
dict
(
weight_series
)
return
dict
(
weight_series
)
id_sort
=
sorted
(
weight_series
.
to_dict
()
.
keys
(),
key
=
lambda
x
:
risk_dict
.
get
(
int
(
x
)))
id_sort
=
sorted
(
weight_series
.
to_dict
()
.
keys
(),
key
=
lambda
x
:
risk_dict
.
get
(
int
(
x
)))
low
=
get_config
(
'portfolios.solver.mpt.low-weight'
)
high
=
get_config
(
'portfolios.solver.mpt.high-weight'
)[
0
]
# 低风险
# 低风险
minidx
=
id_sort
[
0
]
minidx
=
[
i
for
i
in
id_sort
if
weight
[
i
]
<
high
]
[
0
]
# 高风险
# 高风险
maxidx
=
id_sort
[
-
1
]
maxidx
=
[
i
for
i
in
id_sort
if
weight
[
i
]
>
low
]
[
-
1
]
if
weight_series
.
sum
()
<
to
:
if
weight_series
.
sum
()
<
to
:
weight_series
[
minidx
]
+=
to
-
weight_series
.
sum
()
weight_series
[
minidx
]
+=
to
-
weight_series
.
sum
()
elif
weight_series
.
sum
()
>
to
:
elif
weight_series
.
sum
()
>
to
:
...
@@ -50,4 +52,4 @@ def format_weight(weight: dict, to=1) -> dict:
...
@@ -50,4 +52,4 @@ def format_weight(weight: dict, to=1) -> dict:
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
format_weight
({
"5"
:
0.35
,
"6"
:
0.35
,
"10"
:
0.
09
,
"11"
:
0.16
,
"22"
:
0.05
})
format_weight
({
"5"
:
0.35
,
"6"
:
0.35
,
"10"
:
0.
1
,
"11"
:
0.16
,
"22"
:
0.05
})
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