Mtm bug
This commit is contained in:
@@ -80,8 +80,8 @@ class PurchaseTradeTestCase(ModuleTestCase):
|
|||||||
strategy.get_mtm(line, Decimal('10')),
|
strategy.get_mtm(line, Decimal('10')),
|
||||||
Decimal('250.00'))
|
Decimal('250.00'))
|
||||||
|
|
||||||
def test_get_strategy_mtm_price_returns_unit_price(self):
|
def test_get_strategy_mtm_price_applies_component_ratio(self):
|
||||||
'strategy mtm price exposes the raw unit valuation price'
|
'strategy mtm price applies component ratios'
|
||||||
strategy = Mock(
|
strategy = Mock(
|
||||||
scenario=Mock(
|
scenario=Mock(
|
||||||
valuation_date='2026-03-29',
|
valuation_date='2026-03-29',
|
||||||
@@ -99,7 +99,36 @@ class PurchaseTradeTestCase(ModuleTestCase):
|
|||||||
|
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
valuation_module.Valuation._get_strategy_mtm_price(strategy, line),
|
valuation_module.Valuation._get_strategy_mtm_price(strategy, line),
|
||||||
Decimal('100.0000'))
|
Decimal('25.0000'))
|
||||||
|
|
||||||
|
def test_get_strategy_mtm_price_keeps_signed_component_spread(self):
|
||||||
|
'strategy mtm price keeps signed spread between different components'
|
||||||
|
strategy = Mock(
|
||||||
|
scenario=Mock(
|
||||||
|
valuation_date='2026-03-29',
|
||||||
|
use_last_price=True,
|
||||||
|
),
|
||||||
|
currency=Mock(),
|
||||||
|
)
|
||||||
|
strategy.components = [
|
||||||
|
Mock(
|
||||||
|
price_source_type='curve',
|
||||||
|
price_index=Mock(get_price=Mock(return_value=Decimal('120'))),
|
||||||
|
price_matrix=None,
|
||||||
|
ratio=Decimal('100'),
|
||||||
|
),
|
||||||
|
Mock(
|
||||||
|
price_source_type='curve',
|
||||||
|
price_index=Mock(get_price=Mock(return_value=Decimal('80'))),
|
||||||
|
price_matrix=None,
|
||||||
|
ratio=Decimal('-100'),
|
||||||
|
),
|
||||||
|
]
|
||||||
|
line = Mock(unit=Mock())
|
||||||
|
|
||||||
|
self.assertEqual(
|
||||||
|
valuation_module.Valuation._get_strategy_mtm_price(strategy, line),
|
||||||
|
Decimal('40.0000'))
|
||||||
|
|
||||||
def test_sale_line_is_unmatched_checks_lot_links(self):
|
def test_sale_line_is_unmatched_checks_lot_links(self):
|
||||||
'sale line unmatched helper ignores empty matches and detects linked purchases'
|
'sale line unmatched helper ignores empty matches and detects linked purchases'
|
||||||
|
|||||||
@@ -356,6 +356,9 @@ class ValuationBase(ModelSQL):
|
|||||||
value = Decimal(strategy._get_matrix_price(
|
value = Decimal(strategy._get_matrix_price(
|
||||||
comp, line, scenario.valuation_date))
|
comp, line, scenario.valuation_date))
|
||||||
|
|
||||||
|
if comp.ratio:
|
||||||
|
value *= Decimal(comp.ratio) / Decimal(100)
|
||||||
|
|
||||||
total += value
|
total += value
|
||||||
|
|
||||||
return round(total, 4)
|
return round(total, 4)
|
||||||
|
|||||||
Reference in New Issue
Block a user