示例#1
0
        static void HowToUseThisClassExamples()
        {
            // 1. set up timeSeries
            var ts2 = new FinTimeSeries <DateOnly, float, uint>(new TickType[] { TickType.SplitDivAdjClose }, new TickType[] { TickType.Volume });

            ts2.Capacity = 10;  // set capacity will increase all TickType arrays

            // Arrays are refence types. Just create the arrays and pass it to the constructor
            var kvpar1 = new KeyValuePair <TickType, float[]>(TickType.SplitDivAdjClose, Array.Empty <float>());
            var kvpar2 = new KeyValuePair <TickType, uint[]>(TickType.Volume, Array.Empty <uint>());
            var ts1    = new FinTimeSeries <DateOnly, float, uint>(
                new DateOnly[] { },
                new KeyValuePair <TickType, float[]>[] { kvpar1 },
                new KeyValuePair <TickType, uint[]>[] { kvpar2 }
                );


            // 2. consume timeSeries via public methods
            float ts1YesterdayClose3     = ts1.GetValues1(new DateOnly(), TickType.Close); // neat if data is accessed via methods
            bool  isOkTs1YesterdayClose3 = ts1.TryGetValue1(new DateOnly(), TickType.Close, out float value);

            // access array via a List, indirectly. There is no memory consumption. Direct reference to the private array.
            // supports only: [] indexer as one by one direct access, and CopyTo() into destination TValue1[] arrays.
            IList <float> array2 = ts1.Values1(TickType.Close);

            // 3. access timeSeries via private members (can be accessed only from inside the class)
            float[] array1             = ts1.values1[TickType.Close];                                 // access array directly, although it should be private
            float   ts1YesterdayClose2 = ts1.values1[TickType.Close][ts1.IndexOfKey(new DateOnly())]; // possible to access inner members and manipulate if needed

            // 4. The most efficient, faster usage is the direct usage of the array. Better than (linked-) List, and there is no indirection.
            DateOnly[] dates    = ts1.GetKeyArrayDirect();
            float[]    sdaClose = ts1.GetValue1ArrayDirect(TickType.SplitDivAdjClose);

            // Example usage from MemDb:
            // Security sec = MemDb.gMemDb.GetFirstMatchingSecurity(r.Ticker);
            // DateOnly[] dates = sec.DailyHistory.GetKeyArrayDirect();
            // float[] sdaCloses = sec.DailyHistory.GetValue1ArrayDirect(TickType.SplitDivAdjClose);
            // // At 16:00, or even intraday: YF gives even the today last-realtime price with a today-date. We have to find any date backwards, which is NOT today. That is the PreviousClose.
            // int i = (dates[dates.Length - 1] >= new DateOnly(DateTime.UtcNow)) ? dates.Length - 2 : dates.Length - 1;
            // Debug.WriteLine($"Found: {r.Ticker}, {dates[i]}:{sdaCloses[i]}");

            // DateTime[] ts1LastWeekDates = ts1.GetRangeIncDate(new DateTime(), new DateTime());
            // double[] ts1LastWeekCloses = ts1.GetRangeIncDouble(new DateTime(), new DateTime(), TickType.Close);
            // UInt32[] ts1LastWeekVolumes = ts1.GetRangeIncUint(new DateTime(), new DateTime(), TickType.Close);
        }
示例#2
0
 internal FinTimeSeriesValueEnumerator2(FinTimeSeries <TKey, TValue1, TValue2> sortedList, TickType tickType)
 {
     _sortedList = sortedList;
     _version    = sortedList.version;
     _tickType   = tickType;
 }
示例#3
0
 internal FinTimeSeriesKeyEnumerator(FinTimeSeries <TKey, TValue1, TValue2> sortedList)
 {
     _sortedList = sortedList;
     _version    = sortedList.version;
 }
示例#4
0
 internal ValueList2(FinTimeSeries <TKey, TValue1, TValue2> dictionary, TickType tickType)
 {
     _dict     = dictionary;
     _tickType = tickType;
 }
示例#5
0
            private readonly FinTimeSeries <TKey, TValue1, TValue2> _dict; // Do not rename (binary serialization)

            internal KeyList(FinTimeSeries <TKey, TValue1, TValue2> dictionary)
            {
                _dict = dictionary;
            }