aboutsummaryrefslogtreecommitdiff
path: root/src/app/store
diff options
context:
space:
mode:
authorKevin Hoerr <kjhoerr@submelon.dev>2026-04-21 13:52:06 -0400
committerKevin Hoerr <kjhoerr@submelon.dev>2026-04-21 13:52:06 -0400
commitdc277f7c68883208a645e36160b16309e6aa1196 (patch)
treeb7aa7b0f8a0417658bb842b450214f18d153b7e8 /src/app/store
parent754f2aab52542f0ff9097a9e7abe863d78b34779 (diff)
downloadequity-tracker-dc277f7c68883208a645e36160b16309e6aa1196.tar.gz
equity-tracker-dc277f7c68883208a645e36160b16309e6aa1196.tar.bz2
equity-tracker-dc277f7c68883208a645e36160b16309e6aa1196.zip
records.rs: Add comments for change event, fix estimated price impl
Diffstat (limited to 'src/app/store')
-rw-r--r--src/app/store/records.rs15
1 files changed, 11 insertions, 4 deletions
diff --git a/src/app/store/records.rs b/src/app/store/records.rs
index 682f676..3357a02 100644
--- a/src/app/store/records.rs
+++ b/src/app/store/records.rs
@@ -78,12 +78,19 @@ impl std::fmt::Display for ChangeEventType {
/// An immutable record describing a quantative change for a symbolized
/// equity attributed to an account.
pub struct EquityChangeEvent {
+ /// The internal ID representing the change event
pub equity_change_event_id: usize,
+ /// The internal ID of the fiduciary account
pub fiduciary_account_id: u8,
+ /// The internal ID of the equity symbol
pub equity_symbol_id: usize,
+ /// The quantity of shares that changed hands
pub equity_change_quantity: BigDecimal,
+ /// Cost basis of the event; in more simple terms, this was how much monetarily was actually bought or sold
pub equity_change_cost_basis: BigDecimal,
+ /// The type of the event: BUY (purchase of shares), or SELL (sale of shares)
pub equity_change_type: ChangeEventType,
+ /// The precise time the event occurred
pub equity_change_timestamp: DateTime,
}
@@ -92,7 +99,7 @@ impl EquityChangeEvent {
/// Provides an estimate of the numerated change based on the cost basis
/// of the equity and the quantity
pub fn estimated_price(&self) -> BigDecimal {
- DECIMAL_CONTEXT.multiply(&self.equity_change_cost_basis, &self.equity_change_quantity)
+ DECIMAL_CONTEXT.multiply(&self.equity_change_cost_basis, &DECIMAL_CONTEXT.invert(&self.equity_change_quantity))
}
/// Provides the quantity of the event relativized by the event type's score
@@ -141,7 +148,7 @@ mod tests {
equity_change_timestamp: chrono::Local::now().to_utc(),
};
- assert_eq!(nat(event.estimated_price()).to_plain_string(), "10.35");
+ assert_eq!(nat(event.estimated_price()).to_plain_string(), "662.40");
}
#[test]
@@ -156,8 +163,8 @@ mod tests {
equity_change_timestamp: chrono::Local::now().to_utc(),
};
- // actual: 1299.0796728
- assert_eq!(nat(event.estimated_price()).to_plain_string(), "1299.08");
+ // actual: 0.171127379371
+ assert_eq!(nat(event.estimated_price()).to_plain_string(), "0.17");
}
#[test]