public static Index CreateIndexObject(FGAContext db, IDictionary <string, string> data, ILog ExceptionLogger) { Index index; string isin = data["isin"]; CurrencyCode c = data["currency"] == null ? CurrencyCode.EUR : (CurrencyCode)data["currency"]; index = new Index(Name: data["name"], ISIN: isin, IndexCurrency: c); index.IndexFrequency = FrequencyCode.getFrequencyByLabel("DAILY"); index.Identification.OtherIdentification = data["id"]; index.Identification.RIC = (RICIdentifier)data["ric"]; index.Identification.Bloomberg = (BloombergIdentifier)data["bloomberg"]; index.FamilyKeyObject = new MSCIFamilyObject(); if (data["country"] != null) { try { index.Identification.DomesticIdentificationSource = (CountryCode)data["country"]; } catch (Exception e) { ExceptionLogger.Info("Country code :" + data["country"] + " Not recognized"); } } db.Indexes.Add(index); return(index); }
static void Main(string[] args) { using (var db = new FGABusinessComponent.BusinessComponent.FGAContext()) { #if DEBUG FGABusinessComponent.BusinessComponent.Util.EFCodeFirstMethods.DumpDbCreationScriptToFile(db); #endif IndexBasket ex = new IndexBasket(); ex.Identification = new SecuritiesIdentification(Isin: "FR1234567890"); ex.IndexFixingDate = new DateTime(2000, 1, 1, 14, 30, 0); // 14h30 ex.IndexFrequency = FrequencyCode.getFrequencyByLabel("MONTHLY"); ex.IndexCurrency = CurrencyCode.getCurrencyByLabel("Euro"); IndexAsset ia = new IndexAsset(); ia.MarketCapitalization = new CurrencyAndAmount(); ia.MarketCapitalization.Value = 12; ia.MarketCapitalization.Currency = (CurrencyCode)"EUR"; ia.InvestmentRate = new PercentageRate(); ia.InvestmentRate.Value = 10; ia.EffectiveDate = DateTime.Now; ia.HeldNumber = new SecuritiesQuantity(); ia.HeldNumber.SecurityIdentification = new ISINIdentifier(); ia.HeldNumber.SecurityIdentification.ISINCode = "XX0000000000"; ia.HeldNumber.Unit = 2; ia.HeldNumber.Rate = new PercentageRate(); ia.HeldNumber.Amount = new CurrencyAndAmount(); ia.HeldNumber.Amount.Currency = (CurrencyCode)"USD"; ia.HeldNumber.Amount.Value = 66; //ia.HeldNumber = new SecuritiesQuantity(); //ia.HeldNumber.SecurityIdentification = "10 EUR"; ex.Compo = new List <IndexAsset>(); ex.Compo.Add(ia); db.Indexes.Add(ex); ex = new IndexBasket(); ex.Identification = new SecuritiesIdentification(Isin: "FR0000000000"); ex.IndexFixingDate = new DateTime(2000, 1, 1, 14, 30, 0); // 14h30 ex.IndexFrequency = FrequencyCode.getFrequencyByLabel("MONTHLY"); ex.IndexCurrency = (CurrencyCode)"USD"; db.Indexes.Add(ex); db.SaveChanges(); Index ex1 = db.Indexes.FirstOrDefault <Index>(); Index ex2 = db.Indexes.Where <Index>(t => t.Identification.SecurityIdentification == "FR1114567890").FirstOrDefault <Index>(); List <Index> results2 = db.Indexes.Where <Index>(t => t.Identification.SecurityIdentification == "FR0000000000").ToList(); var q = from c in db.Indexes where c.Identification.SecurityIdentification == "FR0000000000" select c; List <Index> results = q.ToList(); Console.WriteLine(results); } }
public ActionResult Answer(BuildOptimalCodeModel model) { var suggestedCode = new FrequencyCode(model.ElementaryCodes, model.InputData.FrequencyList); var optimalCode = OptimalCodeBuilder.GetOptimalCode(model.InputData.CodeAlphabet, model.InputData.FrequencyList); double suggestedOptimality = suggestedCode.GetCodeOptimality(); double optimality = optimalCode.GetCodeOptimality(); string checkMessage = String.Format("Верно. Введенный код является кодом с минимальной избыточностью. " + "Средняя длина элементарного кода - {0:0.0000}.", optimality); if (suggestedOptimality - optimality > 0.000001) { checkMessage = String.Format("Неверно. Введенный код не является кодом с минимальной избыточностью. " + "Средняя длина элементарного кода - {0:0.0000}. Минимальная средняя длина - {1:0.0000}.", suggestedOptimality, optimality); } model.Comment = checkMessage; return(View(model)); }
public InterestCalculation(PercentageRate rate = null, FrequencyCode CalculationFrequency = null, InterestComputationMethodCode DayCountBasis = null) { this.Rate = rate; this.CalculationFrequency = CalculationFrequency; if (CalculationFrequency == null) { this.CalculationFrequency = new FrequencyCode("S"); } if (DayCountBasis == null) { this.DayCountBasis = new InterestComputationMethodCode(); } else { this.DayCountBasis = DayCountBasis; } }
public void IndexContructionTest() { Equity e; Debt s; InvestmentFund f; Rating r; AssetHolding ia; Index ex; try { using (var db = new FGABusinessComponent.BusinessComponent.FGAContext("PREPROD", compiledModel)) { #if DEBUG // xml seeder: le fichier xml est lu et est chargé comme valeurs par défaut db.SaveChanges(); // ecriture du fichier pour permettre d avoir un fichier FGABusinessComponent.BusinessComponent.Util.EFCodeFirstMethods.DumpDbCreationScriptToFile(db); #endif //Security_TEST stest = new Security_TEST(); //stest.ISIN = (ISINIdentifier)"TEST234567890"; //System.Console.WriteLine(stest.ISIN); ex = new Index(Name: "Exemple d indice 1", ISIN: "BTS1TREU", IndexCurrency: (CurrencyCode)"EUR"); ex.IndexFixingDate = new TimeSpan(15, 30, 0); // 15h30 ex.IndexFrequency = FrequencyCode.getFrequencyByLabel("MONTHLY"); s = new Debt(ISIN: "PP11110000", FinancialInstrumentName: "Debt 1-Index test", MaturityDate: new DateTime(2013, 1, 1), interestCoupon: new InterestCalculation(new PercentageRate(1.666), new FrequencyCode(1))); s.Identification = new SecuritiesIdentification(Isin: "PP11110000"); s.FinancialInstrumentName = "Security 1"; s.MaturityDate = new DateTime(2013, 1, 1); ia = new AssetHolding(Date: this.dateOfData, ISIN: s.ISINId, HoldAsset: s, Holder: ex); ia.MarketValue = new CurrencyAndAmount(); ia.MarketValue.Value = 12; ia.MarketValue.Currency = (CurrencyCode)"EUR"; ia.FaceAmount = new CurrencyAndAmount(); ia.FaceAmount.Value = 5; ia.FaceAmount.Currency = (CurrencyCode)"EUR"; ia.BookValue = new CurrencyAndAmount(); ia.BookValue.Value = 5; ia.BookValue.Currency = (CurrencyCode)"EUR"; ia.Quantity = 30; //SecuritiesQuantity held = new SecuritiesQuantity(); //held.Unit = 2; //held.Rate = new PercentageRate(); //held.Rate.Value = 2; //held.Amount = new CurrencyAndAmount(); //held.Amount.Currency = (CurrencyCode)"USD"; //held.Amount.Value = 666; db.AssetHoldings.Add(ia); db.Indexes.Add(ex); db.SaveChanges(); ex = new Index(ISIN: "FR0000000000", Date: new DateTime(9999, 12, 31)); ex.IndexFixingDate = new TimeSpan(16, 30, 0); // 16h30 ex.IndexFrequency = FrequencyCode.getFrequencyByLabel("MONTHLY"); ex.IndexCurrency = (CurrencyCode)"USD"; db.Indexes.Add(ex); db.SaveChanges(); // test sans ISIN (identification) s = new Debt(ISIN: "PP11110000", FinancialInstrumentName: "Debt 2-Index test", MaturityDate: new DateTime(2013, 1, 1), interestCoupon: new InterestCalculation(new PercentageRate(1.666), new FrequencyCode(1))); ia = new AssetHolding(Date: this.dateOfData, ISIN: s.ISINId, Holder: ex, HoldAsset: s); db.AssetHoldings.Add(ia); db.SaveChanges(); Index ex1 = db.Indexes.FirstOrDefault <Index>(); Index ex2 = db.Indexes.Where <Index>(t => t.Identification.SecurityIdentification.ISINCode == "BTS1TREU").FirstOrDefault <Index>(); Index ex3 = db.Indexes.FirstOrDefault <Index>(); foreach (Component a in ex3.Items) { Console.Out.WriteLine(a.ToString()); } Index ex4 = (Index)ex3; List <Index> results2 = db.Indexes.Where <Index>(t => t.Identification.SecurityIdentification.ISINCode == "FR0000000000").ToList(); var q = from c in db.Indexes where c.Identification.SecurityIdentification.ISINCode == "FR0000000000" select c; List <Index> results = q.ToList(); Console.WriteLine(results); Index ex5 = db.Indexes.Find(new object[] { 3, "FR0000000000", new DateTime(9999, 12, 31) }); } } catch (Exception exc) { System.Console.WriteLine(exc); throw exc; } }
public static FrequencyCode GetOptimalCode(string alphabet, Dictionary <char, double> frequencyList) { int q = frequencyList.Count % (alphabet.Length - 1); if (q == 0) { q = alphabet.Length - 1; } if (q == 1) { q = alphabet.Length; } List <NodeContent> looseVertices = new List <NodeContent>(); OrientedGraph graph = new OrientedGraph(); foreach (var item in frequencyList) { NodeContent content = new NodeContent(item.Key, item.Value); AddToListWithSort(looseVertices, content); graph.AddNode(new GraphNode(content)); } while (looseVertices.Count > 1) { NodeContent newContent = new NodeContent(); GraphNode newNode = new GraphNode(newContent); for (int i = 0; i < q; i++) { NodeContent content = looseVertices[0]; newContent.Frequency += content.Frequency; GraphNode node = graph.GetNode(content); newNode.Connections.Add(node); looseVertices.RemoveAt(0); } AddToListWithSort(looseVertices, newContent); graph.AddNode(newNode); q = alphabet.Length; } FrequencyCode code = new FrequencyCode(); Queue <GraphNode> broadSearchQueue = new Queue <GraphNode>(); broadSearchQueue.Enqueue(graph.GetNode(looseVertices[0])); while (broadSearchQueue.Count > 0) { GraphNode node = broadSearchQueue.Dequeue(); NodeContent content = (NodeContent)node.NodeContent; if (node.Connections.Count == 0) { code.Set(content.Symbol, content.Code, content.Frequency); } else { for (int i = 0; i < node.Connections.Count; i++) { NodeContent childContent = (NodeContent)node.Connections[i].NodeContent; childContent.Code = content.Code + alphabet[i]; broadSearchQueue.Enqueue(node.Connections[i]); } } } return(code); }
public ActionResult Upload(HttpPostedFileBase upload) { if (upload != null) { string format = Path.GetExtension(upload.FileName); if (format == ".txt") { try { using (var reader = new StreamReader(upload.InputStream)) { string alphabet = reader.ReadLine(); if (alphabet != null) { for (int i = 0; i < alphabet.Length - 1; i++) { for (int j = i + 1; j < alphabet.Length; j++) { if (alphabet[j] == alphabet[i]) { ViewBag.ErrorMessage = "Все символы алфавита должны быть различны!"; return(View("Index")); } } } Dictionary <char, double> frequencies = new Dictionary <char, double>(); char[] separator = { ' ' }; double frequencySum = 0; while (!reader.EndOfStream) { string[] symbolArgs = reader.ReadLine().Split(separator, StringSplitOptions.RemoveEmptyEntries); if (symbolArgs.Length != 2) { ViewBag.ErrorMessage = "Пожалуйста, проверьте правильность введенных данных!"; return(View("Index")); } char symbol = Convert.ToChar(symbolArgs[0]); double frequency = Convert.ToDouble(symbolArgs[1]); frequencySum += frequency; frequencies.Add(symbol, frequency); } if (frequencies.Count == 0) { ViewBag.ErrorMessage = "Пожалуйста, введите в файл данные для построения кода!"; } else if (Math.Abs(frequencySum - 1) > 0.000001) { ViewBag.ErrorMessage = "Сумма вероятностей должна быть равна 1!"; } else { ViewBag.ErrorMessage = ""; FrequencyCode code = OptimalCodeBuilder.GetOptimalCode(alphabet, frequencies); return(View("Index", code)); } } else { ViewBag.ErrorMessage = "Пожалуйста, введите в файл данные для построения кода!"; } } } catch (FormatException) { ViewBag.ErrorMessage = "Пожалуйста, проверьте правильность введенных данных!"; } } else { ViewBag.ErrorMessage = "Пожалуйста, загрузите файл в формате .txt!"; } } else { ViewBag.ErrorMessage = "Пожалуйста, загрузите файл!"; } return(View("Index")); }
public ActionResult Upload(HttpPostedFileBase upload) { if (upload != null) { string format = Path.GetExtension(upload.FileName); if (format == ".txt") { try { using (var reader = new StreamReader(upload.InputStream)) { string alphabet = reader.ReadLine(); if (alphabet != null) { for (int i = 0; i < alphabet.Length - 1; i++) { for (int j = i + 1; j < alphabet.Length; j++) { if (alphabet[j] == alphabet[i]) { ViewBag.ErrorMessage = "Все символы алфавита должны быть различны!"; return(View("Index")); } } } Dictionary <char, string> codewords = new Dictionary <char, string>(); Dictionary <char, double> frequencies = new Dictionary <char, double>(); char[] separator = { ' ' }; double frequencySum = 0; while (!reader.EndOfStream) { string[] symbolArgs = reader.ReadLine().Split(separator, StringSplitOptions.RemoveEmptyEntries); if (symbolArgs.Length != 3) { ViewBag.ErrorMessage = "Пожалуйста, проверьте правильность введенных данных!"; return(View("Index")); } char symbol = Convert.ToChar(symbolArgs[0]); double frequency = Convert.ToDouble(symbolArgs[1]); frequencySum += frequency; string codeword = symbolArgs[2]; for (int i = 0; i < codeword.Length; i++) { if (alphabet.IndexOf(codeword[i]) == -1) { ViewBag.ErrorMessage = "Кодовые слова должны использовать только символы алфавита!"; return(View("Index")); } } codewords.Add(symbol, codeword); frequencies.Add(symbol, frequency); } if (frequencies.Count == 0) { ViewBag.ErrorMessage = "Пожалуйста, введите в файл данные для построения кода!"; } else if (Math.Abs(frequencySum - 1) > 0.000001) { ViewBag.ErrorMessage = "Сумма вероятностей должна быть равна 1!"; } else { ViewBag.ErrorMessage = ""; FrequencyCode suggestedCode = new FrequencyCode(codewords, frequencies); FrequencyCode optimalCode = OptimalCodeBuilder.GetOptimalCode(alphabet, frequencies); double suggestedCodeOptimality = suggestedCode.GetCodeOptimality(); double optimality = optimalCode.GetCodeOptimality(); if (suggestedCodeOptimality - optimality > 0.000001) { ViewBag.Answer = String.Format("Введенный код не является кодом с минимальной избыточностью. " + "Средняя длина элементарного кода - {0}. Минимальная средняя длина - {1}. " + "Ею обладает следующий код:", suggestedCodeOptimality, optimality); return(View("Index", optimalCode)); } else { ViewBag.Answer = String.Format("Введенный код является кодом с минимальной избыточностью. " + "Средняя длина элементарного кода - {0}.", optimality); return(View("Index")); } } } else { ViewBag.ErrorMessage = "Пожалуйста, введите в файл данные для построения кода!"; } } } catch (FormatException) { ViewBag.ErrorMessage = "Пожалуйста, проверьте правильность введенных данных!"; } } else { ViewBag.ErrorMessage = "Пожалуйста, загрузите файл в формате .txt!"; } } else { ViewBag.ErrorMessage = "Пожалуйста, загрузите файл!"; } return(View("Index")); }