public Portfolio CreatePortfolio(User user, string portfolioname, bool isSimulated, Tuple <string, AssetClass>[] tuples) { Portfolio portfolio = new Portfolio() { Name = portfolioname, AssetAllocations = new List <AssetAllocation>(), UserId = user.Id, }; Portfolios.Add(portfolio); SaveChanges(); foreach (var tuple in tuples) { AssetBase assetBase = GetAssetyBy(tuple.Item2, tuple.Item1); if (assetBase == null) { assetBase = CreateAsset(tuple.Item2, tuple.Item1); } AssetAllocation assetAllocation = new AssetAllocation() { Asset = assetBase, PortfolioId = portfolio.Id, }; AssetAllocations.Add(assetAllocation); portfolio.AssetAllocations.Add(assetAllocation); } portfolio.UserId = user.Id; portfolio.IsSimulated = true; Update(portfolio); return(portfolio); }
public static void AddPosition(QuikConnectionManager.Position obj) { if (!Positions.Any(k => k.AccountName == obj.AccountName && k.Instrument.Code == obj.SecurityCode)) { Entities.Instrument instr; if (obj.AccountName == "FOUXK_001") { Console.Write("fnfyng"); } try { instr = Instruments.First(k => k.Code == obj.SecurityCode); var pos = new Entities.Position(obj.AccountName, instr, obj.TotalNet, obj.BuyQty, obj.SellQty, obj.VarMargin); Positions.Add(pos); log.Info("New position added. SecCode={0} Account={1}", obj.SecurityCode, obj.AccountName); if (pos.Instrument.Type == Entities.InstrumentType.Futures) { if (Portfolios.Any(k => k.BaseCode == pos.Instrument.Code && k.Account == pos.AccountName)) { Portfolios.First(k => k.BaseCode == pos.Instrument.Code && k.Account == pos.AccountName).Positions.Add(pos); log.Info("Futures Position added to existing portfolio."); } else { // create new portfolio Entities.Portfolio port = new Entities.Portfolio(pos.Instrument.Code, pos.AccountName); port.Positions.Add(pos); Portfolios.Add(port); log.Info("New portfolio created. Name={0} Base={1} Account={2}", port.Name, port.BaseCode, port.Account); } } else if (pos.Instrument.Type == Entities.InstrumentType.Option) { if (Portfolios.Any(k => k.BaseCode == pos.Instrument.BaseContract && k.Account == pos.AccountName)) { Portfolios.First(k => k.BaseCode == pos.Instrument.BaseContract && k.Account == pos.AccountName).Positions.Add(pos); log.Info("Option Position added to existing portfolio."); } else { // create new portfolio Entities.Portfolio port = new Entities.Portfolio(pos.Instrument.BaseContract, pos.AccountName); port.Positions.Add(pos); Portfolios.Add(port); log.Info("New portfolio created. Name={0} Base={1} Account={2}", port.Name, port.BaseCode, port.Account); } } } catch (SystemException exep) { log.Error("Try to add position for unknown instrument {0} {1} {2}", obj.SecurityCode, obj.AccountName, obj.TotalNet); log.Error(exep.Message); } } else { log.Warn("Try to add existing position. {0} {1}", obj.AccountName, obj.SecurityCode); } }
public Portfolio AddPortfolio(string portfolioName) { var newPortfolio = new Portfolio() { PortfolioId = Portfolios.Count() + 1, PortfolioName = portfolioName }; Portfolios.Add(newPortfolio); return newPortfolio; }
public Portfolio CreatePortfolio(User user, string portfolioname) { Portfolio portfolio = new Portfolio() { UserId = user.Id, Name = portfolioname, }; Portfolios.Add(portfolio); //https://docs.microsoft.com/en-us/ef/core/saving/related-data //TODO: falta resolver el cascade insert, es decir: si existe obtnerlo y si no crearlo SaveChanges(); return(portfolio); }
private void AddNewPortfolio(object parameter) { Portfolio NewPortfolio = new Portfolio(); NewPortfolioViewModel NPVM = new NewPortfolioViewModel(); NewPortfolioWindow NPW = new NewPortfolioWindow(); NPW.DataContext = NPVM; NPW.ShowDialog(); if (NPW.DialogResult.HasValue && NPW.DialogResult.Value) { NewPortfolio.PortfolioName = NPW.PortfolioNameTextBox.Text; } NewPortfolio.BenchmarkInstrument = NPW.BenchmarkInstrumentTextBox.Text; NewPortfolio.InceptionDate = DateTime.Today; Portfolios.Add(NewPortfolio); RepositoryWriter.WritePortfolio(NewPortfolio.PortfolioName, NewPortfolio.BenchmarkInstrument, NewPortfolio.InceptionDate); }
public static Portfolios Process(DataTable table, string source, DateTime valueDate) { var stopWatch = new Stopwatch(); stopWatch.Start(); var portfolios = new Portfolios { Source = source }; var tenorCol = table.Columns["tenor"]; var portfolioidCol = table.Columns["portfolioid"]; var valueCol = table.Columns["value"]; var sql = "tenor is not null AND portfolioid <> 0"; //remove any null rows. Its assumed all other data is valid that has been saved to file. var rows = table.Select(sql); //todo: AsParallel() this read. foreach (DataRow tableRow in rows) { var tenor = tableRow[tenorCol].ToString(); var portfolioid = Utils.SafeCastToIntParse(tableRow[portfolioidCol].ToString()); var value = Utils.SafeCastToDoubleParse(tableRow[valueCol].ToString()); var pr = new PortfolioRisk() { Tenor = tenor, PortfolioId = portfolioid, Value = value, ValueDate = valueDate, Source = source, LastUpdated = ConfigDataHandler.SystemName, UpdateDate = DateTime.UtcNow }; portfolios.Add(pr); } stopWatch.Stop(); portfolios.LoadTime = stopWatch.Elapsed; return(portfolios); }
public override void Read(Stream stream) { base.Read(stream); BeginValue = ReadInfo(stream); CurrentValue = ReadInfo(stream); BlockedValue = ReadInfo(stream); CurrentPrice = ReadInfo(stream); AveragePrice = ReadInfo(stream); UnrealizedPnL = ReadInfo(stream); RealizedPnL = ReadInfo(stream); VariationMargin = ReadInfo(stream); Leverage = ReadInfo(stream); Commission = ReadInfo(stream); CurrentValueInLots = ReadInfo(stream); var pfCount = stream.Read <int>(); for (var i = 0; i < pfCount; i++) { Portfolios.Add(stream.Read <string>()); } var ccCount = stream.Read <int>(); for (var i = 0; i < ccCount; i++) { ClientCodes.Add(stream.Read <string>()); } var dnCount = stream.Read <int>(); for (var i = 0; i < dnCount; i++) { DepoNames.Add(stream.Read <string>()); } if (Version < MarketDataVersions.Version33) { return; } SettlementPrice = ReadInfo(stream); }
public void Add(Portfolio portfolio, bool emitEvent = true) { if (portfolio.Id == -1) { portfolio.Id = this.counter++; } else { if (Portfolios.Contains(portfolio.Id)) { Console.WriteLine($"PortfolioManager::Add portfolio {portfolio.Name} error. Portfolio with Id {portfolio.Id} already added."); } if (portfolio.Id >= this.counter) { this.counter = portfolio.Id + 1; } } Portfolios.Add(portfolio); if (emitEvent) { this.framework.EventServer.OnPortfolioAdded(portfolio); } }