Dictionary <String, String> IStrategy.select(DataStoreHelper dsh, SelectMode selectMode, ref String sigInfo) { var zf = dsh.Ref(Info.ZF); if (zf > 0 || zf < -0.06) { return(null); } if (dsh.Ref(Info.OF, 1) < -0.03) { return(null); } if (dsh.Ref(Info.ZF, 1) > 0) { return(null); } int iSigDateIndex = -1; int nUpCount = 0; int nUStopCount = 0; int nDStopCount = 0; bool bMeetRealUp = false; bool bHasUpShadowTooHight = false; bool bHasDownShadowTooLow = false; float otherMaxVol = float.MinValue; float otherMaxZF = float.MinValue; float otherMaxC = 0; float otherMaxH = 0; float sigDateVol = 0; float sigZF = 0; float minDownShadow = float.MaxValue; float maxUpShadow = float.MinValue; float totalUp = 0; float totalDown = 0; float otherMinZF = float.MaxValue; float otherMaxCO = float.MinValue; bool bMeetTradeSigAllready = false; int nNotRealCount = 0; for (int i = 1; i < 8; ++i) { var curOf = dsh.Ref(Info.OF, i); var curHf = dsh.Ref(Info.HF, i); var curLf = dsh.Ref(Info.LF, i); var curZf = dsh.Ref(Info.ZF, i); var curPreZf = dsh.Ref(Info.ZF, i + 1); var vol = dsh.Ref(Info.V, i); var coRate = dsh.Ref(Info.CO, i) / dsh.Ref(Info.C, i + 1); if (curZf > 0 && curZf < 0.095 && coRate > 0.05 && vol > dsh.MA(Info.V, 5, i + 1) && dsh.HH(Info.CO, 30, i) == i) { for (int j = i + 1; j < i + 6; ++j) { if (dsh.Ref(Info.V, j) > vol && dsh.Ref(Info.C, j) < dsh.Ref(Info.O, j)) { return(null); } } if (dsh.AccZF(8, i + 1) < -0.1) { return(null); } if (dsh.AccZF(3, i + 1) > 0.095) { return(null); } int iMaxVolIndex = dsh.HH(Info.V, 20, i); if (dsh.Ref(Info.C, iMaxVolIndex) > dsh.Ref(Info.O, iMaxVolIndex)) { iSigDateIndex = i; sigDateVol = vol; sigZF = curZf; break; } } if (curOf < -0.04) { return(null); } if (curZf > 0 && dsh.IsReal(i)) { nUpCount++; } if (!dsh.IsReal(i)) { ++nNotRealCount; } if (curZf > 0.095) { nUStopCount++; } else if (curZf < -0.095) { nDStopCount++; } else if (curZf > 0.012) { bMeetRealUp = true; } if (curZf < -0.03 && dsh.Ref(Info.ZF, i - 1) > 0) { bMeetTradeSigAllready = true; } float upShadow = dsh.UpShadow(i); float downShadow = dsh.DownShadow(i); if (upShadow > maxUpShadow) { maxUpShadow = upShadow; } if (downShadow < minDownShadow) { minDownShadow = downShadow; } if (curZf > 0) { totalUp += curZf; } else { totalDown += curZf; } otherMaxVol = Math.Max(vol, otherMaxVol); otherMaxZF = Math.Max(otherMaxZF, curZf); otherMaxC = Math.Max(dsh.Ref(Info.C, i), otherMaxC); otherMaxH = Math.Max(dsh.Ref(Info.H, i), otherMaxH); otherMinZF = Math.Min(otherMinZF, curZf); otherMaxCO = Math.Max(otherMaxCO, dsh.Ref(Info.CO, i)); } if (iSigDateIndex == -1) { return(null); } sigInfo = dsh.Date(iSigDateIndex).ToString(); if (otherMinZF > 0.02) { return(null); } if (nNotRealCount > 1) { return(null); } if (totalDown + totalUp < -0.01) { return(null); } if (maxUpShadow > 0.03) { bHasUpShadowTooHight = true; } if (minDownShadow < -0.03) { bHasDownShadowTooLow = true; } if (nUpCount < 2) { return(null); } if (otherMaxH < dsh.Ref(Info.H, iSigDateIndex)) { return(null); } if (/*nUStopCount > 0 ||*//* nDStopCount > 0 || */ bMeetTradeSigAllready || !bMeetRealUp) { return(null); } float maxUpF = (otherMaxC - dsh.Ref(Info.C, iSigDateIndex)) / dsh.Ref(Info.C, iSigDateIndex); if (maxUpF < 0.015 /* || maxUpF > 0.04*/) { return(null); } if (dsh.Ref(Info.C) < dsh.Ref(Info.L, iSigDateIndex)) { return(null); } if (bHasUpShadowTooHight || bHasDownShadowTooLow) { return(null); } if ( dsh.Ref(Info.ZF, 2) < 0.005 && dsh.Ref(Info.ZF, 3) < 0.005) { return(null); } if (sigDateVol < otherMaxVol * 1.2) { return(null); } if (sigDateVol > otherMaxVol * 2) { return(null); } if (otherMaxZF + zf > 0) { return(null); } if (otherMaxZF + zf < -0.02) { return(null); } if (dsh.Ref(Info.LF) < -0.06) { return(null); } var delta = (dsh.Ref(Info.C) - dsh.Ref(Info.O, 1)) / dsh.Ref(Info.C, 1); if (delta > -0.01) { return(null); } if (!selectBySZ(dsh)) { return(null); } var ret = new Dictionary <String, String>(); ret[String.Format("delta/{0}", delta < -0.02 ? "1" : "0")] = ""; ret[String.Format("maxUp/{0}", maxUpF > 0.02 ? "1" : "0")] = ""; return(ret); }
public String computeBonus(SelectItem item, Stock stock, int buyDate, out BuySellInfo info) { info = new BuySellInfo(); if (item.buyNormlizePrice_ == 0) { return(""); } IStrategy_LF_M stra = (IStrategy_LF_M)this; DataStoreHelper dsh = new DataStoreHelper(); dsh.setStock(stock); dsh.iIndex_ = App.ds_.index(stock, buyDate); float buyC = item.buyNormlizePrice_; float firstDayBonusL = firstDayBonusLimit(); float bonusL = bonusLimit(); float bL = dsh.iIndex_ > 1 ? bonusL : firstDayBonusL; if (dsh.iIndex_ == 0) { var bonus = Utils.DeltaF(dsh.Ref(Info.C) - buyC, dsh.Ref(Info.C)); info.sellDate_ = buyDate; info.tradeSpan_ = 0; info.allBonus_ = Utils.ToBonus(bonus - 0.002f); return(info.allBonus_); } else { --dsh.iIndex_; int nBuySpan = 0; int nBuySpanLimit = buySpan(); float sellC = 0; for (; dsh.iIndex_ >= 0; --dsh.iIndex_, ++nBuySpan) { float o = dsh.Ref(Info.O); float h = dsh.Ref(Info.H); float c = dsh.Ref(Info.C); float of = dsh.Ref(Info.OF); float hf = dsh.Ref(Info.HF); float lf = dsh.Ref(Info.LF); float zf = dsh.Ref(Info.ZF); var limit = nBuySpan == 0 ? firstDayBonusL : bonusL; float wantedC = buyC * (1 + limit); float wantedMinC = buyC * (1 + bonusL); // // if (lf < -0.111 || hf > 0.111) // {//除权了 // return ""; // } if (Utils.IsDownStop(hf))//一直跌停 { info.bSellWhenMeetMyBounusLimit_ = false; continue; } //今天没一直跌停,大概率能卖出 if (info.bSellWhenMeetMyBounusLimit_) { if (o > wantedC)//开盘超出盈利顶额 { sellC = o; ++nBuySpan; break; } if (h > wantedC)//达到盈利顶额 { sellC = wantedC; ++nBuySpan; break; } if (Utils.IsDownStop(zf))//尾盘跌停,卖不了 { info.bSellWhenMeetMyBounusLimit_ = false; continue; } sellC = c; if (zf >= 0.01 || h >= wantedMinC || nBuySpan >= nBuySpanLimit - 1) { ++nBuySpan; break; } } else //逃命模式 { if (!Utils.IsDownStop(of)) //开盘没跌停 { //跑了 sellC = o; ++nBuySpan; break; } //开盘跌停但因为没一直跌停,所以肯定可以以跌停价卖出 sellC = dsh.Ref(Info.C, 1) * (1 - 0.095f); ++nBuySpan; break; } } if (dsh.iIndex_ == -1) { return(""); } info.sellDate_ = dsh.Date(); info.tradeSpan_ = nBuySpan; var bonus = (sellC - buyC) / buyC; info.allBonus_ = Utils.ToBonus(bonus - 0.002f); return(info.allBonus_); } }
Dictionary <String, String> IStrategy.select(DataStoreHelper dsh, SelectMode selectMode, ref String sigInfo) { IStrategy_LF stra = (IStrategy_LF)this; if (!meetBuyChance(dsh, selectMode)) { return(null); } if (dsh.Ref(Info.OF) > 0.04 || dsh.Ref(Info.OF) < -0.015 || dsh.Ref(Info.ZF, 1) < -0.02 || dsh.Ref(Info.OF, 1) < -0.03) { return(null); } if (dsh.Ref(Info.CO, 1) / dsh.Ref(Info.C, 1) < 0.01) { return(null); } int iSigDateIndex = -1; int nUpCount = 0; int nUStopCount = 0; int nDStopCount = 0; bool bMeetTradeSigAllready = false; bool bMeetRealUp = false; float sigDateVol = 0; float otherMaxVol = 0; bool bHasUpShadowTooHight = false; bool bHasDownShadowTooLow = false; float otherMaxZF = 0; float otherMaxC = 0; float otherMaxH = 0; float sumOfSigDateZF = 0; for (int i = 1; i < 8; ++i) { var curOf = dsh.Ref(Info.OF, i); var curHf = dsh.Ref(Info.HF, i); var curZf = dsh.Ref(Info.ZF, i); var curPreZf = dsh.Ref(Info.ZF, i + 1); var vol = dsh.Ref(Info.V, i); if (curOf < 0.03 && curZf > 0.03 && curZf < 0.095 && dsh.Ref(Info.OF, i + 1) < 0.03 && dsh.Ref(Info.ZF, i + 1) > 0.03) { for (int j = i + 2; j < i + 5; j++) { if (dsh.Ref(Info.ZF, j) < 0) { break; } if (dsh.Ref(Info.ZF, j) > 0.05) { return(null); } } bool bHasDown = false; for (int j = i + 2; j < i + 7; j++) { if (dsh.Ref(Info.ZF, j) < 0) { bHasDown = true; break; } } if (dsh.AccZF(8, i + 2) < -0.15) { return(null); } float preVol = dsh.Ref(Info.V, i + 1); float chkVol = Math.Max(vol, preVol); for (int j = i + 2; j < i + 6; ++j) { if (dsh.Ref(Info.V, j) > chkVol * 2) { return(null); } } if (!bHasDown) { return(null); } sumOfSigDateZF = curZf + dsh.Ref(Info.ZF, i + 1); if (sumOfSigDateZF > 0.1) { iSigDateIndex = i; sigDateVol = Math.Max(dsh.Ref(Info.V, i + 1), vol); break; } } otherMaxVol = Math.Max(vol, otherMaxVol); if (curZf > 0 && dsh.IsReal(i)) { nUpCount++; } if (curZf > 0.095) { nUStopCount++; } else if (curZf < -0.095) { nDStopCount++; } if (curZf < -0.03) { bMeetTradeSigAllready = true; } else if (curZf > 0.012) { bMeetRealUp = true; } if (dsh.UpShadow(i) > 0.03) { bHasUpShadowTooHight = true; } if (dsh.DownShadow(i) < -0.03) { bHasDownShadowTooLow = true; } otherMaxZF = Math.Max(otherMaxZF, curZf); otherMaxC = Math.Max(dsh.Ref(Info.C, i), otherMaxC); otherMaxH = Math.Max(dsh.Ref(Info.H, i), otherMaxH); } if (iSigDateIndex == -1) { return(null); } sigInfo = dsh.Date(iSigDateIndex).ToString(); int iMaxCOIndex = dsh.HH(Info.CO, 30, 1); if (dsh.Ref(Info.ZF, iMaxCOIndex) < 0) { return(null); } if (nUpCount < 2) { return(null); } if (dsh.Ref(Info.C, 1) * (1 + stra.buyLimit() - 0.01) < dsh.Ref(Info.L, iSigDateIndex)) { return(null); } if (/*nUStopCount > 0 ||*//* nDStopCount > 0 || */ bMeetTradeSigAllready || !bMeetRealUp) { return(null); } if (sigDateVol > otherMaxVol * 2) { return(null); } float maxUpF = (otherMaxC - dsh.Ref(Info.C, iSigDateIndex)) / dsh.Ref(Info.C, iSigDateIndex); if (maxUpF < 0.015 /* || maxUpF > 0.04*/) { return(null); } if (sigDateVol < otherMaxVol * 1.2) { return(null); } if (bHasUpShadowTooHight || bHasDownShadowTooLow) { return(null); } if ( dsh.Ref(Info.ZF, 2) < 0.005 && dsh.Ref(Info.ZF, 3) < 0.005) { return(null); } if (Math.Min(dsh.Ref(Info.ZF, iSigDateIndex), dsh.Ref(Info.ZF, iSigDateIndex + 1)) + dsh.Ref(Info.ZF, iSigDateIndex + 2) < -0.01) { return(null); } if (dsh.Ref(Info.C, iSigDateIndex) < dsh.Ref(Info.O, iSigDateIndex)) { return(null); } if (dsh.Ref(Info.C, iSigDateIndex + 1) < dsh.Ref(Info.O, iSigDateIndex + 1)) { return(null); } return(EmptyRateItemButSel); // var delta = (dsh.Ref(Info.C) - dsh.Ref(Info.O, 1)) / dsh.Ref(Info.C, 1); // if (delta > -0.01) // { // return null; // } // var ret = new Dictionary<String, String>(); // ret[String.Format("sumSig/{0}", sumOfSigDateZF>0.12 ? "1": "0")] = ""; // ret[String.Format("delta/{0}", delta < -0.02 ? "1" : "0")] = ""; // ret[String.Format("maxUp/{0}", maxUpF > 0.02 ? "1" : "0")] = ""; // ret[String.Format("diffzf/{0}", otherMaxZF + zf > -0.02 ? "1" : "0")] = ""; // return ret; }
Dictionary <String, String> IStrategy.select(DataStoreHelper dsh, SelectMode selectMode, ref String sigInfo) { IStrategy stra = (IStrategy)this; var zf = dsh.Ref(Info.ZF); if (zf > 0.095 || zf < -0.095) { return(null); } if (dsh.birthCount() > 50) { return(null); } int iOpenUpStopIndex = -1; int nDayCount = 0; for (int i = dsh.dataList_.Count - 2; i > 0; --i) { if (dsh.ds_.Ref(Info.ZF, dsh.dataList_, i) < 0.095) { iOpenUpStopIndex = i - dsh.iIndex_; break; } ++nDayCount; } if (nDayCount < 3) { return(null); } if (iOpenUpStopIndex == -1) { return(null); } int iTopMostIndex = -1; iTopMostIndex = iOpenUpStopIndex + 1; float topMostSimpleC = Math.Max(dsh.Ref(Info.O, iTopMostIndex), dsh.Ref(Info.C, iTopMostIndex)); int iSerarchBeginIndex = -1; for (int i = iOpenUpStopIndex; i > 0; --i) { float curTop = Math.Max(dsh.Ref(Info.O, i), dsh.Ref(Info.C, i)); if (curTop > topMostSimpleC) { topMostSimpleC = curTop; iTopMostIndex = i; } if ( (dsh.Ref(Info.C, i) < dsh.Ref(Info.O, i)) && dsh.MaxCO(i) > dsh.MaxCO(i - 1)) { iSerarchBeginIndex = i; break; } } if (iTopMostIndex == -1 || iSerarchBeginIndex == -1) { return(null); } for (int i = 3; i >= 1; --i) { bool bContinue = true; if (dsh.Ref(Info.ZF, iTopMostIndex - i) > 0.095) { for (int j = iTopMostIndex - i; j > 0; --j) { if (dsh.Ref(Info.ZF, j) < 0) { bContinue = false; break; } float curTop = Math.Max(dsh.Ref(Info.O, j), dsh.Ref(Info.C, j)); if (curTop > topMostSimpleC) { topMostSimpleC = curTop; iTopMostIndex = iTopMostIndex - i; } } } if (!bContinue) { break; } } int iSearchIndex2 = iSerarchBeginIndex; float topMostC = topMostSimpleC; sigInfo = dsh.Date(iTopMostIndex).ToString(); int iStruggleUpIndex = -1; float maxUpZF = float.MinValue; for (int i = iSearchIndex2; i >= 0; --i) { if (iStruggleUpIndex == -1) { if (dsh.Ref(Info.C, i + 2) < topMostC && (dsh.Ref(Info.C, i + 1) - topMostC) / topMostC > 0) { iStruggleUpIndex = i; } } float curZF = (dsh.Ref(Info.C, i) - topMostC) / topMostC; maxUpZF = Math.Max(curZF, maxUpZF); } if (iStruggleUpIndex == -1) { return(null); } return(selectForHStrugle(dsh, topMostC, maxUpZF)); }
Dictionary <String, String> IStrategy.select(DataStoreHelper dsh, SelectMode selectMode, ref String sigInfo) { IStrategy_LF stra = (IStrategy_LF)this; if (!meetBuyChance(dsh, selectMode)) { return(null); } if (dsh.Ref(Info.OF) > 0.04 || dsh.Ref(Info.OF) < -0.015 || dsh.Ref(Info.ZF, 1) < -0.02 || dsh.Ref(Info.OF, 1) < -0.03) { return(null); } if (dsh.Ref(Info.CO, 1) / dsh.Ref(Info.C, 1) < 0.01) { return(null); } int iSigDateIndex = -1; int nUpCount = 0; int nDownCount = 0; int nUStopCount = 0; int nDStopCount = 0; bool bMeetTradeSigAllready = false; bool bMeetRealUp = false; bool bHasUpShadowTooHight = false; bool bHasDownShadowTooLow = false; float otherMaxVol = float.MinValue; float otherMaxC = float.MinValue; float otherMaxH = float.MinValue; float otherMaxZF = float.MinValue; float sigDateVol = 0; float sigZF = 0; float minDownShadow = float.MaxValue; float maxUpShadow = float.MinValue; float otherMinZF = float.MaxValue; float totalUp = 0; float totalDown = 0; for (int i = 1; i < 8; ++i) { var curOf = dsh.Ref(Info.OF, i); var curHf = dsh.Ref(Info.HF, i); var curZf = dsh.Ref(Info.ZF, i); var curPreZf = dsh.Ref(Info.ZF, i + 1); var vol = dsh.Ref(Info.V, i); if (curZf > 0.095) { return(null); } if (curOf < 0.04 && curHf > 0.095 && curZf < 0.095 && curZf > 0) { iSigDateIndex = i; sigDateVol = vol; sigZF = curZf; for (int j = i + 1; j < i + 5; ++j) { if (dsh.Ref(Info.V, j) > vol * 2) { return(null); } } if (dsh.AccZF(8, i + 1) < -0.15) { return(null); } if (dsh.AccZF(3, i + 1) > 0.095) { return(null); } break; } if (curOf < -0.04) { return(null); } if (curZf > 0 && dsh.IsReal(i)) { nUpCount++; } if (curZf < 0 && dsh.IsReal(i)) { nDownCount++; } if (curZf > 0.095) { nUStopCount++; } else if (curZf < -0.095) { nDStopCount++; } if (curZf < -0.03) { bMeetTradeSigAllready = true; } else if (curZf > 0.012) { bMeetRealUp = true; } float upShadow = dsh.UpShadow(i); float downShadow = dsh.DownShadow(i); if (upShadow > maxUpShadow) { maxUpShadow = upShadow; } if (downShadow < minDownShadow) { minDownShadow = downShadow; } if (curZf > 0) { totalUp += curZf; } else { totalDown += curZf; } otherMaxVol = Math.Max(vol, otherMaxVol); otherMaxC = Math.Max(dsh.Ref(Info.C, i), otherMaxC); otherMaxH = Math.Max(dsh.Ref(Info.H, i), otherMaxH); otherMaxZF = Math.Max(otherMaxZF, curZf); otherMinZF = Math.Min(otherMinZF, curZf); } if (iSigDateIndex == -1) { return(null); } sigInfo = dsh.Date(iSigDateIndex).ToString(); if (dsh.Ref(Info.ZF, iSigDateIndex) + dsh.Ref(Info.ZF, iSigDateIndex + 1) < -0.01) { return(null); } if (sigDateVol > otherMaxVol * 2) { return(null); } if (otherMinZF > 0.03) { return(null); } if (totalDown + totalUp < -0.01) { return(null); } if (otherMaxH < dsh.Ref(Info.H, iSigDateIndex)) { return(null); } if (dsh.Ref(Info.C, 1) * (1 + stra.buyLimit() - 0.01) < dsh.Ref(Info.L, iSigDateIndex)) { return(null); } if (maxUpShadow > 0.03) { bHasUpShadowTooHight = true; } if (minDownShadow < -0.03) { bHasDownShadowTooLow = true; } if (nUpCount < 2) { return(null); } if (/*nUStopCount > 0 ||*//* nDStopCount > 0 || */ bMeetTradeSigAllready || !bMeetRealUp) { return(null); } float maxUpF = (otherMaxC - dsh.Ref(Info.C, iSigDateIndex)) / dsh.Ref(Info.C, iSigDateIndex); if (maxUpF < 0.02 /* || maxUpF > 0.04*/) { return(null); } // if (sigDateVol < otherMaxVol * 1.2) // { // return null; // } // if (dsh.Ref(Info.LF) < -0.06) // { // return null; // } if (bHasUpShadowTooHight || bHasDownShadowTooLow) { return(null); } // if (dsh.Ref(Info.OF) < -0.02) // { // return null; // } if ( dsh.Ref(Info.ZF, 2) < 0.005 && dsh.Ref(Info.ZF, 3) < 0.005) { return(null); } if (dsh.Ref(Info.ZF, iSigDateIndex - 1) < 0 && dsh.IsReal(iSigDateIndex - 1) && dsh.Ref(Info.H, iSigDateIndex - 1) > dsh.Ref(Info.H, iSigDateIndex)) { return(null); } // if (dsh.Ref(Info.ZF, iSigDateIndex-1) < 0 && // dsh.Ref(Info.ZF, iSigDateIndex - 2) < 0) // { // return null; // } if (dsh.Ref(Info.C, iSigDateIndex) < dsh.Ref(Info.O, iSigDateIndex)) { return(null); } var delta = (dsh.Ref(Info.C, 1) * (1 + stra.buyLimit() + 0.01) - dsh.Ref(Info.O, 1)) / dsh.Ref(Info.C, 1); if (delta > -0.01) { return(null); } var ret = new Dictionary <String, String>(); ret[String.Format("vol/{0}", sigDateVol < otherMaxVol * 1.5 ? "1" : "0")] = ""; // ret[String.Format("maxUp/{0}", maxUpF > 0.03 ? "1" : "0")] = ""; return(ret); }