private void CheckupContinuity(ref ChartPointsPredition CPsP, int position) { CPsP.Continuity = 0; int iSeconds = (ABBREVIATIONS.ToMinutes(CPsP.TimeFrame) * 60); for (int i = position - 1; i >= 0; i--) { ChartPointsPredition CPsPPrevious = DATA[CPsP.Product][i]; if (CPsPPrevious.Type == ChartPointsPredition.Kind.Uncertain) { break; } double dSecondsDifference = (CPsP.DTOriginal - CPsPPrevious.DTOriginal).TotalSeconds; double dSecondsDifferenceAllowed = (iSeconds * (position - i)) + 6; if (dSecondsDifference > dSecondsDifferenceAllowed) { break; } else { ++CPsP.Continuity; } if (CPsP.Continuity >= CPsP.Deep) { break; } } }
public double SampleStandardDeviationGainStreak(List <ChartPoint> LCPoints, TimeFrame TFrame) { int iTimeShift = ABBREVIATIONS.ToMinutes(TFrame); double dAverangePeak = this.AverageGainStreak(LCPoints, TFrame); double dMeanSquareSum = 0; int counter = 0; int antyCounter = 0; for (int i = 0; i < LCPoints.Count - 1; i++) { if (LCPoints[i].Time.AddMinutes(iTimeShift) == LCPoints[i + 1].Time) { ++counter; } else if (counter != 0) { dMeanSquareSum += Math.Pow(counter - dAverangePeak, 2); counter = 0; ++antyCounter; } else { dMeanSquareSum += Math.Pow(counter - dAverangePeak, 2); ++antyCounter; } ++i; } return(Math.Pow(dMeanSquareSum / (antyCounter - 1), 0.5)); }
private int PositionShift(string pPrimary, string pSecondary, int position) { double dMinutes = (DATA[pPrimary][position].DTOriginal - DATA[pSecondary][position].DTOriginal).TotalMinutes; int iShiftMinutes = (int)(dMinutes / ABBREVIATIONS.ToMinutes(DATA[pPrimary][position].TimeFrame)); return(iShiftMinutes); }
public List <ChartPointsPredition> ExtractTestContinuous(List <ChartPointsPredition> LCPsPAll) { List <ChartPointsPredition> LCPsPExtracted = new List <ChartPointsPredition>(); int iDeepMax = 1; for (int i = iDeepMax + 1; i < LCPsPAll.Count; i++) { int iDeep = -1; bool bPass = true; while (++iDeep < iDeepMax && bPass != false) { ChartPointsPredition CPsPPrevious = LCPsPAll[i - 1 - iDeep]; ChartPointsPredition CPsPNow = LCPsPAll[i - iDeep]; double dTimeSpread = (CPsPNow.DTOriginal - CPsPPrevious.DTOriginal).TotalMinutes; int iTFMinutes = ABBREVIATIONS.ToMinutes(CPsPNow.TimeFrame); if (CPsPNow.Type != CPsPPrevious.Type || dTimeSpread > iTFMinutes)//CPsPNow.Ahead) { bPass = false; } } if (bPass) { LCPsPExtracted.Add(LCPsPAll[i]); } } return(LCPsPExtracted); }
public double AverageGainStreak(List <ChartPoint> LCPoints, TimeFrame TFrame) { double sum = 0; int iTimeShift = ABBREVIATIONS.ToMinutes(TFrame); int counter = 0; int antyCounter = 0; for (int i = 0; i < LCPoints.Count - 1; i++) { if (LCPoints[i].Time.AddMinutes(iTimeShift) == LCPoints[i + 1].Time) { ++counter; } else if (counter != 0) { sum += counter; counter = 0; ++antyCounter; } else { ++antyCounter; } ++i; } return(sum / antyCounter); }
private List <int> PredictSpecified(List <double> LDSet, List <double> LDSetToCompare, List <DateTime> LDTSTimes, TimeFrame TFrame, double[] IASymiliarities) { List <List <double> > LLDComparision = new List <List <double> >(); int iPeriod = ABBREVIATIONS.ToMinutes(TFrame); int iDeep = LDSetToCompare.Count; int iDecimals = 5; double iQuantization = Math.Pow(10, -iDecimals); List <double> LDSetSorted = LDSet.OrderBy(D => D).ToList(); Dictionary <double, int> DDIPositions = new Dictionary <double, int>(); for (int i = 0; i < LDSetSorted.Count; i++) { double dKey = LDSetSorted[i]; if (!DDIPositions.ContainsKey(dKey)) { DDIPositions.Add(dKey, 1); } else { ++DDIPositions[dKey]; } } double[] DAKeys = DDIPositions.Keys.ToArray(); for (int i = 1; i < DAKeys.Length; i++) { DDIPositions[DAKeys[i]] += DDIPositions[DAKeys[i - 1]]; } for (int i = 0; i < iDeep; i++) { List <double> LDComparision = new List <double>(); for (int i2 = 0; i2 < LDSet.Count; i2++) { LDComparision.Add(this.CompareSorted2(DDIPositions, DAKeys, LDSetToCompare[i], LDSet[i2])); } LLDComparision.Add(LDComparision); } List <int> LIMatch = Enumerable.Range(0, LLDComparision[0].Count) .Where(i => this.ExpessionDeppSpecified(LLDComparision, IASymiliarities, i)) .ToList(); return(Enumerable.Range(0, LIMatch.Count) .Where(i => this.ExpressionContinuous(LDTSTimes, iPeriod, iDeep, LIMatch[i])) .Select(i => LIMatch[i]) .ToList()); }
private void AddPredictionSpecified(double[] LDSet, List <ChartPoint> LCPointsToCompare, int setID, ref ConcurrentDictionary <int, List <double> > CDILDMatches, List <DateTime> LDTSTimes, TimeFrame TFrame, int ahead, double[] DAWeightFactors, int iRound) { int iDeep = LCPointsToCompare.Count; double[] DASubSet = new double[iDeep]; for (int i = 0; i < iDeep; i++) { DASubSet[i] = DASubSet[i] = LCPointsToCompare[i].GetParam(setID, iRound);//LCPointsToCompare[i].GetParamQuick(setID);// } Dictionary <double, int> DDIPositions = this.PositionsQuick(LDSet, DASubSet); int iDDIPCount = DDIPositions.Keys.Count; int iPeriod = ABBREVIATIONS.ToMinutes(TFrame); int iSubSetStrength = DDIPositions[DASubSet.Max()] - DDIPositions[DASubSet.Min()]; double[][] DJComparision = new double[iDeep][]; int dComparisionCount = (LDSet.Length - iDeep); for (int i = 0; i < iDeep; i++) { double[] DAComparision = new double[dComparisionCount];//(1 - ((double)(Math.Abs(DDIPositions[DASubSet[i]] - DDIPositions[LDSet[i2]])) / iDDIPCount)) * 100; for (int i2 = 0; i2 < dComparisionCount; i2++) { DAComparision[i2] = (1 - ((double)(Math.Abs(DDIPositions[DASubSet[i]] - DDIPositions[LDSet[i2]])) / iSubSetStrength)) * 100;// this.CompareSortedQuick(DDIPositions, iCount, DASubSet[i], LDSet[i2], iRound);// DAComparision[i2] = this.CompareSorted2(DDIPositions, DAKeys, DASubSet[i], LDSet[i2]); } DJComparision[i] = DAComparision; } List <double> LDMatch = new List <double>(); for (int i = 0; i < dComparisionCount; i++) { if (this.ExpressionContinuous(LDTSTimes, iPeriod, iDeep, ahead, i)) { LDMatch.Add(this.ExpessionDeppSimilarityQuick(DJComparision, i, setID));//ExpessionDeppSimilarityQuickMultiply } else { LDMatch.Add(0); } } // while (!CDILDMatches.TryAdd(setID, LDMatch)) { ; } }
public List <ChartPointsPredition> ExtractTestContinuousTendency(List <ChartPointsPredition> LCPsPAll) { List <ChartPointsPredition> LCPsPExtracted = new List <ChartPointsPredition>(); int iDeepMax = 6; for (int i = iDeepMax + 1; i < LCPsPAll.Count; i++) { int iDeep = -1; bool bPass = true; while (++iDeep < iDeepMax && bPass != false) { ChartPointsPredition CPsPPrevious = LCPsPAll[i - 1 - iDeep]; ChartPointsPredition CPsPNow = LCPsPAll[i - iDeep]; double dTimeSpread = (CPsPNow.DTOriginal - CPsPPrevious.DTOriginal).TotalMinutes; int iTFMinutes = ABBREVIATIONS.ToMinutes(CPsPNow.TimeFrame); if (dTimeSpread > iTFMinutes) { bPass = false; } else if ((CPsPNow.Type == ChartPointsPredition.Kind.Down && CPsPNow.Tendency >= CPsPPrevious.Tendency) || (CPsPNow.Type == ChartPointsPredition.Kind.Up && CPsPNow.Tendency <= CPsPPrevious.Tendency)) { bPass = false; } } if (bPass) { LCPsPExtracted.Add(LCPsPAll[i]); } } return(LCPsPExtracted); }
public List <DateTime[]> GetMissing(TimeFrame TFrame, string product) { List <DateTime[]> LADTPairs = new List <DateTime[]>(); List <ChartPoint> LCPoints = this.GetDATA(TFrame, product); if (LCPoints.Count < 2) { return(LADTPairs); } List <ChartPoint> LCPSorted = new List <ChartPoint>(LCPoints.OrderBy(CP => CP.Time).ToArray()); int iTFrame = ABBREVIATIONS.ToMinutes(TFrame); DateTime DTCurrent, DTNextExpected; DateTime DTNext; for (int i = 0; i < LCPSorted.Count - 1; i++) { DTCurrent = LCPSorted[i].Time; DTNextExpected = DTCurrent.AddMinutes(iTFrame); DTNext = LCPSorted[i + 1].Time; DayOfWeek DOfWeek = DTCurrent.DayOfWeek; if (DTNextExpected != DTNext && DOfWeek != DayOfWeek.Saturday) { if (DOfWeek == DayOfWeek.Friday && DTNextExpected.Hour > 22 && DTNextExpected.Minute > 0 || DOfWeek == DayOfWeek.Sunday && DTCurrent.Hour < 22 && DTCurrent.Minute < 0) { LADTPairs.Add(new DateTime[2] { DTCurrent, DTNext }); } } i += 1; } return(LADTPairs); }
public List <string> GetLiquids(List <string> LSProducts, OpenRatesBlotter ORBlotter, double minPercentage, int deep, double spreadFactor, TimeFrame TFrame) { List <string> LSLiquidProducts = new List <string>(); foreach (string product in ARCHIVE.GetProducts()) { Rates RATE = ORBlotter.Get(product); int iMinutesFrame = ABBREVIATIONS.ToMinutes(TFrame); List <ChartPoint> LCPoints = ARCHIVE.GetDATA(TFrame, product); DateTime DTLast100 = ABBREVIATIONS.GreenwichMeanTime.AddMinutes(-deep * iMinutesFrame); List <ChartPoint> LCPLast100 = (from CP in LCPoints where CP.Time > DTLast100 select CP).ToList(); if (this.LiquidPercentage(LCPLast100, RATE, spreadFactor) > minPercentage) { LSLiquidProducts.Add(product); } } return(LSLiquidProducts); }
public int Update(bool AutoSave, TimeFrame TFrame) { Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US"); string sTFrame = ABBREVIATIONS.ToString(TFrame); int iTFMinutes = ABBREVIATIONS.ToMinutes(TFrame); List <string> LSProducts = this.GetProducts(); //LThreadUpdate = new List<Thread>(); int counter = 0; foreach (string product in LSProducts) { if (this.GetDATA(TFrame, product).Last().IsActual(TFrame, 0)) { continue; } //LThreadUpdate.Add(new Thread(delegate() { DateTime DTCurrent = ABBREVIATIONS.GreenwichMeanTime.AddDays(1); Record DATA = this.Get(TFrame); DateTime startDateTime = DTStart; List <ChartPoint> LCPoints = DATA.Get(product); if (LCPoints != null && LCPoints.Count > 0) { startDateTime = LCPoints.Last().Time.AddMinutes(iTFMinutes); } List <DateTime> LDTUpdates = new List <DateTime>(); ChartData CData = null; do { try { CData = CService.GetChartData(TOKEN, product, TFrame, startDateTime, DTCurrent); //Product\Date and Time\Open\High price\Low price\Closing Price } catch { } if (CData == null || CData.Data == "") { break; } List <ChartPoint> LCPointsNew = this.ProcessData(CData.Data); LCPointsNew = new List <ChartPoint>(LCPointsNew.OrderBy(CP => CP.Time).ToArray()); this.SetDATA(TFrame, product, LCPointsNew); counter += LCPointsNew.Count(); DTCurrent = LCPointsNew[0].Time.AddMinutes(-iTFMinutes); if (AutoSave) { this.Save(product, DTCurrent, TFrame); } } while (startDateTime <= DTCurrent); // })); //LThreadUpdate.Last().Start(); } //foreach (Thread Thrd in LThreadUpdate) // Thrd.Join(); return(counter); }
private void TimrAutoTrader_Tick(object sender, EventArgs e) { //if (ThrdAutoTread != null && ThrdAutoTread.IsAlive) return; List <ChartPointsPredition> LCPsPSimulated = this.LCPsPTestSelected.OrderByDescending(CPsP => CPsP.Resolution).ToList(); if (LCPsPSimulated.Count < 1) { return; } ChartPointsPredition CPsPBest = null; List <Deals> LDeals = ODBlotter.GetData; for (int i = 0; i < LCPsPSimulated.Count; i++) { if (!LCPsPSimulated[i].IsActual) { continue; } //if ((LCPsPSimulated[i].Tendency <= 50 && LCPsPSimulated[i].TendencyToday >= 50) || (LCPsPSimulated[i].Tendency >= 50 && LCPsPSimulated[i].TendencyToday <= 50)) continue; bool found = false; for (int i2 = 0; i2 < LDeals.Count; i++) { try { if (LDeals[i2].PRODUCT == LCPsPSimulated[i].Product) { found = true; break; } } catch { found = true; break; } } if (!found) { CPsPBest = LCPsPSimulated[i]; break; } } if (CPsPBest == null) { return; } string product = CPsPBest.Product; DateTime DTLastGMT = CPsPBest.DTOriginal.AddMinutes(ABBREVIATIONS.ToMinutes(TimeFrame.ONE_MINUTE)); List <Rates> LRAll = ORBlotter.Archive.Get(product, DTLastGMT); // double dExecutionDataCount = (double)(ABBREVIATIONS.GreenwichMeanTime - DTLastGMT).TotalSeconds / 5; if (LRAll == null || LRAll.Count < 7)//dExecutionDataCount) { if (LRAll != null) { TsslInfo2.Text = "Missing Execution Data "; // +LRAll.Count + " / " + (int)dExecutionDataCount; } return; } //double dMin = 0, dMax = 0; if (!this.Extrema(product, 60, ref dMin, ref dMax)) return; //List<ChartPoint> LCPAll = ARCHIVE.GetDATA(TFrame, product, ABBREVIATIONS.GreenwichMeanTime.Date); //double dTendencyGlobal = ANALYSIS.Tendency(LCPAll, -1, false); //double dTendencyLoacl = ANALYSIS.Tendency(LCPAll, 15, true); bool bBUY = false; if (CPsPBest.Type == ChartPointsPredition.Kind.Up) { bBUY = true; } int iLRCount = LRAll.Count; bool bMatch = true; double dTendencyNow, dTendencyPrev; if (bBUY) { dTendencyPrev = 0; } else { dTendencyPrev = 100; } int iOFFTendencies = 0; int iOKTendencies = 0; int iSteps = 2; for (int i = iLRCount - 1; i > 2 && iSteps-- > 0; i /= 2) { dTendencyNow = ANALYSIS.Tendency(LRAll, i); if (bBUY && dTendencyNow < dTendencyPrev) { bMatch = false; break; } else if (!bBUY && dTendencyNow > dTendencyPrev) { bMatch = false; break; } dTendencyPrev = dTendencyNow; if ((dTendencyPrev >= 50 && bBUY) || (dTendencyPrev <= 50 && !bBUY)) { ++iOFFTendencies; } else { ++iOKTendencies; } } double dOPRatio = ((double)iOFFTendencies / (iOFFTendencies + iOKTendencies)) * 100; //if (dOPRatio >= 40) return; if (!bMatch) { return; // && dOPRatio > 40 } this.Action(product, bBUY); Thread ThrdBeep = new Thread(delegate() { Console.Beep(250, 100); }); ThrdBeep.Start(); }