Skip to content

Commit

Permalink
Added a new method to build the stock data class using typical ticker…
Browse files Browse the repository at this point in the history
… data
  • Loading branch information
ooples committed Feb 26, 2022
1 parent 09de2c3 commit 19ce200
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 7 deletions.
10 changes: 5 additions & 5 deletions Helpers/CalculationsHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -741,7 +741,7 @@ public static (List<decimal>, List<decimal>) GetMaxAndMinValuesList(List<decimal
}

/// <summary>
/// Adds the rounded.
/// Rounds the incoming value to a default of 4 decimal points
/// </summary>
/// <param name="list">The list.</param>
/// <param name="value">The value.</param>
Expand All @@ -767,17 +767,17 @@ public static IEnumerable<T> TakeLastExt<T>(this IEnumerable<T> source, int coun
if (0 == count)
yield break;

if (source is ICollection<T>)
if (source is ICollection<T> collection)
{
foreach (T item in source.Skip(Math.Max(0, ((ICollection<T>)source).Count - count)))
foreach (T item in source.Skip(Math.Max(0, collection.Count - count)))
yield return item;

yield break;
}

if (source is IReadOnlyCollection<T>)
if (source is IReadOnlyCollection<T> collection1)
{
foreach (T item in source.Skip(Math.Max(0, ((IReadOnlyCollection<T>)source).Count - count)))
foreach (T item in source.Skip(Math.Max(0, collection1.Count - count)))
yield return item;

yield break;
Expand Down
11 changes: 11 additions & 0 deletions Interfaces/ITickerData.cs
Original file line number Diff line number Diff line change
@@ -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; }
}
55 changes: 54 additions & 1 deletion Models/StockData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@ public class StockData : IStockData
public List<Signal> SignalsList { get; set; }
public int Count { get; set; }

/// <summary>
/// Initializes the StockData Class using prebuilt lists of price information
/// </summary>
/// <param name="openPrices"></param>
/// <param name="highPrices"></param>
/// <param name="lowPrices"></param>
/// <param name="closePrices"></param>
/// <param name="volumes"></param>
/// <param name="dates"></param>
public StockData(IEnumerable<decimal> openPrices, IEnumerable<decimal> highPrices, IEnumerable<decimal> lowPrices, IEnumerable<decimal> closePrices,
IEnumerable<decimal> volumes, IEnumerable<DateTime> dates)
{
Expand All @@ -34,6 +43,50 @@ public StockData(IEnumerable<decimal> openPrices, IEnumerable<decimal> highPrice
SignalsList = new List<Signal>();
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;
}

/// <summary>
/// Initializes the StockData Class using classic list of ticker information
/// </summary>
/// <param name="tickerDataList"></param>
public StockData(IEnumerable<TickerData> tickerDataList)
{
OpenPrices = new List<decimal>();
HighPrices = new List<decimal>();
LowPrices = new List<decimal>();
ClosePrices = new List<decimal>();
Volumes = new List<decimal>();
Dates = new List<DateTime>();
InputValues = new List<decimal>();
CustomValuesList = new List<decimal>();
OutputValues = new Dictionary<string, List<decimal>>();
SignalsList = new List<Signal>();
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;
}
}
12 changes: 12 additions & 0 deletions Models/TickerData.cs
Original file line number Diff line number Diff line change
@@ -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; }
}
2 changes: 1 addition & 1 deletion OoplesFinance.StockIndicators.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<NeutralLanguage>en-US</NeutralLanguage>
<Description>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. </Description>
<Version>1.0.38</Version>
<Version>1.0.39</Version>
<Authors>ooples</Authors>
<Company>Ooples Finance</Company>
<RepositoryUrl>https://github.com/ooples/OoplesFinance.StockIndicators</RepositoryUrl>
Expand Down

0 comments on commit 19ce200

Please sign in to comment.