-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added unit test for ForwardCurve object.
- Loading branch information
1 parent
868d935
commit 93852e3
Showing
2 changed files
with
33 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
from unittest import TestCase | ||
|
||
import datetime | ||
|
||
from quantdsl.priceprocess.forwardcurve import ForwardCurve | ||
|
||
|
||
class TestForwardCurve(TestCase): | ||
def test_get_price(self): | ||
# Check without any data. | ||
curve = ForwardCurve('name', []) | ||
|
||
# Check raises KeyError for any dates. | ||
with self.assertRaises(KeyError): | ||
curve.get_price(date=datetime.datetime(2011, 12, 31)) | ||
|
||
# Check with data. | ||
curve = ForwardCurve('name', [('2011-1-1', 1), ('2011-1-3', 3)]) | ||
# Get first value using exact date. | ||
self.assertEqual(curve.get_price(date=datetime.datetime(2011, 1, 1)), 1) | ||
# Get first value using later date. | ||
self.assertEqual(curve.get_price(date=datetime.datetime(2011, 1, 2)), 1) | ||
# Get second value using exact date. | ||
self.assertEqual(curve.get_price(date=datetime.datetime(2011, 1, 3)), 3) | ||
# Get second value using later date. | ||
self.assertEqual(curve.get_price(date=datetime.datetime(2011, 1, 4)), 3) | ||
|
||
# Check raises KeyError for values before first date. | ||
with self.assertRaises(KeyError): | ||
curve.get_price(date=datetime.datetime(2010, 12, 31)) |