Sha256: 3e25216ef70ff67326be12357b7dbeda47e33a9fed624430f32b9a8d08afd981
Contents?: true
Size: 730 Bytes
Versions: 15
Compression:
Stored size: 730 Bytes
Contents
module ROI class RentabilityLine < Struct.new( :date, :rentability, :daily_result, :share, :have_position, :total_balance) def self.build(date: nil, share: 1, have_position: false) self.new(date, nil, nil, share, have_position, nil) end def self.create(date, assets, last_balance, last_share) line = build(date: date, share: last_share || 1) line.total_balance = assets.map(&:value).inject(:+) if last_balance.to_f > 0 line.daily_result = assets.map(&:daily_result).inject(:+) line.rentability = line.daily_result / last_balance line.share = (last_share * (1 + line.rentability)).round(8) line.have_position = true end line end end end
Version data entries
15 entries across 15 versions & 1 rubygems