public chart Get(string id, string ktype) { var kdata = new kdatadb().kdata(id, ktype); var basic = new Trade.Db.db().basics(id); var since = Trade.Cfg.Configuration.data.bearcrossbull; var k = kdata.Where(p => p.date >= since).ToArray(); var macd = new MACD(kdata.close()).Where(p => p.Date >= since).ToArray(); var macdvol = new MACD(kdata.volume(100)).Where(p => p.Date >= since).ToArray(); var ma5 = new MA(kdata.close(), 5).Range(since); var ma30 = new MA(kdata.close(), 30).Range(since); var ma60 = new MA(kdata.close(), 60).Range(since); var ma120 = new MA(kdata.close(), 120).Range(since); var chg = new CHG(kdata.close()).Range(since); var bottom = new BOTTOM(kdata).Range(since); return(new chart { data = k.Select(p => new object[] { p.date, p.open, p.high, p.low, p.close, chg[p.date] }).ToArray(), volume = k.Select(p => new object[] { p.date, p.volume / 100 }).ToArray(), macd = macd.Select(p => new object[] { p.Date, p.MACD }).ToArray(), dif = macd.Select(p => new object[] { p.Date, p.DIF }).ToArray(), dea = macd.Select(p => new object[] { p.Date, p.DEA }).ToArray(), macdvol = macdvol.Select(p => new object[] { p.Date, p.MACD }).ToArray(), difvol = macdvol.Select(p => new object[] { p.Date, p.DIF }).ToArray(), deavol = macdvol.Select(p => new object[] { p.Date, p.DEA }).ToArray(), ma5 = ma5.Select(p => new object[] { p.Date, p.Value }).ToArray(), ma30 = ma30.Select(p => new object[] { p.Date, p.Value }).ToArray(), ma60 = ma60.Select(p => new object[] { p.Date, p.Value }).ToArray(), ma120 = ma120.Select(p => new object[] { p.Date, p.Value }).ToArray(), code = kdata.Code, name = basic.name, bottom = bottom.Select(p => new object[] { p.Date, p.Value }).ToArray(), keyprices = keyprice(k, id, ktype) }); }
public override void exec() { log.Info("**********START**********"); var cache = new Dictionary <string, kdata>(); var db = new Db.db(); var codes = db.codes(); var i = 0; var count = codes.Count(); var ktypes = new[] { "5", "15", "30", "60", "D", "W", "M" }; foreach (var code in codes.AsParallel()) { Interlocked.Increment(ref i); log.InfoFormat("{0}/{1} calc {2}", i, count, code); foreach (var ktype in ktypes) { try { var kdata = new kdatadb().kdata(code, ktype); if (kdata != null && kdata.Any()) { var date = kdata.Last().date; var close = kdata.close(); var macd = new MACD(close); var macdvol = new MACD(kdata.volume(100)); var ma5 = new MA(close, 5); var ma10 = new MA(close, 10); var ma20 = new MA(close, 20); var ma30 = new MA(close, 30); var ma60 = new MA(close, 60); var ma120 = new MA(close, 120); var chg = new CHG(close); var ka = new kanalytic() { code = code, date = date, ktype = ktype, close = kdata.Last().close.ZeroNaN(), open = kdata.Last().open.ZeroNaN(), high = kdata.Last().high.ZeroNaN(), low = kdata.Last().low.ZeroNaN(), volume = kdata.Last().volume.ZeroNaN(), chg = chg.Last().Value.ZeroNaN(), ma5 = ma5.Last().Value.ZeroNaN(), ma10 = ma10.Last().Value.ZeroNaN(), ma20 = ma20.Last().Value.ZeroNaN(), ma30 = ma30.Last().Value.ZeroNaN(), ma60 = ma60.Last().Value.ZeroNaN(), ma120 = ma120.Last().Value.ZeroNaN(), dea = macd.Last().DEA.ZeroNaN(), macd = macd.Last().MACD.ZeroNaN(), dif = macd.Last().DIF.ZeroNaN(), deavol = macdvol.Last().DEA.ZeroNaN(), macdvol = macdvol.Last().MACD.ZeroNaN(), difvol = macdvol.Last().DIF.ZeroNaN() }; db.save(new[] { ka }); } } catch (Exception e) { log.Warn("ex @ calc " + code + " for " + ktype, e); } } } log.Info("**********DONE**********"); }