Partial merge
This commit is contained in:
commit
01f178fe3b
160 files changed
+6432
-1084
No files matched your search
@@ -27,6 +27,11 @@ using namespace bts::md;
|
||||
|
||||
class HandleIndex {
|
||||
public:
|
||||
enum PNLType{
|
||||
UNRESOLVED = 0,
|
||||
SPREAD,
|
||||
OUTRIGHT
|
||||
};
|
||||
bts::md::MDClient& _client;
|
||||
int _sub;
|
||||
std::optional<bts::md::MDConsumer> _consumer;
|
||||
@@ -51,7 +56,18 @@ public:
|
||||
});
|
||||
return handle;
|
||||
}
|
||||
|
||||
PNLType get_pnl_type (SecurityKey key) const{
|
||||
auto h = _get_handle(key);
|
||||
if (h.is_initialized()){
|
||||
const auto& sec = h.get_normalized_security();
|
||||
if (sec.has_future() || sec.has_option())
|
||||
return PNLType::OUTRIGHT;
|
||||
else
|
||||
return PNLType::SPREAD;
|
||||
}
|
||||
else
|
||||
return PNLType::UNRESOLVED;
|
||||
}
|
||||
std::string get_symbol (SecurityKey key) const{
|
||||
auto handle = _get_handle(key);
|
||||
return handle.get_usersymbol().symbol();
|
||||
@@ -159,10 +175,12 @@ void PositionServicePNLHelper::_aggregate_account_pnl(
|
||||
std::map<uint32_t, AccountPNL> acc_pnl;
|
||||
for (const auto& pnlu : in_pnl){
|
||||
uint32_t acct_id = pnlu.pos().account_id();
|
||||
const std::string& acct_name = pnlu.pos().account();
|
||||
auto it=acc_pnl.find(acct_id);
|
||||
if(it==acc_pnl.end()){
|
||||
AccountPNL new_acc;
|
||||
new_acc.set_account_id(acct_id);
|
||||
new_acc.set_account_name(acct_name);
|
||||
new_acc.set_day_pnl(0.0);
|
||||
acc_pnl[acct_id]=new_acc;
|
||||
it=acc_pnl.find(acct_id);
|
||||
@@ -173,10 +191,12 @@ void PositionServicePNLHelper::_aggregate_account_pnl(
|
||||
}
|
||||
// for accounts with no positions add 0
|
||||
for (const auto& p : account_map){
|
||||
const std::string& acct_name = p.first;
|
||||
uint32_t acct_id = p.second;
|
||||
if(acc_pnl.find(acct_id) == acc_pnl.end()){
|
||||
AccountPNL new_acc;
|
||||
new_acc.set_account_id(acct_id);
|
||||
new_acc.set_account_name(acct_name);
|
||||
new_acc.set_day_pnl(0.0);
|
||||
acc_pnl[acct_id]=new_acc;
|
||||
}
|
||||
@@ -187,6 +207,7 @@ void PositionServicePNLHelper::_aggregate_account_pnl(
|
||||
|
||||
double PositionServicePNLHelper::_compute_day_pnl (
|
||||
const bts::api::position::PNLUnit& u){
|
||||
<<<<<<< HEAD
|
||||
double md = (u.bid_price() + u.ask_price())*0.5;
|
||||
md = bts::os::is_nan(md) ? u.bid_price() : md;
|
||||
md = bts::os::is_nan(md) ? u.ask_price() : md;
|
||||
@@ -196,6 +217,34 @@ double PositionServicePNLHelper::_compute_day_pnl (
|
||||
(md - u.pos().day().long_avg_price()) +
|
||||
std::abs(u.pos().day().short_pos()) * cpp *
|
||||
(u.pos().day().short_avg_price() - md);
|
||||
=======
|
||||
// long
|
||||
double pnl;
|
||||
auto pnl_type = me->handle_index.get_pnl_type(
|
||||
SecurityKey(u.pos().security_id()));
|
||||
switch(pnl_type){
|
||||
case HandleIndex::OUTRIGHT:{
|
||||
double md = (u.bid_price() + u.ask_price())*0.5;
|
||||
md = bts::os::is_nan(md) ? u.bid_price() : md;
|
||||
md = bts::os::is_nan(md) ? u.ask_price() : md;
|
||||
md = bts::os::is_nan(md) ? u.settlement_price() : md;
|
||||
|
||||
double long_pnl = std::abs(u.pos().day_long_pos()) * u.cash_value() *
|
||||
(md - u.pos().day_long_avg_price()),
|
||||
short_pnl = std::abs(u.pos().day_short_pos()) * u.cash_value() *
|
||||
(u.pos().day_short_avg_price() - md);
|
||||
pnl = long_pnl + short_pnl;
|
||||
break;
|
||||
}
|
||||
case HandleIndex::SPREAD:
|
||||
pnl = 0.0;
|
||||
break;
|
||||
case HandleIndex::UNRESOLVED:
|
||||
pnl = os::nan();
|
||||
break;
|
||||
}
|
||||
return pnl;
|
||||
>>>>>>> master
|
||||
}
|
||||
double PositionServicePNLHelper::_get_cpp(uint32_t sec_key){
|
||||
auto it = me->sec_cpp_map.find(sec_key);
|
||||
|
||||
Reference in new issue
Block a user