static void Main(string[] args)
 {
     var service = new ConversionService();
     var local   = new LocalCurrency(400, "KZT");
 }
Example #2
0
        public override void FillData(string data)
        {
            string[] tempContainer = data.Split('\n');
            string[] tempSplit;
            string   tempFinder       = string.Empty;
            string   tempSecurityName = string.Empty;
            string   tempMaturityDate = string.Empty;
            double   tempMultiplier   = 0;
            int      dateTimeIndex    = 0;
            DateTime tempContentDate;

            Texts = tempContainer.ToList();



            lookup.LoadLookUpTables();
            aqrIDLookUp.LoadLookUpTables();

            for (int i = 0; i < Texts.Count; i++)
            {
                if (DateTime.TryParse(Texts[i], out tempContentDate))
                {
                    dateTimeIndex = i > 0 ? i : 0;
                    ContentDate   = tempContentDate;
                    break;
                }
            }


            // COUNTERPARTY - HARDCODED FOR NOW
            CounterParty = "JPM";

            // FUND is the line after the letter date
            Fund = Texts[dateTimeIndex + 1];
            Fund = lookup.GetFundShortName(Fund);

            try
            {
                // CP REF
                tempFinder = Texts.Where(x => x.Contains(JPM_CPREF_REFERENCE)).FirstOrDefault();
                if (!string.IsNullOrEmpty(tempFinder))
                {
                    tempSplit = tempFinder.Split(':');
                    CPRef     = tempSplit.Last().Trim();
                }

                // FUND
                //tempFinder = Texts.Where(x => x.Contains(FUND_REFERENCE)).FirstOrDefault();
                //if (!string.IsNullOrEmpty(tempFinder))
                //{
                //    tempSplit = tempFinder.Split(':');
                //    Fund = tempSplit.Last();
                //}


                // TRANSACTION TYPE
                TransactionType = "Open"; // always open

                // SECURITY NAME
                // Dropdown (Index:   Swiss market Index) We determine the date based on the Valuation date which is also available in the General Terms under Valuation Date at the end of the paragraph, page 2.

                // TRADE DATE
                tempFinder = Texts.Where(x => x.Contains(JPM_TRADE_DATE_REFERENCE)).FirstOrDefault();
                if (!string.IsNullOrEmpty(tempFinder))
                {
                    tempSplit = tempFinder.Split(':');
                    TradeDate = DateTime.Parse(tempSplit.Last());
                }

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

                // MATURITY DATE
                // Valuation date - at the end of the paragraph with this format : 19 December 2014


                // TERMINATION DATE
                tempFinder = Texts.Where(x => x.Contains(TERMINATION_DATE_REFERENCE)).FirstOrDefault();
                if (!string.IsNullOrEmpty(tempFinder))
                {
                    tempSplit = tempFinder.Split(':');
                    if (string.Compare(tempSplit.Last(), JPM_TERMINATION_DATE_CASH_SETTLEMENT_PAYMENT_DATE_REFERENCE) == 0)
                    {
                        MaturityDate = SettlementDate;
                    }
                    else
                    {
                        MaturityDate = DateTime.Parse(tempSplit.Last());
                    }
                }

                // MULTIPLIER
                tempFinder = Texts.Where(x => x.Contains(JPM_MULTIPLIER_REFERENCE)).FirstOrDefault();
                if (!string.IsNullOrEmpty(tempFinder))
                {
                    if (tempFinder.ToLower().Contains("deal"))
                    {
                        tempFinder = tempFinder.ToLower().Split(new string[] { "deal" }, StringSplitOptions.RemoveEmptyEntries).First();
                    }
                    tempSplit = tempFinder.Split(':');
                    double.TryParse(tempSplit.Last(), out tempMultiplier);
                    Multiplier = tempMultiplier;
                }
                //lookup.GetMultiplier(tempFund);

                // PRICE
                try
                {
                    tempFinder = Texts.Where(x => x.Contains(JPM_FORWARD_PRICE)).FirstOrDefault();
                    if (!string.IsNullOrEmpty(tempFinder))
                    {
                        tempSplit = tempFinder.Split(':');
                        string[] priceSplit = tempSplit[1].Split(' ');
                        string   price      = string.Empty;

                        if (!string.IsNullOrEmpty(priceSplit.First()))
                        {
                            price = priceSplit.First().Split(new string[] { "Deal" }, StringSplitOptions.RemoveEmptyEntries).First();
                        }
                        else
                        {
                            price = priceSplit[1].Split(new string[] { "Deal" }, StringSplitOptions.RemoveEmptyEntries).First();
                        }
                        Price = Double.Parse(price);
                    }
                    else
                    {
                        // Initial price
                        tempFinder = Texts.Where(x => x.Contains(JPM_HANGSENG_INITIAL_PRICE)).FirstOrDefault();
                        if (!string.IsNullOrEmpty(tempFinder))
                        {
                            tempSplit = tempFinder.Split(':');
                            string[] priceSplit = tempSplit[1].Split(' ');
                            //string price = string.Empty;

                            //if (!string.IsNullOrEmpty(priceSplit.First()))
                            //{
                            //    price = priceSplit.First().Split(new string[] { "Deal" }, StringSplitOptions.RemoveEmptyEntries).First();
                            //}
                            //else
                            //{
                            //    price = priceSplit[1].Split(new string[] { "Deal" }, StringSplitOptions.RemoveEmptyEntries).First();
                            //}
                            double price_temp = 0;
                            foreach (string tempPrice in priceSplit)
                            {
                                double.TryParse(tempPrice, out price_temp);
                                if (price_temp > 0)
                                {
                                    break;
                                }
                            }
                            Price = price_temp;
                            //Price = Double.Parse(price);
                        }
                    }
                }
                finally
                { }


                // LOCAL CURRENCY
                tempFinder = Texts.Where(x => x.Trim().Contains(JPM_SETTLEMENT_CURRENCY)).FirstOrDefault();
                if (!string.IsNullOrEmpty(tempFinder))
                {
                    //tempSplit = tempFinder.Split(new string[] { ": " }, StringSplitOptions.None);
                    //LocalCurrency = tempSplit.Last();
                    //if (LocalCurrency.Length > 3)
                    //{
                    //    tempSplit = LocalCurrency.Split(' ');
                    //    LocalCCY = tempSplit.First();
                    //}
                    tempSplit     = tempFinder.Split(':');
                    LocalCurrency = tempSplit.Last().Trim();
                    LocalCurrency = StripInvalidCharacters(LocalCurrency);

                    tempFinder = GetTextBaseOnReference(JPM_EQUITY_NOTIONAL_AMOUNT);
                    if (!string.IsNullOrEmpty(tempFinder))
                    {
                        tempSplit = tempFinder.Split(':');
                        if (tempSplit != null && tempSplit.Count() > 0)
                        {
                            string tempCurrency = tempSplit.Last();
                            tempSplit = tempCurrency.Split(' ');


                            if (tempSplit != null && tempSplit.Count() > 0)
                            {
                                tempCurrency = StripInvalidCharacters(tempSplit.First() != string.Empty ? tempSplit.First() : tempSplit[1]);

                                if (string.Compare(tempCurrency.ToLower(), LocalCurrency.ToLower()) != 0)
                                {
                                    LocalCurrency = tempCurrency;
                                }
                            }
                        }
                    }
                }

                // SELLER
                tempFinder = Texts.Where(x => x.Contains(JPM_SELLER)).FirstOrDefault();
                if (!string.IsNullOrEmpty(tempFinder))
                {
                    tempSplit = tempFinder.Split(':');
                    Seller    = tempSplit.Last().Trim();

                    // hard code for now
                    if (string.Compare(StripInvalidCharacters(Seller), "JPMorgan") == 0)
                    {
                        Seller = "JPM";
                    }
                    else if (string.Compare(StripInvalidCharacters(Seller), "Counterparty") == 0)
                    {
                        Seller = Fund;
                    }
                }
                else
                {
                    tempFinder = Texts.Where(x => x.Contains(JPM_EQUITY_AMOUNT_PAYER)).FirstOrDefault();
                    if (!string.IsNullOrEmpty(tempFinder))
                    {
                        tempSplit = tempFinder.Split(':');
                        Seller    = tempSplit.Last().Trim();
                        // hard code for now
                        if (string.Compare(StripInvalidCharacters(Seller), "JPMorgan") == 0)
                        {
                            Seller = "JPM";
                        }
                        else if (string.Compare(StripInvalidCharacters(Seller), "Counterparty") == 0)
                        {
                            Seller = Fund;
                        }
                    }
                }

                // BUYER
                // NOTE: Buyer is always the opposite of seller
                if (string.Compare(Seller, "JPM") == 0)
                {
                    Buyer = Fund;
                }
                else
                {
                    Buyer = "JPM";
                }

                // MATURITY DATE
                tempFinder = Texts.Where(x => x.Contains(JPM_VALUATION_DATE_EXPECTED_TO_BE)).FirstOrDefault();
                if (!string.IsNullOrEmpty(tempFinder))
                {
                    Regex    regex           = new Regex(@"\d{2}\s\w+\s\d{4}");
                    Match    match           = regex.Match(tempFinder);
                    DateTime tempPlaceHolder = DateTime.MinValue;

                    if (match.Success)
                    {
                        DateTime.TryParse(match.Value, out tempPlaceHolder);
                        if (tempPlaceHolder != DateTime.MinValue)
                        {
                            MaturityDate = tempPlaceHolder;
                        }
                    }
                }

                // SECURITY NAME
                tempFinder = Texts.Where(x => x.Replace(" ", "").Contains(JPM_SECURITY_NAME_REFERENCE)).FirstOrDefault();
                if (!string.IsNullOrEmpty(tempFinder))
                {
                    tempSplit        = tempFinder.Split(':');
                    tempSecurityName = tempSplit.Last();

                    if (!string.IsNullOrEmpty(tempSecurityName))
                    {
                        if (tempSecurityName.ToLower().Contains("hang seng"))
                        {
                            if (string.Compare(tempSecurityName.Trim(), "Hang Seng China Enterprises Index", true) == 0)
                            {
                                tempSecurityName = "HSCEI China Index";
                            }
                        }
                        else if (tempSecurityName.ToLower().Contains("taiex index"))
                        {
                            tempSecurityName = "TAIEX Futures Swap";
                        }

                        SecurityName = aqrIDLookUp.GetSecurityNameByMatch(tempSecurityName, MaturityDate);
                    }
                }

                // SECURITY TYPE
                SecurityType = aqrIDLookUp.GetSecurityType(SecurityName);

                // MULTIPLIER
                tempSecurityName = SecurityName.Split(' ').First();
                tempMultiplier   = lookup.GetMultiplier(tempSecurityName, SecurityType);
                if (tempMultiplier == 0)
                {
                }

                // QUANTIY
                tempFinder = Texts.Where(x => x.Contains(JPM_NUMBER_OF_UNITS)).FirstOrDefault();
                if (!string.IsNullOrEmpty(tempFinder))
                {
                    tempSplit     = tempFinder.Split(':');
                    NumberOfUnits = Double.Parse(tempSplit.Last());
                }

                if (NumberOfUnits > 0)
                {
                    Quantity = NumberOfUnits / tempMultiplier;
                }
                else
                {
                    Quantity = Multiplier / tempMultiplier;
                }

                // Multiplier
                Multiplier = tempMultiplier;

                // NOTIONAL
                Notional = Quantity * Price * Multiplier;

                // AQR ID
                AQRID = aqrIDLookUp.GetAQRID(SecurityName, SecurityType);

                //Always zero unless otherwise stated in the contract
                FixedRate = 0;
                //Always zero unless otherwise stated in the contract
                FloatRate = 0;
                //Always zero unless otherwise stated in the contract
                SettledCash     = 0;
                SettledCurrency = LocalCurrency;
                Spread          = 0;
                Status          = ConfirmsData.RunStatus.Success;
            }
            catch (Exception ex)
            {
                Status = ConfirmsData.RunStatus.Failed;
            }
        }