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
ea826bf8
Commit
ea826bf8
authored
Jan 03, 2023
by
纪超
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
去除警告
parent
0b2f68b7
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
16 additions
and
17 deletions
+16
-17
config.yml
config.yml
+2
-2
curve_drift.py
rebalance/signals/curve_drift.py
+3
-3
right_side.py
rebalance/signals/right_side.py
+11
-12
No files found.
config.yml
View file @
ea826bf8
...
...
@@ -139,7 +139,7 @@ rebalance: # 再平衡模块
signals
:
# 信号相关
crisis-signal
:
# 危机信号相关
exp-years
:
3
# 预警期时长,单位自然年,点到点计算
exp-init
:
2008-01-01
# 设置起始危机预警开始时间,如果关闭初始预警起,注释到这一条即可
#
exp-init: 2008-01-01 # 设置起始危机预警开始时间,如果关闭初始预警起,注释到这一条即可
inversion-years
:
1
# 利率倒挂计算时长,单位自然年,点到点取值
inversion-threshold
:
0.3
# 利率倒挂触发阀值
crisis-1
:
# 危机1相关
...
...
@@ -151,7 +151,7 @@ rebalance: # 再平衡模块
fed-threshold
:
-0.75
# fed判断阀值
right-side
:
# 市场右侧相关
rtn-days
:
5
# 计算spx回报率滚动天数,交易日
min-threshold
:
-0.0
3
# spx回报率跌破阀值
min-threshold
:
-0.0
5
# spx回报率跌破阀值
coef
:
0.95
# 计算cvar的系数
cvar-min-volume
:
30
# 计算cvar至少需要多少交易日数据
high-low-buy
:
# 高低买入相关
...
...
rebalance/signals/curve_drift.py
View file @
ea826bf8
...
...
@@ -29,15 +29,15 @@ class CurveDrift(BaseRebalanceSignal):
last_re
=
rrs
.
get_last_one
(
max_date
=
day
,
risk
=
risk
,
effective
=
True
)
if
last_re
is
None
or
SignalType
(
last_re
[
'type'
])
in
self
.
exclude_last_type
:
return
False
if
last_re
[
'date'
]
+
relativedelta
(
days
=
120
)
<=
day
:
return
True
#
if last_re['date'] + relativedelta(days=120) <= day:
#
return True
hr_datums
=
self
.
_datum
.
get_high_risk_datums
(
risk
)
datum_ids
=
[
x
[
'id'
]
for
x
in
hr_datums
]
normal_portfolio
=
self
.
_builder
.
get_portfolios
(
day
,
risk
)
normal_weight
=
round
(
sum
([
x
[
1
]
for
x
in
normal_portfolio
.
items
()
if
x
[
0
]
in
datum_ids
]),
2
)
hold_portfolio
=
self
.
_hold
.
get_portfolios_weight
(
day
,
risk
)
hold_weight
=
round
(
sum
([
x
[
1
]
for
x
in
hold_portfolio
.
items
()
if
x
[
0
]
in
datum_ids
]),
2
)
return
normal_weight
-
hold_weight
>=
self
.
_solver
.
get_drift
(
day
,
risk
)
return
abs
(
normal_weight
-
hold_weight
)
>=
self
.
_solver
.
get_drift
(
day
,
risk
)
@
property
def
signal_type
(
self
)
->
SignalType
:
...
...
rebalance/signals/right_side.py
View file @
ea826bf8
...
...
@@ -38,19 +38,20 @@ class MarketRight(BaseRebalanceSignal):
def
is_trigger
(
self
,
day
,
risk
:
PortfoliosRisk
)
->
bool
:
last_re
=
rrs
.
get_last_one
(
risk
=
risk
,
max_date
=
day
,
effective
=
True
)
if
last_re
is
not
None
and
SignalType
(
last_re
[
'type'
])
in
[
SignalType
.
CRISIS_ONE
,
SignalType
.
CRISIS_TWO
,
SignalType
.
MARKET_RIGHT
,
SignalType
.
INIT
]:
if
last_re
is
not
None
and
SignalType
(
last_re
[
'type'
])
in
[
SignalType
.
CRISIS_ONE
,
SignalType
.
CRISIS_TWO
,
SignalType
.
MARKET_RIGHT
,
SignalType
.
INIT
]:
return
False
spx
=
self
.
load_spx_close_rtns
(
day
)
if
self
.
is_fall
(
day
,
risk
,
spx
=
spx
):
return
True
#
if self.is_fall(day, risk, spx=spx):
#
return True
if
spx
[
-
1
][
'rtn'
]
>
self
.
min_threshold
:
return
False
cvar
=
self
.
get_cvar
(
day
,
risk
,
spx
=
spx
)
return
cvar
is
not
None
and
spx
[
-
1
][
'rtn'
]
<
cvar
def
is_fall
(
self
,
day
,
risk
:
PortfoliosRisk
,
spx
=
None
):
def
is_fall
(
self
,
day
,
risk
:
PortfoliosRisk
,
spx
=
None
):
if
spx
is
None
:
spx
=
self
.
load_spx_close_rtns
(
day
)
start_date
=
self
.
find_cvar_start_date
(
day
,
risk
,
spx
=
spx
)
...
...
@@ -60,7 +61,7 @@ class MarketRight(BaseRebalanceSignal):
return
spx
.
iloc
[
-
1
]
.
close
<
spx
.
iloc
[
0
]
.
close
return
False
def
get_cvar
(
self
,
day
,
risk
:
PortfoliosRisk
,
spx
=
None
):
def
get_cvar
(
self
,
day
,
risk
:
PortfoliosRisk
,
spx
=
None
):
if
spx
is
None
:
spx
=
self
.
load_spx_close_rtns
(
day
)
start_date
=
self
.
find_cvar_start_date
(
day
,
risk
,
spx
=
spx
)
...
...
@@ -74,12 +75,14 @@ class MarketRight(BaseRebalanceSignal):
return
mean
-
std
*
norm
.
pdf
(
norm
.
ppf
(
alpha
))
/
alpha
return
None
def
find_cvar_start_date
(
self
,
day
,
risk
:
PortfoliosRisk
,
spx
=
None
):
def
find_cvar_start_date
(
self
,
day
,
risk
:
PortfoliosRisk
,
spx
=
None
):
if
spx
is
None
:
spx
=
self
.
load_spx_close_rtns
(
day
)
spx
=
pd
.
DataFrame
(
spx
)
last_right
=
rrs
.
get_last_one
(
type
=
(
SignalType
.
MARKET_RIGHT
,
SignalType
.
INIT
),
max_date
=
day
,
risk
=
risk
,
effective
=
True
)
last_buy
=
rrs
.
get_first_after
(
type
=
(
SignalType
.
LOW_BUY
,
SignalType
.
HIGH_BUY
),
risk
=
risk
,
effective
=
True
,
min_date
=
last_right
[
'date'
])
last_right
=
rrs
.
get_last_one
(
type
=
(
SignalType
.
MARKET_RIGHT
,
SignalType
.
INIT
),
max_date
=
day
,
risk
=
risk
,
effective
=
True
)
last_buy
=
rrs
.
get_first_after
(
type
=
(
SignalType
.
LOW_BUY
,
SignalType
.
HIGH_BUY
),
risk
=
risk
,
effective
=
True
,
min_date
=
last_right
[
'date'
])
if
not
last_buy
or
not
last_right
or
last_buy
[
'date'
]
<=
last_right
[
'date'
]:
return
None
spx
=
spx
[(
spx
[
'date'
]
>=
last_right
[
'date'
])
&
(
spx
[
'date'
]
<=
last_buy
[
'date'
])]
...
...
@@ -94,7 +97,3 @@ class MarketRight(BaseRebalanceSignal):
spx
.
dropna
(
inplace
=
True
)
spx
=
spx
[[
'date'
,
'close'
,
'rtn'
]]
return
spx
.
to_dict
(
'records'
)
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