Created
June 14, 2012 22:49
-
-
Save nisbus/2933496 to your computer and use it in GitHub Desktop.
Reduce
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function(keys, values) { | |
var sumObj = {"qty_cross_ccy": 0, | |
"qty_base_ccy": 0, | |
"fees": 0, | |
"profit_loss_realized": 0, | |
"realized_pl_percentage": 0, | |
"average_buy_rate" : 0, | |
"average_sell_rate" : 0, | |
"asset_under_management" : 0}; | |
if(keys != null){ | |
sumObj.strategy = keys[0][0]; | |
}else{ | |
sumObj.strategy = values[0].strategy; | |
} | |
var total_aum = 0; | |
var total_pl = 0; | |
values.forEach(function(e,a){ | |
total_aum += Number(e.asset_under_management); | |
total_pl += Number(e.profit_loss_realized); | |
}); | |
sumObj.asset_under_management = total_aum; | |
sumObj.realized_pl_percentage = total_pl/total_aum; | |
values.forEach(function(e,a){ | |
sumObj.qty_cross_ccy += Number(e.qty_cross_ccy); | |
sumObj.qty_base_ccy += Number(e.qty_base_ccy); | |
sumObj.fees += Number(e.fees); | |
sumObj.profit_loss_realized += Number(e.profit_loss_realized); | |
sumObj.average_buy_rate += Number(e.average_buy_rate); | |
sumObj.average_sell_rate += Number(e.average_sell_rate); | |
}); | |
sumObj.average_buy_rate = sumObj.average_buy_rate/values.length; | |
sumObj.average_sell_rate = sumObj.average_sell_rate/values.length; | |
return sumObj; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment