Ejemplo n.º 1
0
        public override bool LoadData(string rootFolder, StockSerie stockSerie)
        {
            if (finraSerie == null)
            {
                finraSerie = LoadFINRASerie(rootFolder + FOLDER + "\\FINRA_Bond_Breadth.xml");
            }

            // Convert from StockFINRASerie to StockSerie
            var fields = stockSerie.StockName.Split('.');
            StockDailyValue dailyValue = null;
            switch (fields[0])
            {
                case "BOND_AD":
                    switch (fields[1])
                    {
                        case "ALL":

                            break;
                        case "IG":
                            foreach (var val in finraSerie.InvestGrade)
                            {
                                float open = -1.0f + (float)val.Advances * 2.0f / (float)val.Total;
                                dailyValue = new StockDailyValue(stockSerie.StockName, open, open, open, open, val.Volume, val.Date);
                                stockSerie.Add(val.Date, dailyValue);
                            }
                            break;
                        case "HY":
                            foreach (var val in finraSerie.HighYield)
                            {
                                float open = -1.0f + (float)val.Advances * 2.0f / (float)val.Total;
                                dailyValue = new StockDailyValue(stockSerie.StockName, open, open, open, open, val.Volume, val.Date);
                                stockSerie.Add(val.Date, dailyValue);
                            }
                            break;
                    }
                    break;
                case "McClellan":
                    switch (fields[1])
                    {
                        case "ALL":

                            break;
                        case "IG":
                            {
                                var serie = StockDictionary.StockDictionarySingleton["BOND_AD.IG"];
                                if (!serie.Initialise()) return false;
                                FloatSerie ema19 = serie.GetIndicator("EMA(19)").Series[0];
                                FloatSerie ema39 = serie.GetIndicator("EMA(39)").Series[0];
                                var diff = ema19 - ema39;
                                int i = 0;
                                foreach (var val in serie.Values)
                                {
                                    float open = diff[i++];
                                    dailyValue = new StockDailyValue(stockSerie.StockName, open, open, open, open, val.VOLUME, val.DATE);
                                    stockSerie.Add(val.DATE, dailyValue);
                                }
                            }
                            break;
                        case "HY":
                            {
                                var serie = StockDictionary.StockDictionarySingleton["BOND_AD.HY"];
                                if (!serie.Initialise()) return false;
                                FloatSerie ema19 = serie.GetIndicator("EMA(19)").Series[0];
                                FloatSerie ema39 = serie.GetIndicator("EMA(39)").Series[0];
                                var diff = ema19 - ema39;
                                int i = 0;
                                foreach (var val in serie.Values)
                                {
                                    float open = diff[i++];
                                    dailyValue = new StockDailyValue(stockSerie.StockName, open, open, open, open, val.VOLUME, val.DATE);
                                    stockSerie.Add(val.DATE, dailyValue);
                                }
                            }
                            break;
                    }
                    break;
            }

            return true;
        }
Ejemplo n.º 2
0
        public override void InitDictionary(string rootFolder, StockDictionary stockDictionary, bool download)
        {
            // Create data folder if not existing
            if (!Directory.Exists(rootFolder + FOLDER))
            {
                Directory.CreateDirectory(rootFolder + FOLDER);
            }
            string[] names = new string[] { "BOND_AD.ALL", "BOND_AD.HY", "BOND_AD.IG", "McClellan.HY", "McClellan.IG" };
            StockSerie stockSerie = null;

            if (finraSerie == null)
            {
                finraSerie = LoadFINRASerie(rootFolder + FOLDER + "\\FINRA_Bond_Breadth.xml");
            }

            foreach (string name in names)
            {
                if (!stockDictionary.ContainsKey(name))
                {
                    stockSerie = new StockSerie(name, name, StockSerie.Groups.BREADTH, StockDataProvider.FINRA);
                    stockDictionary.Add(name, stockSerie);
                }
            }
            if (download)
            {
                this.DownloadDailyData(rootFolder);
            }
        }