public override List <ChanceClass> getChances(BaseCollection sc, ExpectData ed) { List <ChanceClass> ret = new List <ChanceClass>(); ExpectList el = sc.orgData; List <ChanceClass> scs = new List <ChanceClass>(); strag_CommOldClass coc = new strag_CommOldClass(); coc.CommSetting = this.CommSetting; coc.ChipCount = this.ChipCount; coc.FixChipCnt = true; //coc.AllowMaxHoldTimeCnt = this.AllowMaxHoldTimeCnt; coc.BySer = this.BySer; //coc.ReviewExpectCnt = ; coc.InputMinTimes = this.InputMinTimes; coc.StagSetting = new StagConfigSetting(); if (!this.IsTracing)//未持仓时才计算过往概率 { double sucrate = double.NaN; if (this.CommSetting.UseLocalWaveData)//如果使用本地数据,获取该期本地数据 { sucrate = this.LocalWaveData[el.LastData.Expect]; } if (double.IsNaN(sucrate)) //如果数据异常,继续去寻找 { sucrate = getSucRate(el, coc, true); //该类策略全部是一次性机会,可反复下注 } if (this.RateDic == null) { this.RateDic = new Dictionary <string, double>(); } if (!this.RateDic.ContainsKey(this.LastUseData().LastData.Expect))//加入胜率队列 { RateDic.Add(this.LastUseData().LastData.Expect, sucrate); } if (!this.CheckEnableIn()) { return(ret); } this.IsTracing = true;//满足条件,开始持仓 //this.debug_maxRate = 0; } BaseCollection scc = new ExpectListProcess(el).getSerialData(InputMinTimes, BySer) as BaseCollection; ret = coc.getChances(scc, el.LastData); for (int i = 0; i < ret.Count; i++) { ret[i].NeedConditionEnd = true; ret[i].OnCheckTheChance += CheckNeedEndTheChance; } return(ret); }
public override bool CheckNeedEndTheChance(ChanceClass cc, bool LastExpectMatched) { if (LastExpectMatched) { return(true); } if (this.IsTracing == false) //如果策略不持仓,无论是否命中,所有后续机会均关闭 { return(true); } strag_CommOldClass coc = new strag_CommOldClass(); coc.CommSetting = this.CommSetting; coc.ChipCount = this.ChipCount; coc.FixChipCnt = true; ////coc.AllowMaxHoldTimeCnt = this.AllowMaxHoldTimeCnt; coc.BySer = this.BySer; //coc.ReviewExpectCnt = ; coc.InputMinTimes = this.InputMinTimes; coc.StagSetting = new StagConfigSetting(); double sucrate = double.NaN; if (this.CommSetting.UseLocalWaveData)//如果使用本地数据,获取该期本地数据 { sucrate = this.LocalWaveData[this.LastUseData().LastData.Expect]; } if (sucrate == double.NaN)//如果数据异常,继续去寻找 { sucrate = 100 * getSucRate(this.LastUseData(), coc, cc.AllowMaxHoldTimeCnt == 1 ? true : false); } if (!this.RateDic.ContainsKey(this.LastUseData().LastData.Expect)) { RateDic.Add(this.LastUseData().LastData.Expect, sucrate); } if (this.CheckEnableOut()) { return(true); } return(false); }
public override List <ChanceClass> getChances(BaseCollection sc, ExpectData ed) { List <ChanceClass> ret = new List <ChanceClass>(); if (sc == null || sc.Table == null || sc.Table.Rows.Count < this.ReviewExpectCnt) { return(ret); } if (this.getAllStdDev() == null) { this.setAllStdDev(new Dictionary <string, List <double> >()); } double stdval = 0; List <double> list = sc.getAllDistrStdDev(this.ReviewExpectCnt, this.InputMaxTimes); if (!this.getAllStdDev().ContainsKey(ed.Expect)) { stdval = list[10];//最后一位 this.getAllStdDev().Add(ed.Expect, list); } if (getAllStdDev().Count < 20) { return(ret); } MA_del ma20 = new MA_del(getAllStdDev().Values.Select(p => p[10]).ToArray(), 20); MA_del ma5 = new MA_del(getAllStdDev().Values.Select(p => p[10]).ToArray(), 5); if (!IsTracing) { //if (stdval > 0.2) return ret; if (ma20.IsDownCross())//下穿均线,开始跟踪 { IsTracing = true; } else { return(ret); } } else { ////if (stdval > 0.2) ////{ //// IsTracing = false; //// return ret; ////} if (ma5.IsUpCross())//上穿均线,停止跟踪 { IsTracing = false; return(ret); } } strag_CommOldClass strag = new strag_CommOldClass(); strag.BySer = this.BySer; strag.ChipCount = this.ChipCount; strag.InputMinTimes = this.InputMinTimes; List <ChanceClass> tmp = strag.getChances(sc, ed); Dictionary <string, double> dic = new Dictionary <string, double>(); for (int i = 0; i < 10; i++) { if (list[i] < stdval)//小于整体的才有效 { string strcol = string.Format("{0}", (i + 1) % 10); dic.Add(strcol, list[i]); } } for (int i = 0; i < tmp.Count; i++) { if (dic.ContainsKey(tmp[i].GetCodeKey(this.BySer))) { ret.Add(tmp[i]); } } return(ret); }
double getSucRate(ExpectList el, strag_CommOldClass coc, bool OnlyOnceChance) { Dictionary <string, ChanceClass> NoEndChances = new Dictionary <string, ChanceClass>(); Dictionary <string, ChanceClass> TmpChances = new Dictionary <string, ChanceClass>(); int MatchTimes = 0; int AllTimes = 0; for (int i = this.InputMaxTimes; i < el.Count; i++)//因为最后一次数据如果下注就不知道结果,所以最后一次排除下注,只做验证上次结果用 { ExpectList useList = el.getSubArray(i - this.InputMinTimes, this.InputMinTimes); ExpectData CurrData = useList.LastData; TmpChances = new Dictionary <string, ChanceClass>(); foreach (string key in NoEndChances.Keys) { ChanceClass cc = NoEndChances[key]; int MatchCnt = 0; bool Matched = cc.Matched(CurrData, out MatchCnt, false); if (Matched) { if (OnlyOnceChance)//如果是一次性机会 { if (cc.HoldTimeCnt == 1) { MatchTimes++; continue; } } else { MatchTimes++; } } else { if (!TmpChances.ContainsKey(key)) { cc.HoldTimeCnt++; cc.Closed = false; TmpChances.Add(key, cc); if (!OnlyOnceChance)//如果不是一次性机会,每次机会都加1 { AllTimes++; } } } } if (i == el.Count - 1) { break;//最后一期不找机会 } NoEndChances = new Dictionary <string, ChanceClass>(); foreach (string key in TmpChances.Keys)//遗留机会 { NoEndChances.Add(key, TmpChances[key]); } BaseCollection scc = new ExpectListProcess(useList).getSerialData(InputMinTimes, BySer) as BaseCollection; List <ChanceClass> ccs = coc.getChances(scc, CurrData); for (int j = 0; j < ccs.Count; j++)//新增机会 { if (!NoEndChances.ContainsKey(ccs[j].ChanceCode)) { NoEndChances.Add(ccs[j].ChanceCode, ccs[j]); AllTimes++; } } } return((double)100 * MatchTimes / AllTimes); }