FX Forwards PV cashflow in CouchDB
{
"tradeId": 1003,
"trader": "Terry Trader",
"desk": "FX Desk",
"region": "London",
"notional": 100,
"rate": 1.58,
"side": "Buy",
"assetClass": "FX",
"instrument": "Forward",
"duration": "6M",
"ccyPair": "GBPUSD",
"yieldCurve": "http:\\\\localhost:8001\\yieldCurve\\GBP\\20100101",
"GBPcashflow": [-98.54],
"USDcashflow": [154.22]
}
With an enhanced map:
function(doc) {
if (doc.instrument == "Swap") {
emit(doc.tradeId, sum(doc.fixedLegPVCashflows)+sum(doc.floatingLegPVCashflows));
} else if (doc.assetClass == "FX") {
emit(doc.tradeId, sum(doc.GBPcashflow)+sum(doc.USDcashflow));
}
}
So the above is still fairly simple, and probably not relevant in business – i.e. the sum of total NPV for two instruments. What might be more interesting is the total PV for 6M (6 months). Which possibly highlights the document structure issues around how we hold the Swap cashflow’s.

I am working on something similar in Couch – would be interested in comparing notes.