Exemple #1
0
        private void findAndReplaceSameText()
        {
            int       OldIndex     = Texts.IndexOf(SelectText) - 1;
            TextModel oldText      = Texts[OldIndex];
            string    chinaOldText = oldText.ChinaText;
            string    vietOldText  = oldText.VietText;

            if (IsWorkForAll)
            {
                for (int i = 0; i < Jsons.Count; i++)
                {
                    for (int j = 0; j < Jsons[i].ListText.Count; j++)
                    {
                        if (Jsons[i].ListText[j].ChinaText == chinaOldText)
                        {
                            Jsons[i].ListText[j].VietText = vietOldText;
                            if (!Jsons[i].IsChangeJson || !Jsons[i].IsChangeTxt)
                            {
                                Jsons[i].IsChangeJson = true;
                                Jsons[i].IsChangeTxt  = true;
                            }
                        }
                    }
                }
            }
            else
            {
                JsonSelected.IsChangeJson = true;
                JsonSelected.IsChangeTxt  = true;
                for (int i = 0; i < Texts.Count; i++)
                {
                    if (Texts[OldIndex].ChinaText == Texts[i].ChinaText)
                    {
                        Texts[i].VietText = Texts[OldIndex].VietText;
                    }
                }
            }

            RaisePropertyChanged(TextsPropertyName);
            OnRefreshUI();
        }
Exemple #2
0
        private void NextItemAndSave()
        {
            CountToSave++;
            JsonSelected.IsChangeJson = true;
            int indexSelect = Texts.IndexOf(SelectText);

            //thuc hien replace trong nay

            //nho ho count -1
            if (Texts.Count - 1 > indexSelect)
            {
                SelectText = Texts[indexSelect + 1];
            }
            // auto save
            if (CountToSave >= 5)
            {
                SaveDataCommand.Execute(null);
                CountToSave = 0;
                JsonSelected.IsChangeJson = false;
            }
        }
Exemple #3
0
        public override void FillData(string data)
        {
            lookup.LoadLookUpTables();
            aqrIDLookUp.LoadLookUpTables();

            string[] tempContainer = data.Split('\n');
            string[] tempSplit;
            string   tempFinder       = string.Empty;
            string   tempSecurityName = string.Empty;
            string   tempMaturityDate = string.Empty;
            string   tempFund         = string.Empty;
            string   tempFixedPrice   = string.Empty;
            double   tempMultiplier   = 0;
            int      dateTimeIndex    = 0;
            DateTime tempContentDate;

            Texts = tempContainer.ToList();


            try
            {
                // Get the date reference
                tempFinder = GetTextBaseOnReference(ML_DATE);
                if (!string.IsNullOrEmpty(tempFinder))
                {
                    dateTimeIndex = Texts.IndexOf(tempFinder);

                    // FUND is the line after the letter date
                    while (string.IsNullOrEmpty(tempFund.Trim()))
                    {
                        tempFund = Texts[dateTimeIndex + 1];
                        dateTimeIndex++;
                    }
                    Fund = lookup.GetFundShortName(tempFund);
                }



                // TRADE ID / CP REF
                tempFinder = GetTextBaseOnReference(ML_TRADE_ID);
                if (!string.IsNullOrEmpty(tempFinder))
                {
                    tempSplit = tempFinder.Split(':');
                    regex     = new Regex(@"\d+");
                    Match match = regex.Match(tempSplit[1]);
                    if (match.Success)
                    {
                        CPRef = match.Value;
                    }
                }

                // TRANSACTION TYPE
                TransactionType = "Open";

                // SECURITY TYPE
                tempFinder = GetTextBaseOnReference(ML_COMMODITY);
                if (!string.IsNullOrEmpty(tempFinder))
                {
                    tempSplit        = tempFinder.Split(':');
                    tempSecurityName = tempSplit[1];

                    //if (string.Compare(tempSecurityName.Trim(), "SoyBean Meal", true) == 0)
                    if (tempSecurityName.Trim().Contains("SoyBean Meal"))
                    {
                        tempSecurityName = "Soy Meal";
                    }
                    else if (string.Compare(tempSecurityName.Trim(), ML_REFINED_PRODUCS) == 0)
                    {
                        tempFinder = GetTextBaseOnReference(ML_COMMODITY_REFERENCE_PRICE);
                        if (!string.IsNullOrEmpty(tempFinder))
                        {
                            tempSplit        = tempFinder.Split(':');
                            tempSecurityName = tempSplit.LastOrDefault();
                        }
                    }
                    KeyValuePair <string, string> kvp = lookup.GetSecurityValues(tempSecurityName);

                    tempSecurityName = kvp.Key;
                    SecurityType     = kvp.Value;
                }

                // MATURITY DATE
                tempFinder = GetTextBaseOnReference(ML_EXPIRY_DATE);
                if (string.IsNullOrEmpty(tempFinder))
                {
                    tempFinder = GetTextBaseOnReference(ML_TERMINIATION_DATE);
                }
                if (!string.IsNullOrEmpty(tempFinder))
                {
                    tempSplit = tempFinder.Split(':');
                    string dateToParse = tempSplit[1];

                    if (string.IsNullOrEmpty(dateToParse))
                    {
                        int dateIndex = Texts.IndexOf(tempFinder) + 2;
                        dateToParse = Texts[dateIndex];
                    }
                    DateTime tempPlaceHolder = DateTime.MinValue;
                    DateTime.TryParse(dateToParse, out tempPlaceHolder);

                    MaturityDate = tempPlaceHolder;
                }

                // SECURITY NAME

                // Special condition for Natural Gas
                if (string.Compare(tempSecurityName, "Natural Gas", true) == 0)
                {
                    //SecurityName = aqrIDLookUp.GetSecurityNameByMatch(tempSecurityName, MaturityDate);
                    SecurityName = aqrIDLookUp.GetSecurityNameByMonth(tempSecurityName, MaturityDate);

                    if (!string.IsNullOrEmpty(SecurityName))
                    {
                        MaturityDate = aqrIDLookUp.GetMaturityDateBySecurityName(SecurityName);
                    }
                }
                else
                {
                    // search using alias first
                    SecurityName = aqrIDLookUp.GetSecurityNameByAlias(SecurityType, tempSecurityName, MaturityDate);
                    //SecurityName =  aqrIDLookUp.GetSecurityName(SecurityType, MaturityDate);

                    if (string.IsNullOrEmpty(SecurityName))
                    {
                        SecurityName = aqrIDLookUp.GetSecurityNameByMatch(tempSecurityName, SecurityType, MaturityDate);
                    }
                }
                // AQR ID
                AQRID = aqrIDLookUp.GetAQRID(SecurityName, SecurityType);

                // MULTIPLIER
                Multiplier = lookup.GetMultiplier(tempSecurityName);

                if (Multiplier == 0)
                {
                    Multiplier = lookup.GetMultiplier(SecurityName);
                }

                // TRADE DATE
                tempFinder = GetTextBaseOnReference(ML_TRADE_DATE);
                if (!string.IsNullOrEmpty(tempFinder))
                {
                    tempSplit = tempFinder.Split(':');
                    DateTime tempPlaceHolder = DateTime.MinValue;
                    DateTime.TryParse(tempSplit[1], out tempPlaceHolder);

                    TradeDate = tempPlaceHolder;
                }

                // SETTLEMENT DATE
                int daysToAdd = 0;
                SettlementDate = TradeDate;
                while (daysToAdd < 3)
                {
                    SettlementDate = SettlementDate.AddDays(1);
                    if (SettlementDate.DayOfWeek != DayOfWeek.Saturday && SettlementDate.DayOfWeek != DayOfWeek.Sunday)
                    {
                        daysToAdd++;
                    }
                }

                // QUANTITY
                tempFinder = GetTextBaseOnReference(ML_TOTAL_NOTIONAL_QTY);
                if (string.IsNullOrEmpty(tempFinder))
                {
                    tempFinder = GetTextBaseOnReference(ML_VOLUME);
                }
                if (!string.IsNullOrEmpty(tempFinder))
                {
                    tempSplit = tempFinder.Split(':');
                    regex     = new Regex(@"\d+");

                    Match match = regex.Match(StripInvalidCharacters(tempSplit[1]));
                    if (match.Success)
                    {
                        Quantity = Convert.ToDouble(match.Value);
                        Quantity = Quantity / Multiplier;
                    }
                }

                // PRICE
                tempFinder = GetTextBaseOnReference(ML_FIXED_PRICE);
                if (!string.IsNullOrEmpty(tempFinder))
                {
                    tempSplit = tempFinder.Split(':');
                    Char[] tempChar = tempSplit[1].ToCharArray().Where(c => Char.IsDigit(c) || Char.IsPunctuation(c)).ToArray();
                    // temporary hard code unwanted characters to be removed
                    List <char> tempCharList = tempChar.ToList();
                    tempCharList.Remove('(');
                    tempCharList.Remove(')');

                    Price = Convert.ToDouble(new string(tempCharList.ToArray()));

                    if (lookup.SelectedIndex > -1)
                    {
                        string note = lookup.GetNote(lookup.SelectedIndex);
                        if (!string.IsNullOrEmpty(note) && string.Compare(note, ML_MOVE_2_DECIMAL_RIGHT) == 0)
                        {
                            Price = Price * 100;
                        }
                    }

                    // for local ccy
                    tempFixedPrice = tempSplit[1];
                }

                // LOCAL CCY
                tempFinder = GetTextBaseOnReference(ML_TRANSACTION_CURRENCY);
                if (!string.IsNullOrEmpty(tempFinder))
                {
                    tempSplit     = tempFinder.Split(':');
                    LocalCurrency = tempSplit.LastOrDefault();
                }
                else if (!string.IsNullOrEmpty(tempFixedPrice))
                {
                    tempSplit     = tempFixedPrice.TrimStart(' ').Split(' ');
                    LocalCurrency = tempSplit.FirstOrDefault();
                }

                // NOTIONAL
                Notional = Quantity * Price * Multiplier;

                // BUYER
                tempFinder = GetTextBaseOnReference(ML_FIXED_PRICE_PAYOR);
                if (string.IsNullOrEmpty(tempFinder))
                {
                    tempFinder = GetTextBaseOnReference(ML_FIXED_PRICE_PAYER);
                }

                if (!string.IsNullOrEmpty(tempFinder))
                {
                    string tempBuyer = string.Empty;

                    tempSplit = tempFinder.Split(':');
                    tempBuyer = tempSplit.LastOrDefault();

                    if (string.Compare(tempBuyer, tempFund, true) == 0 || StripInvalidCharacters(tempFund).Contains(StripInvalidCharacters(tempBuyer)))
                    {
                        Buyer = Fund;
                    }
                    else
                    {
                        Buyer = "ML";
                    }
                }

                // SELLER
                tempFinder = GetTextBaseOnReference(ML_FLOATNG_PRICE_PAYOR);
                if (string.IsNullOrEmpty(tempFinder))
                {
                    tempFinder = GetTextBaseOnReference(ML_FLOATNG_PRICE_PAYER);
                }
                if (!string.IsNullOrEmpty(tempFinder))
                {
                    tempSplit = tempFinder.Split(':');
                    Seller    = tempSplit.LastOrDefault();
                    if (string.Compare(Seller.Trim(), ML_LONG_NAME, true) == 0)
                    {
                        Seller = "ML";
                    }
                    else
                    {
                        Seller = Fund;
                    }
                }

                FixedRate       = 0;
                FloatRate       = 0;
                SettledCash     = 0;
                SettledCurrency = LocalCurrency;
                Spread          = 0;

                CounterParty = "ML";
                Status       = RunStatus.Success;
            }
            catch (Exception ex)
            {
                Status = RunStatus.Failed;
                CoreLibrary.Logger.Instance.Error(this.GetType(), "Error in parsing document " + CPRef + Environment.NewLine + ex.Message);
            }
        }