Skip to content

Commit

Permalink
Simplified logic.
Browse files Browse the repository at this point in the history
  • Loading branch information
johnbywater committed Sep 21, 2017
1 parent 7440795 commit 546057c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 23 deletions.
18 changes: 6 additions & 12 deletions quantdsl/semantics.py
Expand Up @@ -513,22 +513,16 @@ def reduce(self, dsl_locals, dsl_globals, effective_present_time=None, pending_c

value = self.evaluate(**combined_namespace)
if isinstance(value, datetime.date):
return Date(value, node=self.node)
elif isinstance(value, DslObject):
return value
value = Date(value, node=self.node)
elif isinstance(value, six.integer_types + (float, ndarray)):
return Number(value, node=self.node)
value = Number(value, node=self.node)
elif isinstance(value, six.string_types):
return String(value, node=self.node)
value = String(value, node=self.node)
elif isinstance(value, datetime.timedelta):
return TimeDelta(value, node=self.node)
value = TimeDelta(value, node=self.node)
elif isinstance(value, relativedelta):
return TimeDelta(value, node=self.node)
# elif isinstance(value, (SynchronizedArray, Synchronized)):
# return Number(numpy_from_sharedmem(value), node=self.node)
else:
raise DslSyntaxError("expected number, string, date, time delta, or DSL object when reducing name '%s'"
"" % self.name, repr(value), node=self.node)
value = TimeDelta(value, node=self.node)
return value

def evaluate(self, **kwds):
try:
Expand Down
19 changes: 10 additions & 9 deletions quantdsl/tests/test_application.py
Expand Up @@ -23,6 +23,7 @@ class ApplicationTestCaseMixin(with_metaclass(ABCMeta)):
NUMBER_MARKETS = 2
NUMBER_WORKERS = 20
PATH_COUNT = 2000
MAX_DEPENDENCY_GRAPH_SIZE = 200

def setUp(self):
if not self.skip_assert_event_handers_empty:
Expand All @@ -31,7 +32,7 @@ def setUp(self):

scipy.random.seed(1354802735)

self.setup_application()
self.setup_application(max_dependency_graph_size=self.MAX_DEPENDENCY_GRAPH_SIZE)

def tearDown(self):
if self.app is not None:
Expand All @@ -40,8 +41,8 @@ def tearDown(self):
assert_event_handlers_empty()
# super(ContractValuationTestCase, self).tearDown()

def setup_application(self):
self.app = QuantDslApplicationWithPythonObjects(max_dependency_graph_size=200)
def setup_application(self, **kwargs):
self.app = QuantDslApplicationWithPythonObjects(**kwargs)


class TestCase(ApplicationTestCaseMixin, unittest.TestCase):
Expand Down Expand Up @@ -412,7 +413,7 @@ def test_functional_derivative_option_definition(self):
def Option(date, strike, x, y):
return Wait(date, Choice(x - strike, y))
Option(Date('2012-01-01'), 9, Underlying(Market('NBP')), 0)
Option(Date('2012-01-01'), 9, Market('NBP'), 0)
"""
self.assert_contract_value(specification, 2.4557, expected_call_count=2)

Expand Down Expand Up @@ -831,9 +832,9 @@ def Incr(n):

class ContractValuationTests(
SingleTests,
# ExperimentalTests,
# SpecialTests,
# ExpressionTests,
# FunctionTests,
# LongerTests
ExperimentalTests,
SpecialTests,
ExpressionTests,
FunctionTests,
LongerTests
): pass
Expand Up @@ -5,5 +5,5 @@

class TestApplicationWithPythonObjectsAndMultithreading(TestCase, ContractValuationTests):

def setup_application(self):
self.app = QuantDslApplicationWithMultithreadingAndPythonObjects()
def setup_application(self, **kwargs):
self.app = QuantDslApplicationWithMultithreadingAndPythonObjects(**kwargs)

0 comments on commit 546057c

Please sign in to comment.