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
7b7e1c19
Commit
7b7e1c19
authored
Nov 28, 2017
by
Dr.李
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added api for insert daily portfolio schedule
parent
fb9c5bbc
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
11 deletions
+16
-11
sqlengine.py
alphamind/data/engines/sqlengine.py
+16
-11
No files found.
alphamind/data/engines/sqlengine.py
View file @
7b7e1c19
...
...
@@ -16,6 +16,7 @@ import sqlalchemy as sa
import
sqlalchemy.orm
as
orm
from
sqlalchemy
import
select
,
and_
,
outerjoin
,
join
,
delete
,
insert
from
sqlalchemy.sql
import
func
from
sqlalchemy.sql.expression
import
bindparam
from
alphamind.data.engines.universe
import
Universe
from
alphamind.data.dbmodel.models
import
FactorMaster
from
alphamind.data.dbmodel.models
import
FactorLog
...
...
@@ -33,6 +34,7 @@ from alphamind.data.dbmodel.models import Market
from
alphamind.data.dbmodel.models
import
IndexMarket
from
alphamind.data.dbmodel.models
import
Universe
as
UniverseTable
from
alphamind.data.dbmodel.models
import
Formulas
from
alphamind.data.dbmodel.models
import
DailyPortfoliosSchedule
from
alphamind.data.transformer
import
Transformer
from
alphamind.model.loader
import
load_model
from
alphamind.formula.utilities
import
encode_formula
...
...
@@ -713,7 +715,7 @@ class SqlEngine(object):
del
model_df
[
'model_desc'
]
return
model_df
def
save
_formula
(
self
,
formula_name
,
formula_obj
,
comment
=
None
):
def
insert
_formula
(
self
,
formula_name
,
formula_obj
,
comment
=
None
):
dict_repr
=
encode_formula
(
formula
=
formula_obj
)
query
=
delete
(
Formulas
)
.
where
(
...
...
@@ -745,18 +747,21 @@ class SqlEngine(object):
if
not
df
.
empty
:
return
pd
.
Series
({
name
:
decode_formula
(
df
.
loc
[
name
,
'formula_desc'
][
'desc'
])
for
name
in
df
.
index
})
def
insert_portfolio_schedule
(
self
,
df
):
query
=
insert
(
DailyPortfoliosSchedule
)
.
values
(
{
DailyPortfoliosSchedule
.
portfolio_name
:
bindparam
(
'portfolio_name'
),
DailyPortfoliosSchedule
.
trade_date
:
bindparam
(
'trade_date'
)
}
)
if
__name__
==
'__main__'
:
from
PyFin.api
import
RES
,
LAST
engine
=
SqlEngine
()
self
.
engine
.
execute
(
query
,
df
.
to_dict
(
'record'
))
names
=
[
'eps_q'
,
'BDTO'
,
'CFinc1'
,
'CHV'
,
'IVR'
,
'VAL'
,
'GREV'
,
'DivP'
,
'Volatility'
]
for
name
in
names
:
formula
=
RES
(
20
,
LAST
(
name
)
^
LAST
(
'roe_q'
))
engine
.
save_formula
(
f
'{name}_res'
,
formula
)
if
__name__
==
'__main__'
:
engine
=
SqlEngine
()
formula
=
RES
(
20
,
-
LAST
(
name
)
^
LAST
(
'roe_q'
))
engine
.
save_formula
(
f
'{name}_neg_res'
,
formula
)
df
=
pd
.
DataFrame
(
dict
(
trade_date
=
[
'2017-11-24'
],
portfolio_name
=
[
'test'
])
)
print
(
engine
.
load_all_formulas
())
\ No newline at end of file
engine
.
insert_portfolio_schedule
(
df
)
\ 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