Class: ROI::RentabilityLine

Inherits:
Struct
  • Object
show all
Defined in:
lib/roi/rentability_line.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#daily_resultObject

Returns the value of attribute daily_result

Returns:

  • (Object)

    the current value of daily_result



2
3
4
# File 'lib/roi/rentability_line.rb', line 2

def daily_result
  @daily_result
end

#dateObject

Returns the value of attribute date

Returns:

  • (Object)

    the current value of date



2
3
4
# File 'lib/roi/rentability_line.rb', line 2

def date
  @date
end

#have_positionObject

Returns the value of attribute have_position

Returns:

  • (Object)

    the current value of have_position



2
3
4
# File 'lib/roi/rentability_line.rb', line 2

def have_position
  @have_position
end

#rentabilityObject

Returns the value of attribute rentability

Returns:

  • (Object)

    the current value of rentability



2
3
4
# File 'lib/roi/rentability_line.rb', line 2

def rentability
  @rentability
end

#shareObject

Returns the value of attribute share

Returns:

  • (Object)

    the current value of share



2
3
4
# File 'lib/roi/rentability_line.rb', line 2

def share
  @share
end

#total_balanceObject

Returns the value of attribute total_balance

Returns:

  • (Object)

    the current value of 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