Class: ROI::RentabilityLine
- Inherits:
-
Struct
- Object
- Struct
- ROI::RentabilityLine
- Defined in:
- lib/roi/rentability_line.rb
Instance Attribute Summary collapse
-
#daily_result ⇒ Object
Returns the value of attribute daily_result.
-
#date ⇒ Object
Returns the value of attribute date.
-
#have_position ⇒ Object
Returns the value of attribute have_position.
-
#rentability ⇒ Object
Returns the value of attribute rentability.
-
#share ⇒ Object
Returns the value of attribute share.
-
#total_balance ⇒ Object
Returns the value of attribute total_balance.
Class Method Summary collapse
- .build(date: nil, share: 1, have_position: false) ⇒ Object
- .create(date, assets, last_balance, last_share) ⇒ Object
Instance Attribute Details
#daily_result ⇒ Object
Returns the value of attribute daily_result
2 3 4 |
# File 'lib/roi/rentability_line.rb', line 2 def daily_result @daily_result end |
#date ⇒ Object
Returns the value of attribute date
2 3 4 |
# File 'lib/roi/rentability_line.rb', line 2 def date @date end |
#have_position ⇒ Object
Returns the value of attribute have_position
2 3 4 |
# File 'lib/roi/rentability_line.rb', line 2 def have_position @have_position end |
#rentability ⇒ Object
Returns the value of attribute rentability
2 3 4 |
# File 'lib/roi/rentability_line.rb', line 2 def rentability @rentability end |
#share ⇒ Object
Returns the value of attribute share
2 3 4 |
# File 'lib/roi/rentability_line.rb', line 2 def share @share end |
#total_balance ⇒ Object
Returns the value of attribute total_balance
2 3 4 |
# File 'lib/roi/rentability_line.rb', line 2 def total_balance @total_balance end |
Class Method Details
.build(date: nil, share: 1, have_position: false) ⇒ Object
5 6 7 |
# File 'lib/roi/rentability_line.rb', line 5 def self.build(date: nil, share: 1, have_position: false) self.new(date, nil, nil, share, have_position, nil) end |
.create(date, assets, last_balance, last_share) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/roi/rentability_line.rb', line 9 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 |