mirror of
https://github.com/we-promise/sure.git
synced 2026-04-18 19:44:09 +00:00
* Prepare entry search for nested categories * Subcategory implementation * Remove caching for test stability
22 lines
513 B
Ruby
22 lines
513 B
Ruby
class Account::Trade < ApplicationRecord
|
|
include Account::Entryable, Monetizable
|
|
|
|
monetize :price
|
|
|
|
belongs_to :security
|
|
|
|
validates :qty, presence: true
|
|
validates :price, :currency, presence: true
|
|
|
|
def unrealized_gain_loss
|
|
return nil if qty.negative?
|
|
current_price = security.current_price
|
|
return nil if current_price.nil?
|
|
|
|
current_value = current_price * qty.abs
|
|
cost_basis = price_money * qty.abs
|
|
|
|
TimeSeries::Trend.new(current: current_value, previous: cost_basis)
|
|
end
|
|
end
|