|
1
|
|
|
"""Test Exercise operations. |
|
2
|
|
|
|
|
3
|
|
|
Exercise operations calls the exercise() method of its |
|
4
|
|
|
assets to get the underlying operations of the exercise. |
|
5
|
|
|
""" |
|
6
|
|
|
|
|
7
|
|
|
from __future__ import absolute_import |
|
8
|
|
|
|
|
9
|
|
|
import unittest |
|
10
|
|
|
import copy |
|
11
|
|
|
|
|
12
|
|
|
from fixtures.operations import ( |
|
13
|
|
|
EXERCISE_OPERATION5, EXERCISE_OPERATION6 |
|
14
|
|
|
) |
|
15
|
|
|
|
|
16
|
|
|
|
|
17
|
|
|
class TestExercise(unittest.TestCase): |
|
18
|
|
|
|
|
19
|
|
|
length = 0 |
|
20
|
|
|
option_quantity = 0 |
|
21
|
|
|
option_price = 0 |
|
22
|
|
|
asset_quantity = 0 |
|
23
|
|
|
asset_price = 0 |
|
24
|
|
|
exercise = None |
|
25
|
|
|
|
|
26
|
|
|
def setUp(self): |
|
27
|
|
|
super(TestExercise, self).setUp() |
|
28
|
|
|
if self.exercise: |
|
29
|
|
|
self.exercise = copy.deepcopy(self.exercise) |
|
30
|
|
|
self.operations = self.exercise.fetch_operations() |
|
31
|
|
|
|
|
32
|
|
|
def test_operations_len(self): |
|
33
|
|
|
"""Check the len of the operations in the exercise.""" |
|
34
|
|
|
if self.exercise: |
|
35
|
|
|
self.assertEqual(len(self.exercise.operations), self.length) |
|
36
|
|
|
|
|
37
|
|
|
def test_option_quantity(self): |
|
38
|
|
|
"""Check the quantity of the operation consuming the option.""" |
|
39
|
|
|
if self.exercise: |
|
40
|
|
|
self.assertEqual( |
|
41
|
|
|
self.exercise.operations[0].quantity, |
|
42
|
|
|
self.option_quantity |
|
43
|
|
|
) |
|
44
|
|
|
|
|
45
|
|
|
def test_option_price(self): |
|
46
|
|
|
"""Check the price of the operation consuming the option.""" |
|
47
|
|
|
if self.exercise: |
|
48
|
|
|
self.assertEqual( |
|
49
|
|
|
self.exercise.operations[0].price, |
|
50
|
|
|
self.option_price |
|
51
|
|
|
) |
|
52
|
|
|
|
|
53
|
|
|
def test_asset_quantity(self): |
|
54
|
|
|
"""Check the quantity of the operation buying the asset.""" |
|
55
|
|
|
if self.exercise: |
|
56
|
|
|
self.assertEqual( |
|
57
|
|
|
self.exercise.operations[1].quantity, |
|
58
|
|
|
self.asset_quantity |
|
59
|
|
|
) |
|
60
|
|
|
|
|
61
|
|
|
def test_asset_price(self): |
|
62
|
|
|
"""Check the price of the operation buying the asset.""" |
|
63
|
|
|
if self.exercise: |
|
64
|
|
|
self.assertEqual( |
|
65
|
|
|
self.exercise.operations[1].price, |
|
66
|
|
|
self.asset_price |
|
67
|
|
|
) |
|
68
|
|
|
|
|
69
|
|
|
|
|
70
|
|
|
class TestExerciseCase00(TestExercise): |
|
71
|
|
|
"""Exercising a call.""" |
|
72
|
|
|
|
|
73
|
|
|
length = 2 |
|
74
|
|
|
option_quantity = -100 |
|
75
|
|
|
option_price = 0 |
|
76
|
|
|
asset_quantity = 100 |
|
77
|
|
|
asset_price = 10 |
|
78
|
|
|
exercise = EXERCISE_OPERATION5 |
|
79
|
|
|
|
|
80
|
|
|
|
|
81
|
|
|
class TestExerciseCase01(TestExercise): |
|
82
|
|
|
"""Being exercised on a call.""" |
|
83
|
|
|
|
|
84
|
|
|
length = 2 |
|
85
|
|
|
option_quantity = -100 |
|
86
|
|
|
option_price = 0 |
|
87
|
|
|
asset_quantity = -100 |
|
88
|
|
|
asset_price = 10 |
|
89
|
|
|
exercise = EXERCISE_OPERATION6 |
|
90
|
|
|
|