public IndicatorCorrelation(IndicatorWMA wma, IndicatorWMA wmaRef) : base("Cor_" + (wma.Period / 60) + "_" + wmaRef.SignalStock.Id + "_" + wma.SignalStock.Id, new List<MarketData> { wma.SignalStock }) { _wma = wma; _wmaRef = wmaRef; _periodSeconds = wma.Period; _periodMilliSeconds = _periodSeconds * 1000m; if (Config.Settings.ContainsKey("TIME_DECAY_FACTOR")) _timeDecayWeight = decimal.Parse(Config.Settings["TIME_DECAY_FACTOR"]) / 10.0m; }
public IndicatorCorrelation(string id, IndicatorWMA wma, IndicatorWMA wmaRef, int periodMinutes) : base(id, new List<MarketData> { wma.SignalStock }) { _wma = wma; _wmaRef = wmaRef; _periodSeconds = periodMinutes * 60; _periodMilliSeconds = _periodSeconds * 1000m; if (Config.Settings.ContainsKey("TIME_DECAY_FACTOR")) _timeDecayWeight = decimal.Parse(Config.Settings["TIME_DECAY_FACTOR"]) / 10.0m; }
public override void Subscribe(string[] epics, IHandyTableListener tableListener) { Dictionary<string, List<CqlQuote>> priceData = GetReplayData(epics); foreach (var epic in epics) { // for each quote, associate the observed gains in the near future var mktData = new MarketData(epic); var wmaLow = new IndicatorWMA(mktData, 10); var wmaMid = new IndicatorWMA(mktData, 30); var wmaHigh = new IndicatorWMA(mktData, 90); var wmaDailyAvg = new IndicatorLevelMean(mktData); foreach (var quote in priceData[epic]) mktData.TimeSeries.Add(quote.t, new Price(quote.MidPrice())); foreach (var quote in ExpectedIndicatorData[wmaLow.Id]) wmaLow.TimeSeries.Add(quote.t, new Price(quote.ScaleValue(0, 1))); foreach (var quote in ExpectedIndicatorData[wmaLow.Id]) wmaLow.TimeSeries.Add(quote.t, new Price(quote.ScaleValue(0, 1))); var expectations = new Dictionary<DateTime, KeyValuePair<CqlQuote, decimal>>(); var gainDistribution = new SortedList<int, DateTime>(); KeyValuePair<int, DateTime> minProfit = new KeyValuePair<int, DateTime>(1000000, DateTime.MinValue); KeyValuePair<int, DateTime> maxProfit = new KeyValuePair<int, DateTime>(-1000000, DateTime.MinValue); var rnd = new Random(155); var openPrice = priceData[epic][0]; foreach (var quote in priceData[epic]) { if (quote.t.TimeOfDay < Config.ParseDateTimeLocal(Config.Settings["TRADING_START_TIME"]).TimeOfDay) continue; var futureVal = wmaLow.Average(quote.t.AddMinutes(2)); var profit = (int)Math.Round(futureVal.Mid() - quote.MidPrice()); expectations.Add(quote.t, new KeyValuePair<CqlQuote, decimal>(quote, profit)); if (gainDistribution.ContainsKey(profit)) { if ((quote.t - gainDistribution[profit]).Hours > 3 && (rnd.Next(100) == 0)) gainDistribution[profit] = quote.t; } else gainDistribution[profit] = quote.t; if (profit < minProfit.Key) minProfit = new KeyValuePair<int, DateTime>(profit, gainDistribution[profit]); if (profit > maxProfit.Key) maxProfit = new KeyValuePair<int, DateTime>(profit, gainDistribution[profit]); quote.b -= openPrice.MidPrice(); quote.o -= openPrice.MidPrice(); } int nbPoints = 10; int idxProfit = 0; KeyValuePair<int, DateTime> nextProfit = minProfit; var selection = new SortedList<DateTime, KeyValuePair<int, CqlQuote>>(); while (idxProfit++ < nbPoints) { PublisherConnection.Instance.Insert(nextProfit.Value, epic, new Value(nextProfit.Key)); selection.Add(nextProfit.Value, new KeyValuePair<int, CqlQuote>(nextProfit.Key, expectations[nextProfit.Value].Key)); nextProfit = gainDistribution.First(keyVal => keyVal.Key >= ((decimal)minProfit.Key + (decimal)idxProfit * (decimal)(maxProfit.Key - minProfit.Key) / (decimal)nbPoints)); } foreach (var profit in selection) { PublisherConnection.Instance.Insert(gainDistribution[profit.Value.Key], wmaLow, wmaLow.Average(gainDistribution[profit.Value.Key]).Mid() - openPrice.MidPrice()); PublisherConnection.Instance.Insert(gainDistribution[profit.Value.Key], wmaMid, wmaMid.Average(gainDistribution[profit.Value.Key]).Mid() - openPrice.MidPrice()); PublisherConnection.Instance.Insert(gainDistribution[profit.Value.Key], wmaHigh, wmaHigh.Average(gainDistribution[profit.Value.Key]).Mid() - openPrice.MidPrice()); PublisherConnection.Instance.Insert(gainDistribution[profit.Value.Key], wmaDailyAvg, wmaDailyAvg.Average().Mid() - openPrice.MidPrice()); } priceData[epic] = selection.Values.Select(keyVal => keyVal.Value).ToList(); } replay(priceData, tableListener); }