example   A
last analyzed

Complexity

Total Complexity 0

Size/Duplication

Total Lines 72
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 0
eloc 35
dl 0
loc 72
rs 10
c 0
b 0
f 0
1
from trade.holder import Holder
2
from trade.occurrence import Occurrence
3
from trade.subject import Subject
4
5
# create a holder
6
holder = Holder()
7
8
# define some subject
9
some_asset = Subject('AST1')
10
11
# create an occurrence with that subject.
12
# In this example, a purchase of 100 units of the asset,
13
# for the value of $20.
14
some_occurrence = Occurrence(
15
		some_asset,
16
		'2018-01-02',
17
		{
18
			"quantity": 100,
19
			"value": 20
20
		}
21
	)
22
23
# pass it to the holder
24
holder.trade(some_occurrence)
25
26
# check the holder state:
27
for subject, state in holder.state.items():
28
	print(subject)
29
	print(state)
30
# AST1
31
# {'value': 20.0, 'quantity': 100}
32
33
34
# create some other occurrence with that subject.
35
# In this example, a sale of 20 units of the asset,
36
# for the value of $30.
37
holder.trade(Occurrence(
38
		some_asset,
39
		'2018-01-03',
40
		{
41
			"quantity": -20,
42
			"value": 30
43
		}
44
	))
45
46
# check the holder state. It should show a change in quantity
47
# and some profit:
48
for subject, state in holder.state.items():
49
	print(subject)
50
	print(state)
51
# AST1
52
# {'value': 20.0, 'quantity': 80}
53
54
55
# create some other occurrence with that subject.
56
# Now a purchase of 10 units of the asset, for the
57
# value of $20.
58
holder.trade(Occurrence(
59
		some_asset,
60
		'2018-01-04',
61
		{
62
			"quantity": 10,
63
			"value": 25
64
		}
65
	))
66
67
# check the holder state. It should show a change in quantity
68
# and in the value of the subject:
69
for subject, state in holder.state.items():
70
	print(subject)
71
	print(state)
72
# AST1
73
# {'value': 20.555555555555557, 'quantity': 90}
74