From e95759c7b3a62e190f2892bef41d6a4217c94ff0 Mon Sep 17 00:00:00 2001 From: Miha Kralj Date: Sun, 15 Oct 2023 09:41:24 -0700 Subject: [PATCH] dev up-to-speed --- Calculations/Logic/EQUITY_Series.cs | 2 +- Calculations/_Updated/TSeries.cs | 13 +++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/Calculations/Logic/EQUITY_Series.cs b/Calculations/Logic/EQUITY_Series.cs index 78e8fa0d..8323feb7 100644 --- a/Calculations/Logic/EQUITY_Series.cs +++ b/Calculations/Logic/EQUITY_Series.cs @@ -81,7 +81,7 @@ public class EQUITY_Series : Single_TSeries_Indicator { if (_inmarket == 0 && TValue.v == 1) { _longbuy = true; } //out of market, enter long if (_inmarket == 1 && TValue.v == -1) { _longsell = true; } //long market, exit long - //Console.WriteLine($"{TValue.v,3}\t {(_inmarket)} : {_cash,10:f2} + {_units*_price[this.Count-1].v,7:f2} = {_equity-_capital:f2}"); + //Console.WriteLine($"{TValue.v,3}\t {(_inmarket)} : {_cash,10:f2} + {_units*_price[^1].v,7:f2} = {_equity-_capital:f2}"); } inmarket.Add((TValue.t, (double)_inmarket)); base.Add((TValue.t, _equity), update, _NaN); diff --git a/Calculations/_Updated/TSeries.cs b/Calculations/_Updated/TSeries.cs index ce0e3c08..ccde468d 100644 --- a/Calculations/_Updated/TSeries.cs +++ b/Calculations/_Updated/TSeries.cs @@ -20,9 +20,11 @@ public class TSeriesEventArgs : EventArgs { } public class TSeries : List<(DateTime t, double v)> { - public List t => this.Select(item => item.t).ToList(); - public List v => this.Select(item => item.v).ToList(); - public (DateTime t, double v) Last => this[^1]; + private readonly (DateTime t, double v) Default = (DateTime.MinValue, double.NaN); + public IEnumerable t => this.Select(item => item.t); + public IEnumerable v => this.Select(item => item.v); + public (DateTime t, double v) Last => Count > 0 ? this[^1] : Default; + public int Length => Count; public string Name { get; set; } @@ -35,13 +37,12 @@ public class TSeries : List<(DateTime t, double v)> { } public virtual (DateTime t, double v) Add(double v, bool update = false) { - var Value = (t: Count == 0 ? DateTime.Today : this[this.Count-1].t.AddDays(1), v); - return Add(Value, update); + return Add((t: Count == 0 ? DateTime.Today : this[^1].t.AddDays(1), v), update); } public virtual (DateTime t, double v) Add((DateTime t, double v) TValue, bool update = false) { if (update) { - this[this.Count-1] = TValue; + this[^1] = TValue; } else { base.Add(TValue);