コード例 #1
0
 public void Open__AddsToActive_SubsCash(PositionDir dir, float price, float vol, StockDataRange range, int intradayInterval)
 {
     _testObj.Open(_stock, dir, CurrentTS, price, vol, Commission, range, intradayInterval, EntrySignal);
     _testObj.Cash.ShouldBe(CashValue - _testObj.PositionsActive[0].DirectionMultiplier() * (price * vol) - Commission);
     _testObj.PositionsActive.Count.ShouldBe(1);
     CheckOpenedPosition(_testObj.PositionsActive[0], _stock, dir, price, vol, Commission, CurrentTS, range, intradayInterval);
 }
コード例 #2
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);
            }
        }
コード例 #3
0
 private void CheckOpenedPosition(Position pos, StockDefinition stock, PositionDir dir, float open, float vol, float commission, DateTime ts, StockDataRange range, int interval)
 {
     pos.Stock.ShouldBe(stock);
     pos.Direction.ShouldBe(dir);
     pos.TSOpen.ShouldBe(ts);
     pos.Open.ShouldBe(open);
     pos.OpenCommission.ShouldBe(commission);
     pos.Volume.ShouldBe(vol);
     pos.DataRange.ShouldBe(range);
     pos.IntradayInterval.ShouldBe(interval);
     pos.EntrySignal.ShouldBe(EntrySignal);
 }
コード例 #4
0
        public static void Open(this SystemState systemState, StockDefinition stock, PositionDir dir, DateTime ts, float price, float volume, float commission, StockDataRange dataRange, int intradayInterval, Signal entrySignal)
        {
            Position pos = new Position
            {
                Stock            = stock,
                DataRange        = dataRange,
                IntradayInterval = intradayInterval,
                Direction        = dir,
                Open             = price,
                OpenCommission   = commission,
                TSOpen           = ts,
                Volume           = volume,
                EntrySignal      = entrySignal,
                TicksActive      = 1
            };

            systemState.PositionsActive.Add(pos);
            systemState.Cash -= pos.DirectionMultiplier() * pos.OpenValue();
            systemState.Cash -= pos.OpenCommission;
        }
コード例 #5
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]);
     }
 }
コード例 #6
0
 /// <summary>
 /// Gets stockpricesdata and index of specified ts. Returns true if index found, and has required length of back buffer.
 /// </summary>
 /// <param name="dataLoader"></param>
 /// <param name="stockName"></param>
 /// <param name="dataRange"></param>
 /// <param name="ts"></param>
 /// <param name="requiredBackBufferLength"></param>
 /// <param name="spData"></param>
 /// <param name="dataIndex"></param>
 /// <returns></returns>
 public static bool GetWithIndex(this ISystemDataLoader dataLoader, string stockName, StockDataRange dataRange, DateTime ts, int requiredBackBufferLength,
                                 out StockPricesData spData, out int dataIndex)
 {
     if (GetWithIndex(dataLoader, stockName, dataRange, ts, out spData, out dataIndex))
     {
         return(dataIndex >= requiredBackBufferLength);
     }
     return(false);
 }
コード例 #7
0
 public void OneTickBefore__ReturnsCorrectly(int tsY, int tsM, int tsD, int tsH, int tsMM, StockDataRange stockDataRange, int interadayInterval
                                             , int etsY, int etsM, int etsD, int etsH, int etsMM)
 {
     DateTimeOperations.OneTickBefore(new DateTime(tsY, tsM, tsD, tsH, tsMM, 0), new StockPricesData(0)
     {
         Range = stockDataRange, IntrradayInterval = interadayInterval
     })
     .ShouldBe(new DateTime(etsY, etsM, etsD, etsH, etsMM, 0));
 }
コード例 #8
0
 private float CalculatePrice(string stockName, StockDataRange dataRange, int intradayInterval, Signal signal, DateTime ts, Func <Signal, StockPricesData, int, float> openPriceSelector)
 {
     (StockPricesData pricesData, int pricesDataIndex) = _dataLoader.GetPricesDataAndIndex(stockName, dataRange, intradayInterval, ts);
     return(openPriceSelector(signal, pricesData, pricesDataIndex));
 }
コード例 #9
0
 /// <summary>
 /// Gets stockpricesdata and index of specified ts. Returns true if index found.
 /// </summary>
 /// <param name="dataLoader"></param>
 /// <param name="stockName"></param>
 /// <param name="dataRange"></param>
 /// <param name="ts"></param>
 /// <param name="spData"></param>
 /// <param name="dataIndex"></param>
 /// <returns></returns>
 public static bool GetWithIndex(this ISystemDataLoader dataLoader, string stockName, StockDataRange dataRange, DateTime ts,
                                 out StockPricesData spData, out int dataIndex)
 {
     spData    = dataLoader.Get(stockName, dataRange, 0, ts, ts);
     dataIndex = spData.FindByTS(ts);
     return(dataIndex >= 0);
 }
コード例 #10
0
        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]);
            }
        }
コード例 #11
0
 public static Signal CreateSignal(float[] newBalance, StockDataRange dataRange, BBTrendFundsData fundsData) =>
コード例 #12
0
        private StockPricesData LoadData(string stockName, StockDataRange dataRange, int intradayInterval, DateTime tsFrom, DateTime tsTo)
        {
            StockDefinition stock = _dataProvider.GetStockDefinition(stockName);

            return(_dataProvider.GetPricesData(stock, dataRange, intradayInterval, tsFrom, tsTo));
        }
コード例 #13
0
 private string BufferKey(string stockName, StockDataRange dataRange, int intradayDataRange) => $"{stockName}_{dataRange}_{intradayDataRange}";
コード例 #14
0
 private string GetStdTableName(StockType stockType, StockDataRange dataRange)
 {
     return(_tableNameByDataRange[dataRange] + ((int)stockType).ToString());
 }