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
9e3342ed
Commit
9e3342ed
authored
Nov 28, 2017
by
Dr.李
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added update and instert positions api
parent
faa4de60
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
0 deletions
+24
-0
sqlengine.py
alphamind/data/engines/sqlengine.py
+24
-0
No files found.
alphamind/data/engines/sqlengine.py
View file @
9e3342ed
...
...
@@ -36,6 +36,7 @@ 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.dbmodel.models
import
Performance
from
alphamind.data.dbmodel.models
import
Positions
from
alphamind.data.transformer
import
Transformer
from
alphamind.model.loader
import
load_model
from
alphamind.formula.utilities
import
encode_formula
...
...
@@ -779,6 +780,29 @@ class SqlEngine(object):
self
.
engine
.
execute
(
query
)
df
.
to_sql
(
Performance
.
__table__
.
name
,
self
.
engine
,
if_exists
=
'append'
,
index
=
False
)
def
upsert_positions
(
self
,
ref_date
,
df
):
universes
=
df
.
universe
.
unique
()
benchmarks
=
df
.
benchmark
.
unique
()
build_types
=
df
.
type
.
unique
()
sources
=
df
.
source
.
unique
()
portfolios
=
df
.
portfolio
.
unique
()
query
=
delete
(
Positions
)
.
where
(
Positions
.
trade_date
==
ref_date
,
Positions
.
type
.
in_
(
build_types
),
Positions
.
universe
.
in_
(
universes
),
Positions
.
benchmark
.
in_
(
benchmarks
),
Positions
.
source
.
in_
(
sources
),
Positions
.
portfolio
.
in_
(
portfolios
)
)
self
.
engine
.
execute
(
query
)
df
.
to_sql
(
Positions
.
__table__
.
name
,
self
.
engine
,
if_exists
=
'append'
,
index
=
False
,
dtype
=
{
'weight'
:
sa
.
types
.
JSON
})
if
__name__
==
'__main__'
:
engine
=
SqlEngine
()
...
...
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