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
66653eb0
Commit
66653eb0
authored
Jan 06, 2023
by
jichao
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'origin/master'
parents
19c41851
f6bcc9cb
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
13 deletions
+12
-13
config.yml
config.yml
+1
-1
right_side.py
rebalance/signals/right_side.py
+11
-12
No files found.
config.yml
View file @
66653eb0
...
...
@@ -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相关
...
...
rebalance/signals/right_side.py
View file @
66653eb0
...
...
@@ -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