Skip to content

Instantly share code, notes, and snippets.

@kennedysean
Created May 12, 2020 00:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kennedysean/72691bd3d17cb127f0ce2830e468d6e5 to your computer and use it in GitHub Desktop.
Save kennedysean/72691bd3d17cb127f0ce2830e468d6e5 to your computer and use it in GitHub Desktop.
double OopStockPortfolio::getPortfolioValue()
{
double returnVal = 0;
std::for_each(stockPortfolio.begin(), stockPortfolio.end(),
[&returnVal](const StockPosition &a) { returnVal += (a.numShares * a.stockValue); });
return returnVal;
}
double OopStockPortfolio::getPortfolioCost()
{
double returnVal = 0;
std::for_each(stockPortfolio.begin(), stockPortfolio.end(),
[&returnVal](const StockPosition &a) { returnVal += (a.numShares * a.stockAverageCost); });
return returnVal;
}
double OopStockPortfolio::getTotalReturn()
{
return (getPortfolioValue() / getPortfolioCost()) * 100 - 100.0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment