Example #1
0
        //public void ShowHist(Region region, int date, int posId = -1, string pfsId = null, int goBack = 2, bool showFixes = false)
        //{
        //    if (pfsId == null) pfsId = GetPfsId(DbConnections[region], posId);
        //    if (posId < 0) posId = GetPfsPosId(DbConnections[region], pfsId);
        //    var secId = GetPfsSecId(DbConnections[region], pfsId);
        //    var underlyer = GetUnderlyer(DbConnections[region], posId);
        //    var fromDate = Utility.DateToRover8(Utility.AddBusinessDays(Utility.Rover8ToDate(date), -goBack - 1, null));
        //    var fxHist = ReadFXHist(DbConnections[region], fromDate);
        //    //    fxHist.Select(kvp => new { Dt = kvp.Key, FX_USD_GBP = kvp.Value["GBP"], FX_USD_AUD = kvp.Value["AUD"], }).Dump();
        //    PaaHist = ReadPaaData(DbConnections[region], posId, fromDate);
        //    var paaHistDict = PaaHist.ToDictionary(h => h.EodDate, h => h);

        //    //string.Format("date= {0}, posId= {1}, secId= {2}, extId= {3},\t\t\t\t\t\t{4}", date, posId, secId, pfsId, underlyer).Dump();
        //    //string.Format(LiveURLFormat, pfsId).Dump();
        //    //string.Format(EodURLFormat, EqrmsPfsRegionMap[region], date, pfsId).Dump();
        //    Console.WriteLine(string.Format("date= {0}, posId= {1}, secId= {2}, extId= {3},\t\t\t\t\t\t{4}", date, posId, secId, pfsId, underlyer));
        //    Console.WriteLine(string.Format(LiveURLFormat, pfsId));
        //    Console.WriteLine(string.Format(EodURLFormat, EqrmsPfsRegionMap[region], date, pfsId));
        //    var pfsHist = FetchPfsSwapHistory(region, pfsId, fromDate).Select(sw => new { Date = sw.Key, Swap = sw.Value }).OrderBy(s => s.Date).ToList();

        //}

        #region Methods called by ShowHist
        public void PopulateDateSets(int date)
        {
            //"".Dump("PFS Data"); pfsData.Dump();
            PfsDataSet = PfsHist.Skip(1).TakeWhile(p => p.Date <= date).ToDictionary(h => h.Date, h => h);

            //"".Dump("PL Consistency Data");
            var plData = (from p in PfsHist
                          join d in PaaHist on p.Date equals d.EodDate
                          select PfsDbConsistencyData.CreatePfsDbConsistencyData(p.Swap_T_1, d)
                          ).Skip(1).TakeWhile(p => p.EodDate <= date);

            ConsistencyDataSet = plData.ToDictionary(h => h.EodDate, h => h);

            //"".Dump("PAA Data");
            PaaDataSet = PaaHist.Skip(1).TakeWhile(p => p.EodDate <= date).ToDictionary(h => h.EodDate, h => h);//.Dump();

            //"".Dump("PAA DtD Data");
            PaaDtdDataSet = PaaDtDData(PaaHist).Skip(1).TakeWhile(p => p.EodDate <= date).ToDictionary(h => h.EodDate, h => h);//.Dump();

            //var paaUsdfied = PaaUsdFiedData(paaHist.TakeWhile(p => p.EodDate <= date).ToList(), fxHist);
            //"".Dump("PAA Data USDfied");
            //paaUsdfied.Skip(1)
            //.Dump();
            //"".Dump("PAA DtD Data USDfied");
            //PaaDtDData(paaUsdfied).Skip(1)
            //.Dump();
        }
Example #2
0
        public void GetOnePositionData(Region region, int posId, List <int> dates, Dictionary <int, Dictionary <string, double> > fxHist, string pfsId = null, int goBack = 2)
        {
            if (pfsId == null)
            {
                pfsId = GetPfsId(DbConnections[region], posId);
            }
            if (fxHist == null)
            {
                throw new ArgumentNullException(nameof(fxHist));
            }

            dates.Sort((a, b) => a.CompareTo(b));
            var fromDate = Utility.DateToRover8(Utility.AddBusinessDays(Utility.Rover8ToDate(dates[0]), -goBack - 1, null));
            var tillDate = dates.Last();

            PaaHist = ReadPaaData(DbConnections[region], posId, fromDate, tillDate);
            var paaHistDict = PaaHist.ToDictionary(h => h.EodDate, h => h);

            var pfsHistDict = FetchPfsSwapHistory(region, pfsId, fromDate, tillDate).OrderBy(s => s.Key).ToList();

            PfsHist = new List <PfsData>();
            var i = -1;

            foreach (var d in dates)
            {
                do
                {
                    i++;
                } while (i < pfsHistDict.Count - 1 && pfsHistDict[i].Key < d);


                if (pfsHistDict[i].Key != d)
                {
                    continue;
                }

                var swap_T_1 = pfsHistDict[i].Value;
                var swap_T_2 = pfsHistDict[i == 0 ? 0 : i - 1].Value;

                var fxRates = fxHist.ContainsKey(d) ? fxHist[d] : null;
                var fxRate  = Utility.GetFxRate(fxRates, swap_T_1.SwapCurrency);

                PfsHist.Add(new PfsData(d, swap_T_1, swap_T_2, fxRate));

                Console.WriteLine(EodURLFormat, EqrmsPfsRegionMap[region], d, pfsId);
                Console.WriteLine(LiveURLFormat, pfsId);
            }
        }