Skip to content

Commit

Permalink
view by ticker or by all investments in each account
Browse files Browse the repository at this point in the history
  • Loading branch information
rrelyea committed Jun 21, 2023
1 parent e9f878d commit 49b8910
Show file tree
Hide file tree
Showing 2 changed files with 112 additions and 28 deletions.
94 changes: 66 additions & 28 deletions Pages/Portfolio.razor
Original file line number Diff line number Diff line change
Expand Up @@ -149,41 +149,79 @@ Portfolio@(stepPath==null?": review":": "+stepPath.Replace('-',' ')) - bogle.too
@if (familyData.Accounts.Count > 0) {
@((MarkupString)boldUnderline("Current Retirement Assets:"))<br/>
}
<table>
@if (familyData.Accounts.Count > 0) {
<tr style=vertical-align:bottom>
<th>Account</th>
<th style=padding-left:8px></th>
<th style=padding-left:8px>Type</th>
<th style=padding-left:8px>Ticker</th>
<th style=padding-left:8px;text-align:center>
@if (familyData.EODHistoricalDataApiKey != null)
{
<button @onclick=@refreshPrices title=Refresh>🔃</button>
} else {
<a href="updated-quotes">Enable<br/>updates.</a>
}
<br/>
<span>$ / share</span>
</th>
<th style=padding-left:8px>Shares</th>
<th style=padding-left:8px>$ Value</th>
</tr>
}
@foreach (var account in familyData.Accounts) {
@foreach (var investment in account.Investments) {

<Label>View:</Label>&nbsp;<InputSelect @bind-Value=familyData.PortfolioView >
<option>All Investments by Account</option>
<option>Group Investments by Ticker</option>
</InputSelect>
@if(familyData.PortfolioView == "Group Investments by Ticker")
{
<table>
@if (familyData.Accounts.Count > 0) {
<tr style=vertical-align:bottom>
<th style=padding-left:8px>Ticker</th>
<th style=padding-left:8px;text-align:center>
@if (familyData.EODHistoricalDataApiKey != null)
{
<button @onclick=@refreshPrices title=Refresh>🔃</button>
} else {
<a href="updated-quotes">Enable<br/>updates.</a>
}
<br/>
<span>$ / share</span>
</th>
<th style=padding-left:8px>Shares</th>
<th style=padding-left:8px>$ Value</th>
</tr>
}
@foreach (var investment in familyData.GroupedInvestments) {
<tr>
<td>@((account.Custodian != null ? account.Custodian + " ": "")+ account.Note)</td>
<td style=padding-left:8px>@account.Identifier</td>
<td style=padding-left:8px>@account.AccountType</td>
<td style=padding-left:8px title=@investment.Name>@investment.Ticker</td>
<td style=text-align:right;padding-left:8px>@formatDoubleTwoDecimal(investment.Price)</td>
<td style=text-align:right;padding-left:8px>@formatDoubleFourDecimal(investment.Shares)</td>
<td style=text-align:right;padding-left:8px>@formatDoubleTwoDecimal(investment.Value)</td>
</tr>
}
}
</table>
</table>
}
else
{
<table>
@if (familyData.Accounts.Count > 0) {
<tr style=vertical-align:bottom>
<th>Account</th>
<th style=padding-left:8px></th>
<th style=padding-left:8px>Type</th>
<th style=padding-left:8px>Ticker</th>
<th style=padding-left:8px;text-align:center>
@if (familyData.EODHistoricalDataApiKey != null)
{
<button @onclick=@refreshPrices title=Refresh>🔃</button>
} else {
<a href="updated-quotes">Enable<br/>updates.</a>
}
<br/>
<span>$ / share</span>
</th>
<th style=padding-left:8px>Shares</th>
<th style=padding-left:8px>$ Value</th>
</tr>
}
@foreach (var account in familyData.Accounts) {
@foreach (var investment in account.Investments) {
<tr>
<td>@((account.Custodian != null ? account.Custodian + " ": "")+ account.Note)</td>
<td style=padding-left:8px>@account.Identifier</td>
<td style=padding-left:8px>@account.AccountType</td>
<td style=padding-left:8px title=@investment.Name>@investment.Ticker</td>
<td style=text-align:right;padding-left:8px>@formatDoubleTwoDecimal(investment.Price)</td>
<td style=text-align:right;padding-left:8px>@formatDoubleFourDecimal(investment.Shares)</td>
<td style=text-align:right;padding-left:8px>@formatDoubleTwoDecimal(investment.Value)</td>
</tr>
}
}
</table>
}
<br/>
</td>
break;
Expand Down
46 changes: 46 additions & 0 deletions Shared/Models/FamilyData/FamilyData.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using DocumentFormat.OpenXml.Office.CoverPageProps;
using IRS;
using System.ComponentModel.DataAnnotations;
using System.IO;
Expand Down Expand Up @@ -337,6 +338,51 @@ public double Value {

public List<Account> Accounts { get; set; }

public List<Investment> GroupedInvestments {
get {
Dictionary<string,Investment> _GroupedInvestments = new();
foreach (var account in Accounts)
{
foreach (var investment in account.Investments)
{
if (investment.Ticker != null) {
Investment matchingInvestment = null;
if (!_GroupedInvestments.ContainsKey(investment.Ticker))
{
matchingInvestment = new Investment() { Ticker = investment.Ticker, Shares = 0.0, Price = investment.Price };
_GroupedInvestments.Add(investment.Ticker, matchingInvestment);
}
else
{
matchingInvestment = _GroupedInvestments[investment.Ticker];
}

if (investment.Shares != null) {
matchingInvestment.Shares += investment.Shares;
}
else
{
matchingInvestment.Value += investment.Value;
}
}
}
}

var listInvestments = new List<Investment>();
foreach (var key in _GroupedInvestments.Keys)
{
var investment = _GroupedInvestments[key];
if (investment.Price != null && investment.Shares != null)
{
investment.Value = investment.Price * investment.Shares;
}
listInvestments.Add(investment);
}

return listInvestments;
}
}
public string PortfolioView { get; set; }
public string? AdditionalBackground { get; set; }
public List<string> Questions { get; set; }

Expand Down

0 comments on commit 49b8910

Please sign in to comment.