try use floating point to calc average costbasis
This commit is contained in:
@@ -1334,18 +1334,20 @@ UniValue PricesInfo(uint256 bettxid, int32_t refheight)
|
|||||||
|
|
||||||
int64_t totalbets = 0;
|
int64_t totalbets = 0;
|
||||||
int64_t totalprofits = 0;
|
int64_t totalprofits = 0;
|
||||||
int64_t costbasis = 0;
|
double dcostbasis = 0.0;
|
||||||
for (auto b : bets) {
|
for (auto b : bets) {
|
||||||
totalbets += b.amount;
|
totalbets += b.amount;
|
||||||
totalprofits += b.profits;
|
totalprofits += b.profits;
|
||||||
costbasis += b.amount * (b.costbasis / PRICES_POINTFACTOR); // prevent int64 overflow
|
dcostbasis += b.amount * b.costbasis;
|
||||||
std::cerr << "PricesInfo() acc costbasis=" << costbasis << " b.amount=" << b.amount << " b.costbasis/PRICES_POINTFACTOR=" << (b.costbasis / PRICES_POINTFACTOR) << std::endl;
|
// costbasis += b.amount * (b.costbasis / PRICES_POINTFACTOR); // prevent int64 overflow (but we have underflow for 1/BTC)
|
||||||
|
// std::cerr << "PricesInfo() acc costbasis=" << costbasis << " b.amount=" << b.amount << " b.costbasis/PRICES_POINTFACTOR=" << (b.costbasis / PRICES_POINTFACTOR) << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t equity = totalbets + totalprofits;
|
int64_t equity = totalbets + totalprofits;
|
||||||
|
int64_t costbasis;
|
||||||
if (totalbets != 0) { //prevent zero div
|
if (totalbets != 0) { //prevent zero div
|
||||||
costbasis *= PRICES_POINTFACTOR; // save last 0.0000xxxx positions
|
// costbasis *= PRICES_POINTFACTOR; // save last 0.0000xxxx positions
|
||||||
costbasis /= totalbets;
|
costbasis = (int64_t) (dcostbasis / (double)totalbets);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
costbasis = 0;
|
costbasis = 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user