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
319fff13
Commit
319fff13
authored
Feb 06, 2018
by
Dr.李
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added more
parent
01f16109
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
64 additions
and
3 deletions
+64
-3
allocations.py
alphamind/portfolio/allocations.py
+64
-3
No files found.
alphamind/portfolio/allocations.py
View file @
319fff13
...
...
@@ -24,6 +24,15 @@ class Allocation(object):
self
.
maximum
=
maximum
self
.
current
=
current
pyFinAssert
(
self
.
minimum
<=
self
.
current
,
ValueError
,
"minimum qty should be lower than current"
)
pyFinAssert
(
self
.
maximum
>=
self
.
current
,
ValueError
,
"minimum qty should be greater than current"
)
def
__repr__
(
self
):
return
"Allocation(code={0}, minimum={1}, maximum={2}, current={3})"
.
format
(
self
.
code
,
self
.
minimum
,
self
.
maximum
,
self
.
current
)
class
Portfolio
(
object
):
...
...
@@ -39,6 +48,14 @@ class Portfolio(object):
except
KeyError
:
return
Allocation
(
code
,
0
,
0
,
0
)
def
__repr__
(
self
):
return
"Portfolio(name={0}, allocations={1})"
.
format
(
self
.
name
,
list
(
self
.
allocations
.
values
()))
@
property
def
codes
(
self
)
->
List
[
int
]:
return
sorted
(
self
.
allocations
.
keys
())
class
Execution
(
object
):
...
...
@@ -50,6 +67,11 @@ class Execution(object):
self
.
qty
=
qty
self
.
comment
=
comment
def
__repr__
(
self
):
return
"Execution(code={0}, qty={1}, comment={2})"
.
format
(
self
.
code
,
self
.
qty
,
self
.
comment
)
class
Executions
(
object
):
...
...
@@ -57,7 +79,11 @@ class Executions(object):
name
,
executions
:
List
[
Execution
]
=
None
):
self
.
name
=
name
self
.
executions
=
{
e
.
code
:
e
.
qty
for
e
in
executions
}
self
.
executions
=
executions
def
__repr__
(
self
):
return
"Executions(name={0}, executions={1})"
.
format
(
self
.
name
,
self
.
executions
)
class
Asset
(
object
):
...
...
@@ -71,20 +97,36 @@ class Asset(object):
self
.
name
=
name
if
priority
:
self
.
priority
=
set
(
priority
)
else
:
self
.
priority
=
set
()
if
forbidden
:
self
.
forbidden
=
set
(
forbidden
)
else
:
self
.
forbidden
=
set
()
self
.
_validation
()
def
_validation
(
self
):
for
p
in
self
.
priority
:
pyFinAssert
(
p
not
in
self
.
forbidden
,
ValueError
,
"{0} in priority is in forbidden"
.
format
(
p
))
def
__repr__
(
self
):
return
"Asset(code={0}, name={1}, priority={2}, forbidden={3})"
.
format
(
self
.
code
,
self
.
name
,
self
.
priority
,
self
.
forbidden
)
class
TargetPositions
(
object
):
def
__init__
(
self
):
self
.
targets
=
{}
def
__init__
(
self
,
assets
:
List
[
Asset
]
=
None
,
qtys
:
List
[
int
]
=
None
):
if
assets
:
self
.
targets
=
{
asset
.
code
:
(
asset
,
qty
)
for
asset
,
qty
in
zip
(
assets
,
qtys
)}
else
:
self
.
targets
=
{}
def
add_asset
(
self
,
asset
:
Asset
,
...
...
@@ -100,6 +142,9 @@ class TargetPositions(object):
def
codes
(
self
)
->
List
[
int
]:
return
sorted
(
self
.
targets
.
keys
())
def
__repr__
(
self
):
return
"TargetPositions(assets={0}, qtys={1})"
.
format
(
*
zip
(
*
self
.
targets
.
values
()))
def
handle_one_asset
(
pre_allocation
:
Allocation
,
asset
:
Asset
,
...
...
@@ -159,5 +204,21 @@ def pass_through(target_pos: TargetPositions,
return
Executions
(
p_name
,
executions
),
Portfolio
(
p_name
,
allocations
),
new_target_pos
if
__name__
==
'__main__'
:
asset1
=
Asset
(
1
,
'a'
)
asset2
=
Asset
(
2
,
'b'
)
asset3
=
Asset
(
3
,
'b'
)
target_pos
=
TargetPositions
([
asset1
,
asset2
,
asset3
],
[
200
,
300
,
100
])
allc1
=
Allocation
(
1
,
0
,
100
,
0
)
allc2
=
Allocation
(
2
,
0
,
400
,
100
)
allc2
=
Allocation
(
3
,
0
,
400
,
200
)
portfolio
=
Portfolio
(
'test1'
,
[
allc1
,
allc2
])
executions
,
portfolio
,
target_pos
=
pass_through
(
target_pos
,
portfolio
)
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