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
dfc774fb
Commit
dfc774fb
authored
Jun 06, 2023
by
wenwen.tang
😕
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add tips
parent
3615cbcd
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
28 additions
and
2 deletions
+28
-2
api.py
api.py
+4
-0
config-svrobo4.yml
config-svrobo4.yml
+1
-0
config-svrobo5.yml
config-svrobo5.yml
+2
-1
builder.py
portfolios/builder.py
+16
-0
solver.py
portfolios/solver.py
+5
-1
No files found.
api.py
View file @
dfc774fb
...
...
@@ -356,6 +356,10 @@ class Solver(ABC):
'''
pass
@
abstractmethod
def
set_transfer_type
(
self
,
transfer_type
):
pass
@
abstractmethod
def
set_navs
(
self
,
navs
):
'''
...
...
config-svrobo4.yml
View file @
dfc774fb
...
...
@@ -90,6 +90,7 @@ portfolios: # 投组模块
max-nan
:
# 最大缺失净值条件
asset
:
8
# 单一资产最多缺少多少交易日数据,则踢出资产池
day
:
0.5
# 单一交易日最多缺少百分之多少净值,则删除该交易日
fixed-ratio
:
true
#是否固定比率,false则从Excel中读取比率
normal-ratio
:
#分别对应低中高风险所占比率
LOW
:
[
0.5
,
0.5
,
0.7
]
HIGH
:
[
0.5
,
0.4
,
0.2
]
...
...
config-svrobo5.yml
View file @
dfc774fb
...
...
@@ -91,6 +91,7 @@ portfolios: # 投组模块
max-nan
:
# 最大缺失净值条件
asset
:
8
# 单一资产最多缺少多少交易日数据,则踢出资产池
day
:
0.5
# 单一交易日最多缺少百分之多少净值,则删除该交易日
fixed-ratio
:
false
#是否固定比率,false则从Excel中读取比率
normal-ratio
:
#US_STOCK:US_HY_BOND:US_IG_BOND三者分别对应低中高风险所占比率
US_STOCK
:
[
0.5
,
0.5
,
0.7
]
US_HY_BOND
:
[
0.4
,
0.4
,
0.2
]
...
...
@@ -235,7 +236,7 @@ robo-executor: # 执行器相关
start-date
:
2012-10-16
# 回测起始日期
end-date
:
2023-03-01
# 回测截止日期
sealing-period
:
10
#调仓封闭期
start-step
:
${BACKTEST_START_STEP:
1
}
# 回测从哪一步开始执行 1:计算资产池;2:计算最优投组:3:计算再平衡信号以及持仓投组
start-step
:
${BACKTEST_START_STEP:
2
}
# 回测从哪一步开始执行 1:计算资产池;2:计算最优投组:3:计算再平衡信号以及持仓投组
end-step
:
${BACKTEST_END_STEP:3}
# 回测从哪一步执行完成后结束执行 1:计算资产池;2:计算最优投组:3:计算再平衡信号以及持仓投组
clean-up
:
true
real
:
# 实盘执行器
...
...
portfolios/builder.py
View file @
dfc774fb
...
...
@@ -59,6 +59,9 @@ class MptPortfoliosBuilder(PortfoliosBuilder):
f
"start to build protfolio of type[{type.name}] and risk[{risk.name}] with date[{format_date(day)}]"
)
solver
=
self
.
_factory
.
create_solver
(
risk
,
type
)
navs_group
=
solver
.
reset_navs
(
day
)
# todo 临时替换比重数据
ratio_list
=
self
.
get_ratio
(
day
)
solver
.
set_transfer_type
(
ratio_list
)
for
category
,
navs
in
navs_group
.
items
():
# count = solver.get_config('asset-count')[0]
# nav_count = len(navs.columns)
...
...
@@ -83,6 +86,19 @@ class MptPortfoliosBuilder(PortfoliosBuilder):
}
return
result
def
get_ratio
(
self
,
date
):
"""
获取当天比重,只能剔除休息日,不知道节假日
@param date:
@return:
"""
import
pandas
as
pd
df
=
pd
.
read_excel
(
'tips.xlsx'
,
index_col
=
'index'
)
df
=
df
[
df
.
index
<=
str
(
date
)]
# 过滤出小于date的行
stg
=
df
[
'STG'
]
.
iloc
[
-
1
]
half
=
(
1
-
stg
)
/
2
return
[
stg
,
half
,
half
]
def
clear
(
self
,
day
=
None
,
risk
:
PortfoliosRisk
=
None
):
rmp
.
delete
(
min_date
=
day
,
risk
=
risk
)
...
...
portfolios/solver.py
View file @
dfc774fb
...
...
@@ -90,9 +90,13 @@ class DefaultSolver(Solver):
@
property
def
transfer_type
(
self
):
self
.
_transfer_type
=
self
.
get_config
(
"normal-ratio"
)
if
self
.
get_config
(
"fixed-ratio"
):
self
.
_transfer_type
=
self
.
get_config
(
"normal-ratio"
)
return
self
.
_transfer_type
def
set_transfer_type
(
self
,
transfer_type
):
self
.
_transfer_type
=
{
k
:
[
v
]
for
k
,
v
in
zip
(
self
.
get_config
(
"normal-ratio"
),
transfer_type
)}
def
set_navs
(
self
,
navs
):
self
.
__navs
=
navs
...
...
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