Пример #1
0
        public void FindByTS_ValuesOnList__ReturnsItemIndex()
        {
            StockPricesData d = CreateTestObj();

            d.FindByTS(TestStartTS).ShouldBe(TESTDATALEN - 1, "last");
            d.FindByTS(TestStartTS.AddDays(-1)).ShouldBe(TESTDATALEN - 2, "mid");
            d.FindByTS(TestStartTS.AddDays(-2)).ShouldBe(TESTDATALEN - 3, "first");
        }
 /// <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);
 }
 private float CalcActive(SystemState system, DateTime ts, ISystemDataLoader dataLoader)
 {
     return(system.PositionsActive.Sum(p =>
     {
         StockPricesData prices = dataLoader.Get(p.Stock.FullName, p.DataRange, p.IntradayInterval, ts, ts);
         int ix = prices.FindByTS(ts);
         return p.DirectionMultiplier() * prices.C[ix] * p.Volume;
     }));
 }
Пример #4
0
 private void ProcessActivePrositions(DateTime ts, SystemState systemState,
     Func<Position, StockPricesData, int, bool> positionSelector,
     Func<Position, StockPricesData, int, float> closePriceSelector)
 {
     int i = 0;
     while (i < systemState.PositionsActive.Count)
     {
         StockPricesData pricesData = GetPricesData(systemState.PositionsActive[i], ts);
         int pricesDataIndex = pricesData.FindByTS(ts);
         if (positionSelector(systemState.PositionsActive[i], pricesData, pricesDataIndex))
             ProcessPosition(ts, systemState, i, closePriceSelector, pricesData, pricesDataIndex);
         else
             i++;
     }
 }