Skip to content

Commit

Permalink
edit account and investment info on seperate page
Browse files Browse the repository at this point in the history
  • Loading branch information
rrelyea committed Dec 23, 2023
1 parent 30fee7c commit e778b37
Show file tree
Hide file tree
Showing 6 changed files with 1,291 additions and 75 deletions.
1,010 changes: 1,010 additions & 0 deletions Pages/AccountView.razor

Large diffs are not rendered by default.

223 changes: 193 additions & 30 deletions Pages/Portfolio.razor

Large diffs are not rendered by default.

105 changes: 61 additions & 44 deletions Shared/Models/FamilyData/Account.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,51 +129,12 @@ public void UpdatePercentages(double totalValue, FamilyData familyData)
foreach (var investment in Investments)
{
investment.Percentage = (investment.Value ?? 0) / totalValue * 100;
if (investment.AssetType == null)

UpdateInvestmentCategoryTotals(investment, familyData);
foreach (var transaction in investment.Transactions)
{
familyData.OtherBalance += investment.Value;
}
else
{
switch (investment.AssetType) {
case AssetType.Stock:
case AssetType.USStock:
case AssetType.USStock_ETF:
case AssetType.USStock_Fund:
familyData.StockBalance += investment.Value;
break;
case AssetType.InternationalStock:
case AssetType.InternationalStock_ETF:
case AssetType.InternationalStock_Fund:
familyData.InternationalStockBalance += investment.Value;
break;
case AssetType.Bond:
case AssetType.Bond_ETF:
case AssetType.Bond_Fund:
case AssetType.InternationalBond:
case AssetType.InternationalBond_ETF:
case AssetType.InternationalBond_Fund:
familyData.BondBalance += investment.Value;
break;
case AssetType.Cash:
case AssetType.Cash_BankAccount:
case AssetType.Cash_MoneyMarket:
familyData.CashBalance += investment.Value;
break;
case AssetType.StocksAndBonds_ETF:
case AssetType.StocksAndBonds_Fund:
familyData.StockBalance += investment.Value * investment.GetPercentage(AssetType.USStock);
familyData.InternationalStockBalance += investment.Value * investment.GetPercentage(AssetType.InternationalStock);
familyData.BondBalance += investment.Value * investment.GetPercentage(AssetType.Bond);
familyData.BondBalance += investment.Value * investment.GetPercentage(AssetType.InternationalBond);
familyData.CashBalance += investment.Value * investment.GetPercentage(AssetType.Cash);
break;
case AssetType.Unknown:
familyData.OtherBalance += investment.Value;
break;
default:
throw new InvalidDataException("unexpected case");
}
var fromInvestment = (transaction.FromInvestment == investment);
UpdateInvestmentCategoryTotals(investment, familyData, overrideValue:transaction.Value, useNegative:fromInvestment);
}

if (investment.ExpenseRatio.HasValue && investment.Value.HasValue) {
Expand All @@ -186,6 +147,62 @@ public void UpdatePercentages(double totalValue, FamilyData familyData)
}
}

public void UpdateInvestmentCategoryTotals(Investment investment, FamilyData familyData, double? overrideValue = null, bool useNegative = false)
{
var value = investment.Value * (useNegative?-1:1);
if (overrideValue != null)
{
value = overrideValue * (useNegative?-1:1);
}

if (investment.AssetType == null)
{
familyData.OtherBalance += value;
}
else
{
switch (investment.AssetType) {
case AssetType.Stock:
case AssetType.USStock:
case AssetType.USStock_ETF:
case AssetType.USStock_Fund:
familyData.StockBalance += value;
break;
case AssetType.InternationalStock:
case AssetType.InternationalStock_ETF:
case AssetType.InternationalStock_Fund:
familyData.InternationalStockBalance += value;
break;
case AssetType.Bond:
case AssetType.Bond_ETF:
case AssetType.Bond_Fund:
case AssetType.InternationalBond:
case AssetType.InternationalBond_ETF:
case AssetType.InternationalBond_Fund:
familyData.BondBalance += value;
break;
case AssetType.Cash:
case AssetType.Cash_BankAccount:
case AssetType.Cash_MoneyMarket:
familyData.CashBalance += value;
break;
case AssetType.StocksAndBonds_ETF:
case AssetType.StocksAndBonds_Fund:
familyData.StockBalance += value * investment.GetPercentage(AssetType.USStock);
familyData.InternationalStockBalance += value * investment.GetPercentage(AssetType.InternationalStock);
familyData.BondBalance += value * investment.GetPercentage(AssetType.Bond);
familyData.BondBalance += value * investment.GetPercentage(AssetType.InternationalBond);
familyData.CashBalance += value * investment.GetPercentage(AssetType.Cash);
break;
case AssetType.Unknown:
familyData.OtherBalance += value;
break;
default:
throw new InvalidDataException("unexpected case");
}
}
}

public void GuessAccountType()
{
if (Note is not null) {
Expand Down
6 changes: 6 additions & 0 deletions Shared/Models/FamilyData/FamilyData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,12 @@ public double? Bonds {
public double? CashBalance { get; set; }
public double? OtherBalance { get; set; }

public double ActualTotalStockAllocation {
get {
return ActualStockAllocation*100.0 * (1.0-ActualInternationalStockAllocation);
}
}

public double ActualStockAllocation {
get {
var overallTotal = (StockBalance ?? 0.0) + (InternationalStockBalance ?? 0.0) + (BondBalance ?? 0.0) + (OtherBalance ?? 0.0) + (CashBalance ?? 0.0);
Expand Down
12 changes: 11 additions & 1 deletion Shared/Models/FamilyData/Investment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@
public class Investment
{
public Investment() {

}

public Investment(int? pin) : this()
{
PIN = pin;
}

[JsonIgnore]
public bool Selected { get; set; }

[JsonIgnore]
public IList<Fund>? funds { get; set; }

Expand All @@ -25,6 +27,14 @@ public string? Name {
}
}

private List<Transaction> _Transactions = new();
public List<Transaction> Transactions
{
get {
return _Transactions;
}
}

public bool AutoCompleted { get; set; }
private string? _Ticker;
public string? Ticker {
Expand Down
10 changes: 10 additions & 0 deletions Shared/Models/FamilyData/Transaction.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System.Text.Json.Serialization;

public class Transaction
{
[JsonIgnore]
public Investment FromInvestment { get; set; }
[JsonIgnore]
public Investment ToInvestment { get; set; }
public double? Value { get; set; }
}

0 comments on commit e778b37

Please sign in to comment.