private float PcntProfitFromNTicks(string fundName, int n, DateTime ts)
 {
     if (!_dataLoader.GetWithIndex(fundName, _dataRange, ts, n, out StockPricesData spData, out int dataIndex))
     {
         return(float.MinValue);
     }
     return((spData.C[dataIndex] - spData.C[dataIndex - n]) / spData.C[dataIndex - n]);
 }
        public static void Calculate(SimplexFundsData data, DateTime ts, int profitRange, int changeRange, StockDataRange dataRange, ISystemDataLoader dataLoader)
        {
            dataLoader.GetWithIndex(data.Stocks[0].FullName, dataRange, ts, 0, out StockPricesData spData0, out _);
            DateTime simLastTs = spData0.TS[spData0.TS.Length - 1];

            for (int i = 0; i < data.Stocks.Length; i++)
            {
                data.Active[i] = dataLoader.GetWithIndex(data.Stocks[i].FullName, dataRange, ts, Math.Max(profitRange, changeRange) + 1, out StockPricesData spData, out int dataIndex);
                if (!data.Active[i])
                {
                    continue;
                }
                data.Active[i] = NotLastButOneDataIndex(spData, dataIndex, simLastTs);
                if (!data.Active[i])
                {
                    continue;
                }

                data.Prices[i]         = spData.C[dataIndex];
                data.AvgProfit[i]      = AvgChangeInPercent(spData.C, dataIndex, profitRange, null);
                data.AvgChange[i]      = AvgChangeInPercent(spData.C, dataIndex, changeRange, Math.Abs);
                data.AvgChangeSigma[i] = StdDev(spData.C, dataIndex, changeRange, data.AvgChange[i]);
            }
        }
Example #3
0
        public static void CalculateMaxValuesAndStops(BBTrendFundsData data, float stopWidth, DateTime ts, StockDataRange dataRange, ISystemDataLoader dataLoader)
        {
            for (int i = 0; i < data.Stocks.Length; i++)
            {
                if (data.CurrentTrends[i] != BBTrendType.Up)
                {
                    data.UpTrendMaxValues[i]  = float.MinValue;
                    data.UpTrendStopValues[i] = float.MinValue;
                    continue;
                }

                if (!dataLoader.GetWithIndex(data.Stocks[i].FullName, dataRange, ts, out StockPricesData spData, out int dataIndex))
                {
                    continue;
                }
                //data.UpTrendMaxValues[i] = Math.Max(spData.H[dataIndex], data.UpTrendMaxValues[i]);
                data.UpTrendMaxValues[i]  = Math.Max(spData.C[dataIndex], data.UpTrendMaxValues[i]);
                data.UpTrendStopValues[i] = data.UpTrendMaxValues[i] * (1f - stopWidth);
            }
        }
Example #4
0
 public static void CalculateTrendsAndExpectations(BBTrendFundsData data, DateTime ts, StockDataRange dataRange, ISystemDataLoader dataLoader)
 {
     for (int i = 0; i < data.Stocks.Length; i++)
     {
         if (!dataLoader.GetWithIndex(data.Stocks[i].FullName, dataRange, ts, data.StatsBB[i].BackBufferLength, out StockPricesData spData, out int dataIndex))
         {
             continue;
         }
         BBTrendType lastTrend = data.CurrentTrends[i];
         data.CurrentTrends[i] = BBTrendRecognizer.BBTrendRecognizer.RecognizeTrend(spData, data.StatsBB[i], dataIndex, data.CurrentTrends[i], out float trendStartLevel);
         if (lastTrend != data.CurrentTrends[i])
         {
             data.UpTrendStartValues[i] = trendStartLevel;// spData.H[dataIndex];
             data.TrendLength[i]        = 0;
         }
         data.TrendLength[i]++;
         BBTrendExpectation lastExpectation = data.CurrentExpectations[i];
         data.CurrentExpectations[i] = BBTrendRecognizer.BBTrendRecognizer.GetExpectation(spData, data.StatsBB[i], dataIndex, data.CurrentTrends[i]);
         data.ExpectationChanged[i]  = (lastExpectation != data.CurrentExpectations[i]);
     }
 }
Example #5
0
        public static void CheckStops(BBTrendFundsData data, DateTime ts, StockDataRange dataRange, ISystemDataLoader dataLoader)
        {
            for (int i = 0; i < data.Stocks.Length; i++)
            {
                if (data.CurrentTrends[i] != BBTrendType.Up)
                {
                    data.StoppedOut[i] = false;
                    continue;
                }

                if (!dataLoader.GetWithIndex(data.Stocks[i].FullName, dataRange, ts, out StockPricesData spData, out int dataIndex))
                {
                    continue;
                }
                if (data.StoppedOut[i])
                {
                    data.StoppedOut[i] = (spData.C[dataIndex] <= data.StoppedOutValues[i]) || !PriceAbovePrevMaxH(data, i, dataIndex, spData.C[dataIndex]);
                }
                else
                {
                    data.StoppedOut[i] = (spData.C[dataIndex] <= data.UpTrendStopValues[i]);
                }
            }
        }