From dc277f7c68883208a645e36160b16309e6aa1196 Mon Sep 17 00:00:00 2001 From: Kevin Hoerr Date: Tue, 21 Apr 2026 13:52:06 -0400 Subject: records.rs: Add comments for change event, fix estimated price impl --- src/app/store/records.rs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'src') 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] -- cgit v1.3