Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
A
alpha-mind
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
Dr.李
alpha-mind
Commits
d3bf7111
Commit
d3bf7111
authored
Mar 05, 2018
by
Dr.李
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
using long short
parent
771804b0
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
6 additions
and
18 deletions
+6
-18
crosssetctions.py
alphamind/analysis/crosssetctions.py
+6
-18
No files found.
alphamind/analysis/crosssetctions.py
View file @
d3bf7111
...
@@ -8,9 +8,8 @@ Created on 2018-3-5
...
@@ -8,9 +8,8 @@ Created on 2018-3-5
import
numpy
as
np
import
numpy
as
np
import
pandas
as
pd
import
pandas
as
pd
import
statsmodels.api
as
sm
import
statsmodels.api
as
sm
from
alphamind.portfolio.constraints
import
LinearConstraints
from
alphamind.analysis.factoranalysis
import
er_portfolio_analysis
from
alphamind.utilities
import
alpha_logger
from
alphamind.utilities
import
alpha_logger
from
alphamind.data.neutralize
import
neutralize
def
cross_section_analysis
(
ref_date
,
def
cross_section_analysis
(
ref_date
,
...
@@ -18,9 +17,6 @@ def cross_section_analysis(ref_date,
...
@@ -18,9 +17,6 @@ def cross_section_analysis(ref_date,
universe
,
universe
,
horizon
,
horizon
,
constraint_risk
,
constraint_risk
,
linear_bounds
,
lbound
,
ubound
,
engine
):
engine
):
codes
=
engine
.
fetch_codes
(
ref_date
,
universe
)
codes
=
engine
.
fetch_codes
(
ref_date
,
universe
)
...
@@ -33,23 +29,14 @@ def cross_section_analysis(ref_date,
...
@@ -33,23 +29,14 @@ def cross_section_analysis(ref_date,
total_data
=
pd
.
merge
(
total_data
,
industry_matrix
,
on
=
'code'
)
.
dropna
()
total_data
=
pd
.
merge
(
total_data
,
industry_matrix
,
on
=
'code'
)
.
dropna
()
total_risk_exp
=
total_data
[
constraint_risk
]
total_risk_exp
=
total_data
[
constraint_risk
]
constraints
=
LinearConstraints
(
linear_bounds
,
total_risk_exp
)
er
=
total_data
[
factor_name
]
.
values
.
astype
(
float
)
er
=
total_data
[
factor_name
]
.
values
.
astype
(
float
)
er
=
neutralize
(
total_risk_exp
.
values
,
er
)
.
flatten
()
industry
=
total_data
.
industry_name
.
values
industry
=
total_data
.
industry_name
.
values
target_pos
,
_
=
er_portfolio_analysis
(
er
,
industry
,
None
,
constraints
,
False
,
None
,
method
=
'risk_neutral'
,
lbound
=
lbound
*
np
.
ones
(
len
(
er
)),
ubound
=
ubound
*
np
.
ones
(
len
(
er
)))
codes
=
total_data
.
code
.
tolist
()
codes
=
total_data
.
code
.
tolist
()
target_pos
[
'code'
]
=
codes
target_pos
=
pd
.
DataFrame
({
'code'
:
codes
,
'weight'
:
er
,
'industry'
:
industry
})
target_pos
[
'weight'
]
=
target_pos
[
'weight'
]
/
target_pos
[
'weight'
]
.
abs
()
.
sum
()
target_pos
[
'weight'
]
=
target_pos
[
'weight'
]
/
target_pos
[
'weight'
]
.
abs
()
.
sum
()
dx_returns
=
engine
.
fetch_dx_return
(
ref_date
,
codes
,
horizon
=
horizon
,
offset
=
1
)
dx_returns
=
engine
.
fetch_dx_return
(
ref_date
,
codes
,
horizon
=
horizon
,
offset
=
1
)
...
@@ -63,4 +50,5 @@ def cross_section_analysis(ref_date,
...
@@ -63,4 +50,5 @@ def cross_section_analysis(ref_date,
t_stats
=
results
.
tvalues
[
1
]
t_stats
=
results
.
tvalues
[
1
]
alpha_logger
.
info
(
f
"{ref_date} is finished with {len(target_pos)} stocks for {factor_name}"
)
alpha_logger
.
info
(
f
"{ref_date} is finished with {len(target_pos)} stocks for {factor_name}"
)
alpha_logger
.
info
(
f
"{ref_date} risk_exposure {target_pos.weight.values @ total_risk_exp.values}"
)
return
port_ret
,
ic
,
t_stats
return
port_ret
,
ic
,
t_stats
\ No newline at end of file
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