Skip to content

Commit

Permalink
add percent change and last updated
Browse files Browse the repository at this point in the history
  • Loading branch information
rrelyea committed Jun 21, 2023
1 parent c36fbb0 commit 81be466
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
22 changes: 21 additions & 1 deletion Pages/Portfolio.razor
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,8 @@ Portfolio@(stepPath==null?": review":": "+stepPath.Replace('-',' ')) - bogle.too
</th>
<th style=padding-left:8px>Quantity</th>
<th style=padding-left:8px>Balance</th>
<th style=padding-left:8px>% change</th>
<th style=padding-left:8px>as of</th>
</tr>
}
@foreach (var investment in familyData.GroupedInvestments) {
Expand All @@ -182,6 +184,8 @@ Portfolio@(stepPath==null?": review":": "+stepPath.Replace('-',' ')) - bogle.too
<td style=text-align:right;padding-left:8px>@formatMoney(investment.Price)</td>
<td style=text-align:right;padding-left:8px>@formatDoubleFourDecimal(investment.Shares)</td>
<td style=text-align:right;padding-left:8px>@formatMoney(investment.Value)</td>
<td style=text-align:right;padding-left:8px>@formatPercent3(investment.PercentChange)</td>
<td style=text-align:right;padding-left:8px>@investment.LastUpdated</td>
</tr>
}
</table>
Expand All @@ -207,6 +211,8 @@ Portfolio@(stepPath==null?": review":": "+stepPath.Replace('-',' ')) - bogle.too
</th>
<th style=padding-left:8px>Quantity</th>
<th style=padding-left:8px>Balance</th>
<th style=padding-left:8px>% change</th>
<th style=padding-left:8px>as of</th>
</tr>
}
@foreach (var account in familyData.Accounts) {
Expand All @@ -219,6 +225,8 @@ Portfolio@(stepPath==null?": review":": "+stepPath.Replace('-',' ')) - bogle.too
<td style=text-align:right;padding-left:8px>@formatMoney(investment.Price)</td>
<td style=text-align:right;padding-left:8px>@formatDoubleFourDecimal(investment.Shares)</td>
<td style=text-align:right;padding-left:8px>@formatMoney(investment.Value)</td>
<td style=text-align:right;padding-left:8px>@formatPercent3(investment.PercentChange)</td>
<td style=text-align:right;padding-left:8px>@investment.LastUpdated</td>
</tr>
}
}
Expand Down Expand Up @@ -1048,7 +1056,14 @@ Portfolio@(stepPath==null?": review":": "+stepPath.Replace('-',' ')) - bogle.too
investment.Value = investment.Price * investment.Shares;
}
}

public static DateTime? UnixTimeStampToDateTime( int? unixTimeStamp )
{
if (!unixTimeStamp.HasValue) return null;
// Unix timestamp is seconds past epoch
DateTime dateTime = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);
dateTime = dateTime.AddSeconds( unixTimeStamp ?? 0 ).ToLocalTime();
return dateTime;
}
private async Task UpdateInvestmentsPrice(string ticker, List<Investment> investments)
{
if (!string.IsNullOrEmpty(familyData.EODHistoricalDataApiKey)) {
Expand All @@ -1057,6 +1072,11 @@ Portfolio@(stepPath==null?": review":": "+stepPath.Replace('-',' ')) - bogle.too
if (quoteData?.Close != null) {
foreach (var investment in investments) {
investment.Price = quoteData.Close;
investment.PreviousClose = quoteData.PreviousClose;
investment.PercentChange = quoteData.ChangeP;
if (quoteData.Timestamp != null) {
investment.LastUpdated = UnixTimeStampToDateTime(quoteData.Timestamp);
}
investment.Value = investment.Price * investment.Shares;
}
}
Expand Down
2 changes: 1 addition & 1 deletion Shared/Models/FamilyData/FamilyData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ public List<Investment> GroupedInvestments {
Investment? matchingInvestment;
if (!_GroupedInvestments.ContainsKey(key))
{
matchingInvestment = new Investment() { Name = investment.Name, Ticker = investment.Ticker, Shares = 0.0, Price = investment.Price, Value = 0.0 };
matchingInvestment = new Investment() { Name = investment.Name, Ticker = investment.Ticker, PercentChange = investment.PercentChange, LastUpdated = investment.LastUpdated, Shares = 0.0, Price = investment.Price, Value = 0.0 };
_GroupedInvestments.Add(key, matchingInvestment);
}
else
Expand Down
3 changes: 3 additions & 0 deletions Shared/Models/FamilyData/Investment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ public double? ExpenseRatio {
public double? Shares { get; set; }
public double? CostBasis { get; set; }
public double? Price { get; set; }
public double? PreviousClose { get; set; }
public double? PercentChange { get; set; }
public DateTime? LastUpdated { get; set; }
public double? Value { get; set; }
[JsonIgnore]
public double Percentage { get; set; }
Expand Down

0 comments on commit 81be466

Please sign in to comment.