|
1
|
|
|
"""Tests the Portfolio accumulation of underlying assets.""" |
|
2
|
|
|
|
|
3
|
|
|
from __future__ import absolute_import |
|
4
|
|
|
|
|
5
|
|
|
import copy |
|
6
|
|
|
import unittest |
|
7
|
|
|
import trade_app.trade.holder as accumulator |
|
8
|
|
|
|
|
9
|
|
|
from fixtures.operation_sequences import ( |
|
10
|
|
|
OPERATION_SEQUENCE20, OPERATION_SEQUENCE21 |
|
11
|
|
|
) |
|
12
|
|
|
from fixtures.assets import ASSET, OPTION1 |
|
13
|
|
|
from fixtures.accumulator_states import ( |
|
14
|
|
|
STATE06, STATE07, STATE08, |
|
15
|
|
|
) |
|
16
|
|
|
|
|
17
|
|
|
|
|
18
|
|
|
class TestPortfolio(unittest.TestCase): |
|
19
|
|
|
"""Base class for Portfolio tests.""" |
|
20
|
|
|
|
|
21
|
|
|
initial_state = None |
|
22
|
|
|
operations = [] |
|
23
|
|
|
state = {} |
|
24
|
|
|
|
|
25
|
|
|
def setUp(self): |
|
26
|
|
|
self.portfolio = accumulator.Holder(state=self.initial_state) |
|
27
|
|
|
for operation in self.operations: |
|
28
|
|
|
self.portfolio.accumulate(copy.deepcopy(operation)) |
|
29
|
|
|
|
|
30
|
|
|
def test_accumulators_states(self): |
|
31
|
|
|
"""Test the state of each accumulator.""" |
|
32
|
|
|
for asset, state in self.state.items(): |
|
33
|
|
|
for key in state.keys(): |
|
34
|
|
|
self.assertEqual( |
|
35
|
|
|
self.portfolio.subjects[asset].state[key], |
|
36
|
|
|
state[key] |
|
37
|
|
|
) |
|
38
|
|
|
|
|
39
|
|
|
def test_keys(self): |
|
40
|
|
|
"""Test the each accumulator key.""" |
|
41
|
|
|
self.assertEqual( |
|
42
|
|
|
len(self.portfolio.subjects.keys()), |
|
43
|
|
|
len(self.state.keys()) |
|
44
|
|
|
) |
|
45
|
|
|
|
|
46
|
|
|
|
|
47
|
|
|
class TestUnderlyingAssetAccumulationCase00(TestPortfolio): |
|
48
|
|
|
"""Test the accumulation of one operation with underlying assets.""" |
|
49
|
|
|
|
|
50
|
|
|
operations = OPERATION_SEQUENCE20 |
|
51
|
|
|
state = { |
|
52
|
|
|
ASSET.symbol: STATE07, |
|
53
|
|
|
OPTION1.symbol: STATE06, |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
|
|
57
|
|
|
class TestUnderlyingAssetAccumulationCase01(TestPortfolio): |
|
58
|
|
|
"""Test the accumulation of one operation with underlying assets.""" |
|
59
|
|
|
|
|
60
|
|
|
operations = OPERATION_SEQUENCE21 |
|
61
|
|
|
state = { |
|
62
|
|
|
ASSET.symbol: STATE08, |
|
63
|
|
|
OPTION1.symbol: STATE06, |
|
64
|
|
|
} |
|
65
|
|
|
|