Skip to content

Commit

Permalink
implement FamilyData.ChangeInXUnits
Browse files Browse the repository at this point in the history
  • Loading branch information
rrelyea committed Mar 12, 2024
1 parent 333254b commit 0da7a50
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions library/Models/FamilyData/EmergencyFund.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public int? MonthlyExpenses
if (FamilyData != null)
{
FamilyData.UpdateValueInXUnits();
FamilyData.UpdateChangeInXUnits();
}
}
}
Expand Down
14 changes: 14 additions & 0 deletions library/Models/FamilyData/FamilyData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ public bool DebtsComplete
}

public double? ValueInXUnits { get { return valueInXUnits; } set { valueInXUnits = value; OnPropertyChanged(); } }
public double? ChangeInXUnits { get { return changeInXUnits; } set { changeInXUnits = value; OnPropertyChanged(); } }

public TriState DebtFree { get; set; }
public List<Debt> Debts { get; set; }
Expand Down Expand Up @@ -612,6 +613,7 @@ public async Task UpdatePercentagesAsync()

var changes = PortfolioChange();
Change = changes.change;
UpdateChangeInXUnits();
PercentChange = changes.percentChange;
}

Expand Down Expand Up @@ -728,6 +730,7 @@ public int PersonCount
[JsonIgnore]
public SortedDictionary<string, List<Investment>>? TickersToUpdate;
private double? valueInXUnits;
private double? changeInXUnits;

public async Task RefreshPrices(HttpClient http)
{
Expand Down Expand Up @@ -1000,4 +1003,15 @@ internal void UpdateValueInXUnits()

ValueInXUnits = valueInXUnits;
}

internal void UpdateChangeInXUnits()
{
double? changeInXUnits = (double)(Change) / (double)(EmergencyFund.AnnualExpenses ?? 0.0);
if (changeInXUnits.HasValue && (double.IsNaN(changeInXUnits.Value) || double.IsInfinity(changeInXUnits.Value)))
{
changeInXUnits = null;
}

ChangeInXUnits = changeInXUnits;
}
}

0 comments on commit 0da7a50

Please sign in to comment.