예제 #1
0
        public void MakeSureThatPricingCategoriesAreWorking()
        {
            var mgr = new DatawarehouseManager();
            // some equity requests
            var fieldList = "BDVD_NEXT_EST_EX_DT,BDVD_PROJ_DIV_AMT,DVD_CRNCY,VOLATILITY_10D_CALC,VOLATILITY_180D_CALC,VOLATILITY_200D_CALC,VOLATILITY_260D_CALC,VOLATILITY_30D_CALC,VOLATILITY_360D_CALC,VOLATILITY_60D_CALC,VOLATILITY_90D_CALC";

            Assert.AreEqual(1, Convert.ToInt16(mgr.RequiresBloombergLicenseSecurityMaster(fieldList, false)));
            Assert.AreEqual(1, Convert.ToInt16(mgr.RequiresBloombergLicenseDerivedDataEod(fieldList)));
            Assert.AreEqual(0, Convert.ToInt16(mgr.RequiresBloombergLicensePricingDataEod(fieldList)));
            Assert.AreEqual(1, Convert.ToInt16(mgr.RequiresBloombergLicenseEstimates(fieldList)));
            Assert.AreEqual(0, Convert.ToInt16(mgr.RequiresBloombergLicenseCreditRisk(fieldList)));

            fieldList = "COUNTRY,EQY_SH_OUT_REAL,ID_ISIN";
            Assert.AreEqual(1, Convert.ToInt16(mgr.RequiresBloombergLicenseSecurityMaster(fieldList, false)));
            Assert.AreEqual(0, Convert.ToInt16(mgr.RequiresBloombergLicenseDerivedDataEod(fieldList)));
            Assert.AreEqual(0, Convert.ToInt16(mgr.RequiresBloombergLicensePricingDataEod(fieldList)));
            Assert.AreEqual(0, Convert.ToInt16(mgr.RequiresBloombergLicenseEstimates(fieldList)));
            Assert.AreEqual(0, Convert.ToInt16(mgr.RequiresBloombergLicenseCreditRisk(fieldList)));

            fieldList = "ID_BB_GLOBAL,NAME,SECURITY_TYP,ID_BB_ULTIMATE_PARENT_CO,ID_BB_ULTIMATE_PARENT_CO_NAME";
            Assert.AreEqual(0, Convert.ToInt16(mgr.RequiresBloombergLicenseSecurityMaster(fieldList, false)));
            Assert.AreEqual(0, Convert.ToInt16(mgr.RequiresBloombergLicenseDerivedDataEod(fieldList)));
            Assert.AreEqual(0, Convert.ToInt16(mgr.RequiresBloombergLicensePricingDataEod(fieldList)));
            Assert.AreEqual(0, Convert.ToInt16(mgr.RequiresBloombergLicenseEstimates(fieldList)));
            Assert.AreEqual(1, Convert.ToInt16(mgr.RequiresBloombergLicenseCreditRisk(fieldList)));

            fieldList = "ID_BB_GLOBAL,NAME,SECURITY_TYP,ID_BB_ULTIMATE_PARENT_CO,ULT_PARENT_CNTRY_INCORPORATION";
            Assert.AreEqual(0, Convert.ToInt16(mgr.RequiresBloombergLicenseCreditRisk(fieldList)));

            fieldList = " PX_LAST,PX_BID,PX_ASK,  QUOTE_TYP,PX_YEST_CLOSE,PX_CLOSE_2D ";
            Assert.AreEqual(0, Convert.ToInt16(mgr.RequiresBloombergLicenseSecurityMaster(fieldList, false)));
            Assert.AreEqual(0, Convert.ToInt16(mgr.RequiresBloombergLicenseDerivedDataEod(fieldList)));
            Assert.AreEqual(1, Convert.ToInt16(mgr.RequiresBloombergLicensePricingDataEod(fieldList)));

            Assert.AreEqual(0, Convert.ToInt16(mgr.RequiresBloombergLicensePricingDataIntraday(fieldList, true)));
            Assert.AreEqual(1, Convert.ToInt16(mgr.RequiresBloombergLicensePricingDataIntraday(fieldList, false)));

            Assert.AreEqual(0, Convert.ToInt16(mgr.RequiresBloombergLicenseEstimates(fieldList)));
            Assert.AreEqual(0, Convert.ToInt16(mgr.RequiresBloombergLicenseCreditRisk(fieldList)));

            fieldList = "BDVD_NEXT_EST_EX_DT,BDVD_PROJ_DIV_AMT,DVD_CRNCY,ID_ISIN,VOLATILITY_10D_CALC,VOLATILITY_180D_CALC,VOLATILITY_200D_CALC,VOLATILITY_260D_CALC,VOLATILITY_30D_CALC,VOLATILITY_360D_CALC,VOLATILITY_60D_CALC,VOLATILITY_90D_CALC";
            Assert.AreEqual(1, Convert.ToInt16(mgr.RequiresBloombergLicenseDerivedDataEod(fieldList)));
            Assert.AreEqual(0, Convert.ToInt16(mgr.RequiresBloombergLicensePricingDataIntraday(fieldList, true)));
            Assert.AreEqual(0, Convert.ToInt16(mgr.RequiresBloombergLicensePricingDataIntraday(fieldList, false)));
            Assert.AreEqual(0, Convert.ToInt16(mgr.RequiresBloombergLicensePricingDataEod(fieldList)));

            fieldList = "PX_LAST,PX_LAST_Eod,PX_BID,PX_ASK,  QUOTE_TYP,PX_YEST_CLOSE,PX_CLOSE_2D";
            Assert.IsFalse(mgr.RequiresBloombergLicensePricingDataIntraday(fieldList, true));
            Assert.IsTrue(mgr.RequiresBloombergLicensePricingDataEod(fieldList));

            fieldList = "EQY_SH_OUT_REAL,INDUSTRY_SECTOR,COUNTRY_FULL_NAME,SSR_LIQUIDITY_INDICATOR,PX_LAST,PX_LAST_Eod,PX_BID,PX_ASK,  QUOTE_TYP,PX_YEST_CLOSE,PX_CLOSE_2D ";
            Assert.IsTrue(mgr.RequiresBloombergLicensePricingDataIntraday(fieldList, false));
            Assert.IsFalse(mgr.RequiresBloombergLicensePricingDataIntraday(fieldList, true));

            fieldList = "ULT_PARENT_CNTRY_DOMICILE, COUNTRY";
            Assert.IsTrue(mgr.RequiresBloombergLicenseSecurityMaster(fieldList, false));
            Assert.IsFalse(mgr.RequiresBloombergLicenseSecurityMaster(fieldList, true));

            fieldList = "EQY_SH_OUT_REAL,ID_ISIN,ULT_PARENT_CNTRY_DOMICILE, COUNTRY";
            Assert.IsFalse(mgr.RequiresBloombergLicenseSecurityMaster(fieldList, true));
        }
예제 #2
0
파일: Program.cs 프로젝트: colinnaylor/CN
        private static void Main(string[] args)
        {
            Utils.Logger.Info("Starting process");
            Utils.Logger.Info("Database connection string: {0} ", ConfigurationManager.ConnectionStrings["BloombergConnectionString"].ToString());


            try
            {
                var mgr = new DatawarehouseManager();
                Utils.SetLoggerClassName(args[0]);

                if (args[0].ToUpper() == "PM")
                {
                    var T = DateTime.Now.Date;

                    if (args.Length == 2)
                    {
                        T = DateTime.Parse(args[1]);
                    }

                    Utils.Logger.Info("Running EOD for: {0}", T.ToString(CultureInfo.InvariantCulture));

                    //fill with tickers from T positions
                    Utils.Logger.Info(string.Format("{0}: GetLiveTickersUsingBergConsumerSqls", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")));
                    var tickers = mgr.GetLiveTickersUsingBergConsumerSqls(T);

                    Utils.Logger.Info(string.Format("{0}: InsertTickersIntoDatawarehouse", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")));
                    mgr.InsertTickersIntoDatawarehouse(tickers, T);

                    //recreate datawarehouse - categorise tor long types for all tickers in datawarehouse
                    Utils.Logger.Info(string.Format("{0}: CategoriseBergTickersIntoTorontoAssetTypes", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")));
                    mgr.CategoriseBergTickersIntoTorontoAssetTypes(T);

                    //upload tickers to toronto
                    Utils.Logger.Info(string.Format("{0}: UploadTickersToToronto", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")));
                    Utils.DbController.ExecuteNonQuery(File.ReadAllText("Sql\\UploadTickersToToronto.sql").Replace("{Position_Date}", T.ToString("ddMMMyyyy")));
                }
                else if (args[0].ToUpper() == "AM")
                {
                    var tminus1 = new DateUtils().PreviousWorkDay(DateTime.Now.Date);

                    //download from tor for T-1
                    Utils.Logger.Info(string.Format("{0}: DownloadDataFromToronto", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")));
                    Utils.DbController.ExecuteNonQuery(File.ReadAllText("Sql\\DownloadDataFromToronto.sql").Replace("{Position_Date}", tminus1.ToString("ddMMMyyyy")));

                    //enrich datawarehouse entries for T-1
                    Utils.Logger.Info(string.Format("{0}: EnrichDatawarehouse", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")));
                    Utils.DbController.ExecuteNonQuery(File.ReadAllText("sql\\EnrichDatawarehouse.sql").Replace("{Position_Date}", tminus1.ToString("ddMMMyyyy")));

                    //ready for use!
                }
                else if (args[0].ToUpper() == "ENRICH")
                {
                    var tminus1 = new DateUtils().PreviousWorkDay(DateTime.Now.Date);
                    if (args.Length == 2)
                    {
                        tminus1 = DateTime.Parse(args[1]);
                    }
                    var dw = new DatawarehouseManager();
                    if (dw.HasBeenEnrichedForDate(tminus1))
                    {
                        Utils.Logger.Info("EnrichDatawarehouse - doing nothing - already enriched: {0:ddMMMyyyy}", tminus1);
                    }
                    else
                    {
                        if (dw.DataAvailableInAllPricingViews(tminus1))
                        {
                            Utils.Logger.Info("EnrichDatawarehouse - starting: {0:ddMMMyyyy}", tminus1);
                            Utils.DbController.ExecuteNonQuery(File.ReadAllText("sql\\EnrichDatawarehouse.sql").Replace("{Position_Date}", tminus1.ToString("ddMMMyyyy")));
                            Utils.Logger.Info("EnrichDatawarehouse - completed: {0:ddMMMyyyy}", tminus1);

                            Utils.Logger.Info("Calculating usage costs - writing to table CostReportActual - starting: {0:ddMMMyyyy}", tminus1);
                            mgr.RunCostReportActual(tminus1);
                            Utils.Logger.Info("Calculating usage costs - writing to table CostReportActual - completed: {0:ddMMMyyyy}", tminus1);

                            CheckData(tminus1);
                        }
                        else
                        {
                            Utils.Logger.Info("EnrichDatawarehouse - doing nothing - not all required data is ready: {0:ddMMMyyyy}", tminus1);
                        }
                    }
                }
                else if (args[0].ToUpper() == "COSTS")
                {
                    var tminus1 = new DateUtils().PreviousWorkDay(DateTime.Now.Date);
                    if (args.Length == 2)
                    {
                        tminus1 = DateTime.Parse(args[1]);
                    }
                    mgr.RunCostReportActual(tminus1);
                }
                else if (args[0].ToUpper() == "DOWNLOAD")
                {
                    var tminus1 = new DateUtils().PreviousWorkDay(DateTime.Now.Date);
                    if (args.Length == 2)
                    {
                        tminus1 = DateTime.Parse(args[1]);
                    }

                    //download from tor for T-1
                    var dw = new DatawarehouseManager(); var toronto = new TorontoViewManager();

                    foreach (var torView in toronto.ListOfTorontoViews())
                    {
                        Utils.Logger.Info("Checking for work to be done on {0} for date {1:ddMMMyyyy}", torView, tminus1);
                        if (!dw.HasDataInWarehouseTableForDate(torView.Replace("ve_", "TorView"), tminus1) &&
                            toronto.DataIsReadyInViewForDate(torView, tminus1))
                        {
                            Utils.Logger.Info("DOWNLOAD starting ... {0} for date {1:ddMMMyyyy}", torView, tminus1);
                            Utils.DbController.ExecuteNonQuery(
                                File.ReadAllText(string.Format("Sql\\DownloadDataFromToronto.{0}.sql", torView.Replace("ve_", "TorView")))
                                .Replace("{Position_Date}", tminus1.ToString("ddMMMyyyy")));
                            Utils.Logger.Info("DOWNLOAD completed ... {0} for date {1:ddMMMyyyy}", torView, tminus1);
                        }
                        else
                        {
                            Utils.Logger.Info("Doing nothing - already have data or data not yet available ... {0} for date {1:ddMMMyyyy}", torView, tminus1);
                        }
                    }
                }
                else if (args[0].ToUpper() == "GETTICKERS")
                {
                    var T = DateTime.Now.Date;
                    if (args.Length == 2)
                    {
                        T = DateTime.Parse(args[1]);
                    }
                    //fill with tickers from T positions
                    Utils.Logger.Info(string.Format("{0}: GetLiveTickersUsingBergConsumerSqls", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")));
                    var tickers = mgr.GetLiveTickersUsingBergConsumerSqls(T);

                    Utils.Logger.Info(string.Format("{0}: InsertTickersIntoDatawarehouse", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")));
                    mgr.InsertTickersIntoDatawarehouse(tickers, T);
                }
                else if (args[0].ToUpper() == "UPLOAD")
                {
                    var T = DateTime.Now.Date;

                    //upload tickers to toronto
                    Utils.Logger.Info(string.Format("{0}: UploadTickersToToronto", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")));
                    Utils.DbController.ExecuteNonQuery(File.ReadAllText("Sql\\UploadTickersToToronto.sql").Replace("{Position_Date}", T.ToString("ddMMMyyyy")));
                }
                else if (args[0].ToUpper() == "CATEGORISE")
                {
                    var T = DateTime.Now.Date;
                    if (args.Length == 2)
                    {
                        T = DateTime.Parse(args[1]);
                    }
                    //recreate datawarehouse - categorise tor long types for all tickers in datawarehouse
                    Utils.Logger.Info(string.Format("{0}: CategoriseBergTickersIntoTorontoAssetTypes", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")));
                    mgr.CategoriseBergTickersIntoTorontoAssetTypes(T);
                }
                else if (args[0].ToUpper() == "CHECK")
                {
                    var tminus1 = new DateUtils().PreviousWorkDay(DateTime.Now.Date);
                    if (args.Length == 2)
                    {
                        tminus1 = DateTime.Parse(args[1]);
                    }

                    CheckData(tminus1);
                }
            }
            catch (Exception ex)
            {
                Utils.Logger.Error("Stopping process with error: {0}", ex.ToString());
            }
            finally
            {
                Utils.Logger.Info("Process end.");
            }
        }