diff --git a/Helpers/CalculationsHelper.cs b/Helpers/CalculationsHelper.cs index e9410cc..5c1e39c 100644 --- a/Helpers/CalculationsHelper.cs +++ b/Helpers/CalculationsHelper.cs @@ -741,7 +741,7 @@ public static (List, List) GetMaxAndMinValuesList(List - /// Adds the rounded. + /// Rounds the incoming value to a default of 4 decimal points /// /// The list. /// The value. @@ -767,17 +767,17 @@ public static IEnumerable TakeLastExt(this IEnumerable source, int coun if (0 == count) yield break; - if (source is ICollection) + if (source is ICollection collection) { - foreach (T item in source.Skip(Math.Max(0, ((ICollection)source).Count - count))) + foreach (T item in source.Skip(Math.Max(0, collection.Count - count))) yield return item; yield break; } - if (source is IReadOnlyCollection) + if (source is IReadOnlyCollection collection1) { - foreach (T item in source.Skip(Math.Max(0, ((IReadOnlyCollection)source).Count - count))) + foreach (T item in source.Skip(Math.Max(0, collection1.Count - count))) yield return item; yield break; diff --git a/Interfaces/ITickerData.cs b/Interfaces/ITickerData.cs new file mode 100644 index 0000000..4a3909c --- /dev/null +++ b/Interfaces/ITickerData.cs @@ -0,0 +1,11 @@ +namespace OoplesFinance.StockIndicators.Interfaces; + +public interface ITickerData +{ + public DateTime Date { get; } + public decimal Open { get; } + public decimal High { get; } + public decimal Low { get; } + public decimal Close { get; } + public decimal Volume { get; } +} diff --git a/Models/StockData.cs b/Models/StockData.cs index ac64052..8b38b6f 100644 --- a/Models/StockData.cs +++ b/Models/StockData.cs @@ -19,6 +19,15 @@ public class StockData : IStockData public List SignalsList { get; set; } public int Count { get; set; } + /// + /// Initializes the StockData Class using prebuilt lists of price information + /// + /// + /// + /// + /// + /// + /// public StockData(IEnumerable openPrices, IEnumerable highPrices, IEnumerable lowPrices, IEnumerable closePrices, IEnumerable volumes, IEnumerable dates) { @@ -34,6 +43,50 @@ public StockData(IEnumerable openPrices, IEnumerable highPrice SignalsList = new List(); InputName = InputName.Close; IndicatorName = IndicatorName.None; - Count = (OpenPrices.Count + HighPrices.Count + LowPrices.Count + ClosePrices.Count + Volumes.Count) / 5 == ClosePrices.Count ? ClosePrices.Count : 0; + Count = (OpenPrices.Count + HighPrices.Count + LowPrices.Count + ClosePrices.Count + Volumes.Count + Dates.Count) / 6 == ClosePrices.Count ? ClosePrices.Count : 0; + } + + /// + /// Initializes the StockData Class using classic list of ticker information + /// + /// + public StockData(IEnumerable tickerDataList) + { + OpenPrices = new List(); + HighPrices = new List(); + LowPrices = new List(); + ClosePrices = new List(); + Volumes = new List(); + Dates = new List(); + InputValues = new List(); + CustomValuesList = new List(); + OutputValues = new Dictionary>(); + SignalsList = new List(); + InputName = InputName.Close; + + for (int i = 0; i < tickerDataList.Count(); i++) + { + var ticker = tickerDataList.ElementAt(i); + + var date = ticker.Date; + Dates.Add(date); + + var open = ticker.Open; + OpenPrices.AddRounded(open); + + var high = ticker.High; + HighPrices.AddRounded(high); + + var low = ticker.Low; + LowPrices.AddRounded(low); + + var close = ticker.Close; + ClosePrices.AddRounded(close); + + var volume = ticker.Volume; + Volumes.AddRounded(volume); + } + + Count = (OpenPrices.Count + HighPrices.Count + LowPrices.Count + ClosePrices.Count + Volumes.Count + Dates.Count) / 6 == ClosePrices.Count ? ClosePrices.Count : 0; } } \ No newline at end of file diff --git a/Models/TickerData.cs b/Models/TickerData.cs new file mode 100644 index 0000000..088b623 --- /dev/null +++ b/Models/TickerData.cs @@ -0,0 +1,12 @@ +namespace OoplesFinance.StockIndicators.Models; + +[Serializable] +public class TickerData : ITickerData +{ + public DateTime Date { get; set; } + public decimal Open { get; set; } + public decimal High { get; set; } + public decimal Low { get; set; } + public decimal Close { get; set; } + public decimal Volume { get; set; } +} diff --git a/OoplesFinance.StockIndicators.csproj b/OoplesFinance.StockIndicators.csproj index 3c13020..2dfe79e 100644 --- a/OoplesFinance.StockIndicators.csproj +++ b/OoplesFinance.StockIndicators.csproj @@ -8,7 +8,7 @@ True en-US Largest C# stock indicator library with over 750 to choose from and easiest to use with abilities such as making an indicator out of any other indicator or using any moving average with any indicator. - 1.0.38 + 1.0.39 ooples Ooples Finance https://github.com/ooples/OoplesFinance.StockIndicators