def test_count_short_calls(self): leg1 = option_factory.long_call(100, 5) leg2 = option_factory.long_call(200, 2) leg3 = option_factory.short_call(50, 1) expected_result = 1 actual_result = option_position_analysis.count_short_calls([leg1, leg2, leg3]) self.assertAlmostEqual(expected_result, actual_result, 1)
def test_is_position_allowed(self): # more long legs than short should always be true leg1 = option_factory.long_call(100, 5) leg2 = option_factory.long_call(200, 2) leg3 = option_factory.short_call(50, 1) self.assertTrue(option_position_analysis.is_position_allowed([leg1, leg2, leg3], True)) self.assertTrue(option_position_analysis.is_position_allowed([leg1, leg2, leg3], False)) # same number long as short should always be true leg4 = option_factory.short_call(75, 1) self.assertTrue(option_position_analysis.is_position_allowed([leg1, leg2, leg3, leg4], True)) self.assertTrue(option_position_analysis.is_position_allowed([leg1, leg2, leg3, leg4], False)) # extra short legs should be false when allow_uncapped_risk is false leg5 = option_factory.short_call(150, 3) self.assertTrue(option_position_analysis.is_position_allowed([leg1, leg2, leg3, leg4, leg5], True)) self.assertFalse(option_position_analysis.is_position_allowed([leg1, leg2, leg3, leg4, leg5], False))