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
64080a96
Commit
64080a96
authored
Nov 02, 2023
by
wenwen.tang
😕
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
回测nav的计算用复权净值
parent
f1d06bf7
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
3 deletions
+15
-3
holder.py
portfolios/holder.py
+15
-3
No files found.
portfolios/holder.py
View file @
64080a96
...
...
@@ -245,7 +245,9 @@ class InvTrustPortfoliosHolder(DividendPortfoliosHolder):
if
last_nav
:
# 若非首次配息
share
=
{
int
(
x
):
y
for
x
,
y
in
json
.
loads
(
last_nav
[
'portfolios'
])[
'share'
]
.
items
()}
# 参与配息的基金份额
share_nav
=
{
int
(
x
):
y
for
x
,
y
in
json
.
loads
(
last_nav
[
'portfolios'
])[
'share_nav'
]
.
items
()}
share_nodiv_nav
=
{
int
(
x
):
y
for
x
,
y
in
json
.
loads
(
last_nav
[
'portfolios'
])[
'share_nodiv_nav'
]
.
items
()}
fund_div_tuple
=
self
.
get_navs_and_div
(
fund_ids
=
tuple
(
set
(
weight
)
|
set
(
share
)),
day
=
day
)
navs
=
fund_div_tuple
[
0
]
fund_dividend
=
fund_div_tuple
[
1
]
...
...
@@ -256,13 +258,14 @@ class InvTrustPortfoliosHolder(DividendPortfoliosHolder):
map
(
lambda
k
:
share
[
k
]
*
fund_dividend
[
k
],
filter
(
lambda
k
:
k
in
fund_dividend
,
share
.
keys
())))
dividend_acc
=
last_nav
[
'div_acc'
]
+
fund_dividend
fund_av
=
round
(
sum
([
navs
[
x
]
*
y
for
x
,
y
in
share
.
items
()]),
4
)
nav
=
round
(
sum
([
nav_cals
[
x
]
*
y
for
x
,
y
in
share
.
items
()]),
4
)
fund_nav
=
round
(
sum
([
navs
[
x
]
*
y
for
x
,
y
in
share_nav
.
items
()]),
4
)
nav
=
round
(
sum
([
nav_cals
[
x
]
*
y
for
x
,
y
in
share_nodiv_nav
.
items
()]),
4
)
fund_nav
+=
fund_dividend_nav
asset_nav
=
fund_av
share
=
{
x
:
fund_av
*
w
/
navs
[
x
]
for
x
,
w
in
weight
.
items
()}
# 若调仓当日,有基金产生配息
share_nav
=
{
x
:
fund_nav
*
w
/
navs
[
x
]
for
x
,
w
in
weight
.
items
()}
share_nodiv_nav
=
{
x
:
nav
*
w
/
nav_cals
[
x
]
for
x
,
w
in
weight
.
items
()}
if
self
.
is_first_workday
(
day
):
div_forecast
=
asset_nav
*
self
.
month_dividend
else
:
...
...
@@ -277,6 +280,8 @@ class InvTrustPortfoliosHolder(DividendPortfoliosHolder):
funds_subscription_rate
=
{
fund
[
'id'
]:
fund
.
get
(
'subscriptionRate'
,
0
)
for
fund
in
funds
}
share
=
{
x
:
(
1
-
funds_subscription_rate
[
x
])
*
(
fund_av
*
w
)
/
navs
[
x
]
for
x
,
w
in
weight
.
items
()}
share_nav
=
share
# 不考虑配息
share_nodiv_nav
=
share
# 初始买入扣手续费
fee
=
sum
(
funds_subscription_rate
[
x
]
*
(
fund_av
*
w
)
for
x
,
w
in
weight
.
items
())
fund_av
=
fund_av
-
fee
...
...
@@ -293,8 +298,10 @@ class InvTrustPortfoliosHolder(DividendPortfoliosHolder):
'portfolios'
:
{
'weight'
:
weight
,
'weight_nav'
:
weight
,
'weight_nodiv_nav'
:
weight
,
'share'
:
share
,
'share_nav'
:
share_nav
,
'share_nodiv_nav'
:
share_nodiv_nav
},
'fund_av'
:
fund_av
,
'fund_nav'
:
fund_nav
,
...
...
@@ -314,6 +321,7 @@ class InvTrustPortfoliosHolder(DividendPortfoliosHolder):
dividend_acc
=
last_nav
[
'div_acc'
]
share
=
{
int
(
x
):
y
for
x
,
y
in
json
.
loads
(
last_nav
[
'portfolios'
])[
'share'
]
.
items
()}
share_nav
=
{
int
(
x
):
y
for
x
,
y
in
json
.
loads
(
last_nav
[
'portfolios'
])[
'share_nav'
]
.
items
()}
share_nodiv_nav
=
{
int
(
x
):
y
for
x
,
y
in
json
.
loads
(
last_nav
[
'portfolios'
])[
'share_nodiv_nav'
]
.
items
()}
fund_div_tuple
=
self
.
get_navs_and_div
(
fund_ids
=
tuple
(
share
),
day
=
day
)
navs
=
fund_div_tuple
[
0
]
fund_dividend
=
fund_div_tuple
[
1
]
...
...
@@ -333,12 +341,14 @@ class InvTrustPortfoliosHolder(DividendPortfoliosHolder):
map
(
lambda
k
:
share
[
k
]
*
fund_dividend
[
k
],
filter
(
lambda
k
:
k
in
fund_dividend
,
share
.
keys
())))
dividend_acc
=
dividend_acc
+
port_div
+
fund_dividend
fund_av
=
round
(
sum
([
navs
[
x
]
*
y
for
x
,
y
in
share
.
items
()]),
4
)
nav
=
round
(
sum
([
nav_cals
[
x
]
*
y
for
x
,
y
in
share
.
items
()]),
4
)
nav
=
round
(
sum
([
nav_cals
[
x
]
*
y
for
x
,
y
in
share
_nodiv_nav
.
items
()]),
4
)
fund_nav
=
round
(
sum
([
navs
[
x
]
*
y
for
x
,
y
in
share_nav
.
items
()]),
4
)
weight
=
{
x
:
round
(
y
*
navs
[
x
]
/
fund_av
,
2
)
for
x
,
y
in
share
.
items
()}
weight_nodiv_nav
=
{
x
:
round
(
y
*
nav_cals
[
x
]
/
nav
,
2
)
for
x
,
y
in
share_nav
.
items
()}
weight_nav
=
{
x
:
round
(
y
*
navs
[
x
]
/
fund_av
,
2
)
for
x
,
y
in
share_nav
.
items
()}
weight
=
format_weight
(
weight
)
weight_nav
=
format_weight
(
weight_nav
)
weight_nodiv_nav
=
format_weight
(
weight_nodiv_nav
)
asset_nav
=
fund_av
div_forecast
=
last_nav
[
'div_forecast'
]
if
self
.
is_first_workday
(
day
):
...
...
@@ -354,8 +364,10 @@ class InvTrustPortfoliosHolder(DividendPortfoliosHolder):
'portfolios'
:
{
'weight'
:
weight
,
'weight_nav'
:
weight_nav
,
'weight_nodiv_nav'
:
weight_nodiv_nav
,
'share'
:
share
,
'share_nav'
:
share_nav
'share_nav'
:
share_nav
,
'share_nodiv_nav'
:
share_nodiv_nav
},
'fund_av'
:
fund_av
,
'fund_nav'
:
fund_nav
,
...
...
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