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
6ec07856
Commit
6ec07856
authored
Dec 28, 2022
by
jichao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
同步汇率
parent
b2f4f7b7
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
2 deletions
+16
-2
right_side.py
rebalance/signals/right_side.py
+15
-1
test_case.py
rebalance/test_case.py
+1
-1
No files found.
rebalance/signals/right_side.py
View file @
6ec07856
...
...
@@ -41,11 +41,25 @@ class MarketRight(BaseRebalanceSignal):
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
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
):
if
spx
is
None
:
spx
=
self
.
load_spx_close_rtns
(
day
)
start_date
=
self
.
find_cvar_start_date
(
day
,
risk
,
spx
=
spx
)
if
start_date
:
spx
=
pd
.
DataFrame
(
spx
)
spx
=
spx
[(
spx
.
date
>=
start_date
)
&
(
spx
.
date
<=
day
)]
return
spx
.
iloc
[
-
1
]
.
close
<
spx
.
iloc
[
0
]
.
close
return
False
def
get_cvar
(
self
,
day
,
risk
:
PortfoliosRisk
,
spx
=
None
):
if
spx
is
None
:
spx
=
self
.
load_spx_close_rtns
(
day
)
...
...
@@ -65,7 +79,7 @@ class MarketRight(BaseRebalanceSignal):
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_
last_one
(
type
=
(
SignalType
.
LOW_BUY
,
SignalType
.
HIGH_BUY
),
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'
])]
...
...
rebalance/test_case.py
View file @
6ec07856
...
...
@@ -33,7 +33,7 @@ class RebalanceTest(unittest.TestCase):
@
autowired
(
names
=
{
'builder'
:
'market-right'
})
def
test_market_right
(
self
,
builder
:
RebalanceSignal
=
None
):
signal
=
builder
.
get_signal
(
parse_date
(
'2022-
10-13
'
),
PortfoliosRisk
.
FT9
)
signal
=
builder
.
get_signal
(
parse_date
(
'2022-
02-22
'
),
PortfoliosRisk
.
FT9
)
logger
.
info
(
signal
)
@
autowired
(
names
=
{
'builder'
:
'curve-drift'
})
...
...
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