private void CacheData(string key, MarketPrices data) { var policy = new CacheItemPolicy(); cache.Set(key, data, policy); //var stringWriter = new StringWriter(); //data.WriteXml(stringWriter); //diskCache[key] = stringWriter.ToString(); }
private static MarketPrices For(IEnumerable<string> symbols, string dataColumnName, TimeSeries timeSeries) { var r = new MarketPrices(); Console.WriteLine("Reading market data..."); Stopwatch stopwatch = Stopwatch.StartNew(); foreach (string symbol in symbols) r.ReadStock(dataColumnName, symbol, timeSeries); stopwatch.Stop(); Console.WriteLine(" Elapsed time: " + stopwatch.Elapsed); return r; }
public EventProfiler(ConcurrentDictionary<string, IList<int>> eventMatrix, DateTime startDay, DateTime endDay, int lookbackDays, int lookforwardDays) { this.eventMatrix = eventMatrix; // this.startDay = startDay; // this.endDay = endDay; this.lookbackDays = lookbackDays; this.lookforwardDays = lookforwardDays; symbols = eventMatrix.Keys.ToList(); totalGraphDays = lookbackDays + lookforwardDays + 1; var dataObj = DataAccess.GetInstance(); var timeOfDay = TimeSpan.FromHours(16); var timestamps = Nyse.GetTradingDates(startDay, endDay, timeOfDay); List<DateTime> timestamps1 = timestamps.ToList(); close = dataObj.GetMarketData(symbols, "Close", new TimeSeries(timestamps1)); marketDays = timestamps1.Count(); close.ReplaceNanFill(FillDirection.Forward).ReplaceNanFill(FillDirection.Backward); dailyReturns = new Dictionary<string, IList<float>>(); marketNeutralDm = new Dictionary<string, IList<float>>(); }
private static ConcurrentDictionary<string, IList<float>> MarketRelativeReturns(MarketPrices close, IList<float> spyValues) { var marketNeutralDailyMovement = new ConcurrentDictionary<string, IList<float>>(); Parallel.ForEach(close.Symbols, (symbol, loopState) => { var priceList = close.ColumnList(symbol); if (priceList == null) loopState.Break(); else { IList<float> dailyReturns = priceList.Returnize(); IList<float> marketRelative = dailyReturns.Select((d, i) => (float)(d - spyValues[i])).ToList(); marketNeutralDailyMovement[symbol] = marketRelative; } }); return marketNeutralDailyMovement; }
private static void DetectEvents(MarketPrices close, int marketDays, IList<float> spyValues, IDictionary<string, IList<float>> marketNeutralDM, IDictionary<string, IList<int>> eventMatrix, List<DateTime> timestamps) { Parallel.ForEach(close.Symbols, symbol => { foreach (int i in Enumerable.Range(0, marketDays)) { DetectEvent(spyValues, marketNeutralDM, eventMatrix, timestamps, i, symbol); } }); }