public IHttpActionResult GetPositionsbyPortID(int portfolioid) { List <Position> positionlist = PositionDao.getPositionsByPortfolioId(portfolioid); List <Positionlist> returnlist = new List <Positionlist>(); foreach (Position p in positionlist) { double porfit = 0; porfit = Convert.ToDouble((PriceHistoryDao.getLastPriceHistorysByisin(p.Isin).OfferPrice - p.Price) / p.Price); returnlist.Add(new Positionlist(p.PositionId, getSecurityname(p.Isin, p.Type), p.Price, p.Quantity, PriceHistoryDao.getLastPriceHistorysByisin(p.Isin).OfferPrice, porfit.ToString("P"), p.Type, p.Isin)); } return(Ok(returnlist)); }
public IHttpActionResult GetPositionsbyPortID(int portfolioid) { List <Position> positionlist = PositionDao.getPositionsByPortfolioId(portfolioid); List <Positionlist> returnlist = new List <Positionlist>(); foreach (Position p in positionlist) { double porfit = 0; porfit = Convert.ToDouble((PriceHistoryDao.getLastPriceHistorysByisin(p.Isin).Price - p.Price) / p.Price); returnlist.Add(new Positionlist(p.PositionId, StockDao.getStocksById(p.Isin).Name, p.Quantity, porfit)); } return(Ok(returnlist)); }
public static double Getportfoliopnl(int portid) { decimal amountbefore = 0; decimal amountafter = 0; double pnl = 0; List <Position> posilist = PositionDao.getPositionsByPortfolioId(portid); foreach (Position p in posilist) { string isin = p.Isin; amountbefore += p.Quantity * p.Price; amountafter += p.Quantity * PriceHistoryDao.getLastPriceHistorysByisin(isin).OfferPrice; } pnl = Convert.ToDouble((amountafter - amountbefore) / amountbefore); return(pnl); }
public IHttpActionResult GetPercentage(int portid) { List <Position> list = PositionDao.getPositionsByPortfolioId(portid); List <PositionPercentage> returnlist = new List <PositionPercentage>(); var query = from p in list orderby p.Price * p.Quantity select p; foreach (Position p in query) { returnlist.Add(new PositionPercentage(p.Price * p.Quantity, getSecurityname(p.Isin, p.Type))); } return(Ok(returnlist)); }
public static double Caculatepnl(int portfolitid) { decimal amountbefore = 0; decimal amountafter = 0; double pnl = 0; List <Position> posilist = PositionDao.getPositionsByPortfolioId(portfolitid); foreach (Position p in posilist) { if (p.Type == "Stock") { int isin = p.Isin; amountafter += p.Quantity * p.Price; amountbefore += p.Quantity * PriceHistoryDao.getLastPriceHistorysByisin(isin).Price; } else { } } pnl = Convert.ToDouble((amountafter - amountbefore) / amountbefore); return(pnl); }