public OptimalPortoliosViewModel CreatePortfolio(User user, CreatePortfolioCommand cmd) { if (cmd.CalcType == enumEfCalculationType.Custom && cmd.Exchanges.Count < 1) { for (int i = 0; i < user.Licence.Stocks.Count; i++) { cmd.Exchanges.Add(Convert.ToInt32(user.Licence.Stocks[i].id)); } } OptimalPortoliosViewModel vm = new OptimalPortoliosViewModel(); var portID = 0; var count = cPortHandler.GetPortfolioCount(user.UserID); if (count < user.Licence.Service.Iportfolios) { portID = cPortHandler.CreateDefaultPortfolio(user, cmd); } else { vm.Messages.Add(new Message { LogLevel = LogLevel.Error, Text = "You've exceeded the number of portfolios you can create. Please delete any unwanted portfolios" }); } if (portID > 0) { vm = opService.GetPortfolioOptimazation(user, new Models.Queries.OptimazationQuery { CalcType = cmd.CalcType, PortID = portID, Securities = cmd.Securities, Exchanges = cmd.Exchanges, Risk = cmd.Risk //LR on 18/07/18 }); if (vm.Messages.Count == 0) { cPortHandler.SelectedPortfolio.Details.LastOptimization = DateTime.Today; cPortHandler.SelectedPortfolio.Details.SecsNum = vm.Portfolios[vm.PortNumA].Securities.Count; cPortHandler.SelectedPortfolio.Details.CurrentStDev = vm.Portfolios[vm.PortNumA].Risk; UpdatePortfolioCommand updCmd = new UpdatePortfolioCommand { CalcType = cPortHandler.SelectedPortfolio.Details.CalcType, Equity = cmd.Equity, Risk = vm.Portfolios[vm.PortNumA].Risk, PortID = portID, Securities = vm.Portfolios[vm.PortNumA].Securities }; cPortHandler.UpdatePortfolio(updCmd); } else { cPortHandler.DeletePortfolio(portID); } } return(vm); }
public CommandStatus Handle(UpdatePortfolioCommand command) { var portfolio = _repo.Load(); var currentPrices = _ex.GetPrice(portfolio.StockSymbols); // Convert currency if needed; left out for simplicity portfolio.Update(currentPrices); _repo.Store(portfolio); return(new Success()); }
public BackTestingViewModel calculateBacktesting(User user, Models.Command.CreatePortfolioCommand cmd, DateTime dtStartDate, DateTime dtEndDate, List <string> becnhMarkIDs) { // Service which creates a new backtesting portfolio + calculates proper backtesting values BackTestingViewModel vmBacktesting = new BackTestingViewModel(); // Set up portfolio int idPortfolio = _manageBacktestingPortfolios.CreateDefaultPortfolio(user, dtStartDate, dtEndDate, cmd); _manageBacktestingPortfolios.SelectedPortfolio.openExistingPortfolio(idPortfolio, true); _backtestingHandler.setBacktestingPortfolio(_manageBacktestingPortfolios.SelectedPortfolio, dtStartDate, dtEndDate, cmd.Equity); cPort = _manageBacktestingPortfolios.SelectedPortfolio; // Set portfolio data List <int> colExchanges = (cmd.Exchanges != null && cmd.Exchanges.Count > 0 && cmd.Exchanges.Count <= user.Licence.Stocks.Count) ? cmd.Exchanges : user.Licence.Stocks.Select(t => t.id).ToList(); if (!_manageBacktestingPortfolios.SelectedPortfolio.instantiateVariablesForPortfolio(true, cPort.Details.CalcCurrency, colExchanges, cmd.Securities)) { // Failed to get data vmBacktesting.Messages.Add(new Models.App.Message { LogLevel = Models.App.LogLevel.Error, Text = "Error Get Portfolio Data. Please Contanct System Administrator" }); return(vmBacktesting); } if (cmd.Securities.Count > 0) { _manageBacktestingPortfolios.SelectedPortfolio.ColHandler.ActiveSecs = getFilteredSecByCustomList(cmd); } else { _manageBacktestingPortfolios.SelectedPortfolio.ColHandler.ActiveSecs = getFilteredSecByExchangesAndRisk(colExchanges); } // Run calculation //vmBacktesting = _backtestingHandler.calculateBacktesting(_manageBacktestingPortfolios.SelectedPortfolio, dtStartDate, dtEndDate, cmd.Equity, becnhMarkIDs); vmBacktesting = _backtestingHandler.calculateNewBacktesting(_manageBacktestingPortfolios.SelectedPortfolio, dtStartDate, dtEndDate, cmd.Equity, becnhMarkIDs); // Save portfolio data // Create command to update portfolio + portfolio securities UpdatePortfolioCommand pc = new UpdatePortfolioCommand(); pc.CalcType = cmd.CalcType; pc.Equity = cmd.Equity; pc.PortID = _manageBacktestingPortfolios.SelectedPortfolio.Details.ID; pc.Risk = vmBacktesting.Portfolios[vmBacktesting.PortNumA].Risk; pc.Securities = vmBacktesting.Portfolios[vmBacktesting.PortNumA].Securities; _manageBacktestingPortfolios.UpdatePortfolio(pc, vmBacktesting); return(vmBacktesting); }//calculateBacktesting
}//CreateDefaultPortfolio public BaseViewModel UpdatePortfolio(UpdatePortfolioCommand cmd, BackTestingViewModel vmBack) { BaseViewModel vm = new BaseViewModel(); Entities.dbo.BacktestingPortfolio portEntity = null;; repository.Execute(session => { portEntity = session.Get <Entities.dbo.BacktestingPortfolio>(cmd.PortID); AutoMapper.Mapper.Map <BasePortfolioCommand, Entities.dbo.BacktestingPortfolio>(cmd, portEntity); portEntity.dCurrRisk = cmd.Risk; portEntity.iSecsNum = cmd.Securities.Count; portEntity.dCurrEquity = vmBack.Equity; }); var secList = AutoMapper.Mapper.Map <List <Entities.dbo.BacktestingPortfolioSecurities> >(cmd.Securities).Where(x => x.Securities.idSecurity != "0000").ToList(); repository.ExecuteTransaction(session => { session.Update(portEntity); }); DeletePortfolioSecurities(cmd.PortID); repository.ExecuteTransactionStateLess(session => { foreach (var item in secList) { try { item.idPortSec = Guid.NewGuid(); item.Portfolios = new Entities.dbo.BacktestingPortfolio { idPortfolio = cmd.PortID }; session.Insert(item); } catch (Exception e) { m_objErrorHandler.LogInfo(e); } } }, secList.Count); return(vm); }
public CommandStatus Handle(UpdatePortfolioCommand command) => _client.Execute <HttpCommandStatus>("updateportfoliocommand", command).CommandStatus;
public BaseViewModel UpdatePortfolio(User user, UpdatePortfolioCommand cmd) { var vm = cPortHandler.UpdatePortfolio(cmd); return(vm); }
public HttpCommandStatus Handle([Payload] UpdatePortfolioCommand command) => new HttpCommandStatus(Handler.Handle(command));
public IHttpActionResult Put(UpdatePortfolioCommand cmd) { var res = service.UpdatePortfolio(user, cmd); return(Ok(res)); }
public async Task UpdatePortfolioAsync(int portfolioId, UpdatePortfolioCommand command) { await api.PutAsync(GetPortfoliosPath(portfolioId), command); }