Mark-to-Market

Extract from Calypso the Net Present Value (NPV) of the newly booked front office trades from the last 5 days that haven’t been cancelled or deleted and have the following products:

Forward Exchange (FXForward)
Forward Exchange Options (FXOption)
Forward Exchange Swap (FXSwap)
Forward Contract Forward Exchange Options (FXOptionForward)
Forward Exchange TakeUp (FXTakeUp)
Interest Rate Cap and Floor (CapFloor)
Derivative Swap (Swaps)

Step 1

Load all live trades from Calypso with keyword attributes of:

Cover Trade ID
ExercisedOption
ExercisedUnder
Cover Trade ID
ExercisedOption
ExercisedUnder
SalesB2BFrom
SalesB2BTo
RolledOverFrom
RolledOverTo

Load Calypso posting amount (trade mark-to-market)

SELECT
	t.trade_id,
	b.business_unit as desk_id,
	p.booking_date as mtm_date,
	p.currency_code as ccy,
	sum(
		case
			when p.credit_acc_id <> -1 then p.amount * -1
			else p.amount
		end
	) as mtm
FROM
	calypso.trade t
	INNER JOIN calypso.bo_posting p ON t.trade_id = p.trade_id
	INNER JOIN calypso.product_desc d ON d.product_id = p.product_id
	INNER JOIN calypso.vw_book b ON b.book_id = p.book_id
	INNER JOIN calypso.acc_rule r ON p.acc_rule_id = r.acc_rule_id
WHERE
	r.acc_rule_type = 'FO_PNL'
	AND p.bo_posting_type like 'MTM%'
	AND p.description = 'NPV'
	AND p.sent_status <> 'DELETED'
	AND d.product_type in (
		'FX',
		'FXForward',
		'FXOption',
		'FXSwap',
		'FXOptionForward',
		'FXTakeUp',
		'CapFloor',
		'Swap'
	)
	AND p.posting_type = 'NEW'
	AND t.trade_status <> 'CANCELED'
	AND p.booking_date >= (
		SELECT
			dateadd(
				day,
				-5,
				convert(datetime, convert(varchar(10), getdate(), 103), 103)
			)
	)
GROUP BY
	t.trade_id,
	b.business_unit,
	p.booking_date,
	p.currency_code

Step 2

Trade level values

Load trade mark-to-market values to production 

Load trade mark-to-market values to table dw_trade_mtm

INSERT INTO
	dbo.dw_trade_mtm (
		trade_id,
		mtm_date,
		ccy,
		mtm,
		mtm_gbp
	)
SELECT
	trade_id,
	mtm_date,
	ccy,
	mtm,
	round(
		case
			when ccy = 'GBP' then mtm
			else mtm * dbo.fnc_get_fx_rate(ccy, 'GBP', mtm_date)
		end,
		2
	) as mtm_gbp
FROM
	dbo.stage_calypso_trade_mtm

Step 3

Counterparty level values

Denormalise the data so each keyword has a column

Load simple money market trades