Beispiel #1
0
        public static StockPrices ReadStock(string symbol, string dataColumnName, TimeSeries dayOffsets)
        {
            var prices = new StockPrices(dayOffsets.Count);
            string filePath = DataAccess.GetInstance().GetFilePath(symbol);
            using (var csv = new CsvReader2(filePath))
            {
                while (csv.Read())
                {
                    var date = csv.GetDateTime("Date");
                    int offset = dayOffsets.GetOffsetDaysFromStart(date);
                    if (offset < 0)
                        continue;

                    var price = csv.GetFloat(dataColumnName);
                    prices.Set(offset, price);
                }
            }
            return prices;
        }
        static void Main()
        {
            List<string> symbols;

            const string stocksfile = "SP500port.csv";
            using (var csv = new CsvReader2(stocksfile)) 
            {
                symbols = csv.AsEnumerable().Select(r => r[0]).OrderBy(r => r).ToList();
            }

            var startday = new DateTime(2008, 1, 1);
            var endday = new DateTime(2010, 12, 31);

//            symbols = new List<string>(){"PLD", "SPY"};
//            var startday = new DateTime(2008, 9, 30);
//            var endday = new DateTime(2008, 10, 9);

            var eventMatrix = FindEvents(symbols, startday, endday, marketSymbol: "SPY");

            var eventProfiler = new EventProfiler(eventMatrix, startday, endday, lookbackDays: window, lookforwardDays: window);

            eventProfiler.Study(filename: "MyEventStudy.pdf", plotErrorBars: true, plotMarketNeutral: true,
                plotEvents: false, marketSymbol: "SPY");
        }