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
edd65798
Commit
edd65798
authored
Aug 29, 2017
by
Dr.李
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
commit model training new example
parent
6d06e29d
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
7 deletions
+16
-7
model_training.py
alphamind/examples/model_training.py
+15
-7
data_preparing.py
alphamind/model/data_preparing.py
+1
-0
No files found.
alphamind/examples/model_training.py
View file @
edd65798
...
@@ -31,15 +31,16 @@ training - every 4 week
...
@@ -31,15 +31,16 @@ training - every 4 week
engine
=
SqlEngine
(
'postgresql+psycopg2://postgres:A12345678!@10.63.6.220/alpha'
)
engine
=
SqlEngine
(
'postgresql+psycopg2://postgres:A12345678!@10.63.6.220/alpha'
)
universe
=
Universe
(
'zz500'
,
[
'zz500'
])
universe
=
Universe
(
'zz500'
,
[
'zz500'
])
neutralize_risk
=
[
'SIZE'
]
+
industry_styles
neutralize_risk
=
industry_styles
alpha_factors
=
[
'RVOL'
,
'EPS'
,
'CFinc1'
,
'BDTO'
,
'VAL'
,
'GREV'
,
alpha_factors
=
[
'RVOL'
,
'EPS'
,
'CFinc1'
,
'BDTO'
,
'VAL'
,
'CHV'
,
'GREV'
,
'ROEDiluted'
]
# ['BDTO', 'RVOL', 'CHV', 'VAL', 'CFinc1'] # risk_styles
'ROEDiluted'
]
# ['BDTO', 'RVOL', 'CHV', 'VAL', 'CFinc1'] # risk_styles
benchmark
=
905
benchmark
=
905
n_bins
=
5
n_bins
=
5
frequency
=
'1w'
frequency
=
'1w'
batch
=
4
batch
=
4
start_date
=
'201
1-01-05
'
start_date
=
'201
2-01-01
'
end_date
=
'2017-08-31'
end_date
=
'2017-08-31'
method
=
'rank'
use_rank
=
100
'''
'''
fetch data from target data base and do the corresponding data processing
fetch data from target data base and do the corresponding data processing
...
@@ -143,16 +144,23 @@ for i, predict_date in enumerate(dates):
...
@@ -143,16 +144,23 @@ for i, predict_date in enumerate(dates):
constraints
=
cons
,
constraints
=
cons
,
detail_analysis
=
True
,
detail_analysis
=
True
,
benchmark
=
benchmark_w
,
benchmark
=
benchmark_w
,
is_tradable
=
is_tradable
)
is_tradable
=
is_tradable
,
method
=
method
,
use_rank
=
use_rank
)
model_res
=
pd
.
DataFrame
({
'weight'
:
model
.
coef_
[
0
],
'factor'
:
np
.
array
(
data_package
[
'x_names'
])})
# model_res.to_csv(r'\\10.63.6.71\sharespace\personal\licheng\portfolio\zz500_model\{0}.csv'.format(predict_date.strftime('%Y-%m-%d')))
final_res
[
i
]
=
analysis
[
'er'
][
'total'
]
/
benchmark_w
.
sum
()
final_res
[
i
]
=
analysis
[
'er'
][
'total'
]
/
benchmark_w
.
sum
()
print
(
'trade_date: {0} predicting finished'
.
format
(
train
_date
))
print
(
'trade_date: {0} predicting finished'
.
format
(
predict
_date
))
last_date
=
advanceDateByCalendar
(
'china.sse'
,
dates
[
-
1
],
frequency
)
last_date
=
advanceDateByCalendar
(
'china.sse'
,
dates
[
-
1
],
frequency
)
df
=
pd
.
Series
(
final_res
,
index
=
dates
[
1
:]
+
[
last_date
])
df
=
pd
.
Series
(
final_res
,
index
=
dates
[
1
:]
+
[
last_date
])
df
.
sort_index
(
inplace
=
True
)
df
.
sort_index
(
inplace
=
True
)
df
.
cumsum
()
.
plot
()
df
.
cumsum
()
.
plot
()
plt
.
title
(
'
Risk style factors model training with Linear Regression from 2012 - 2017
'
)
plt
.
title
(
'
Prod factors model Linear Regression (neutralized Industries rank 100)
'
)
plt
.
show
()
plt
.
show
()
alphamind/model/data_preparing.py
View file @
edd65798
...
@@ -180,6 +180,7 @@ def fetch_data_package(engine: SqlEngine,
...
@@ -180,6 +180,7 @@ def fetch_data_package(engine: SqlEngine,
alpha_logger
.
info
(
"Data processing is finished"
)
alpha_logger
.
info
(
"Data processing is finished"
)
ret
=
dict
()
ret
=
dict
()
ret
[
'x_names'
]
=
transformer
.
names
ret
[
'settlement'
]
=
return_df
ret
[
'settlement'
]
=
return_df
ret
[
'train'
]
=
{
'x'
:
train_x_buckets
,
'y'
:
train_y_buckets
}
ret
[
'train'
]
=
{
'x'
:
train_x_buckets
,
'y'
:
train_y_buckets
}
ret
[
'predict'
]
=
{
'x'
:
predict_x_buckets
}
ret
[
'predict'
]
=
{
'x'
:
predict_x_buckets
}
...
...
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