Class: SQA::Portfolio::Position
- Inherits:
-
Struct
- Object
- Struct
- SQA::Portfolio::Position
- Defined in:
- lib/sqa/portfolio.rb
Overview
Represents a single position in the portfolio
Instance Attribute Summary collapse
-
#avg_cost ⇒ Object
Returns the value of attribute avg_cost.
-
#shares ⇒ Object
Returns the value of attribute shares.
-
#ticker ⇒ Object
Returns the value of attribute ticker.
-
#total_cost ⇒ Object
Returns the value of attribute total_cost.
Instance Method Summary collapse
- #profit_loss(current_price) ⇒ Object
- #profit_loss_percent(current_price) ⇒ Object
- #value(current_price) ⇒ Object
Instance Attribute Details
#avg_cost ⇒ Object
Returns the value of attribute avg_cost
11 12 13 |
# File 'lib/sqa/portfolio.rb', line 11 def avg_cost @avg_cost end |
#shares ⇒ Object
Returns the value of attribute shares
11 12 13 |
# File 'lib/sqa/portfolio.rb', line 11 def shares @shares end |
#ticker ⇒ Object
Returns the value of attribute ticker
11 12 13 |
# File 'lib/sqa/portfolio.rb', line 11 def ticker @ticker end |
#total_cost ⇒ Object
Returns the value of attribute total_cost
11 12 13 |
# File 'lib/sqa/portfolio.rb', line 11 def total_cost @total_cost end |
Instance Method Details
#profit_loss(current_price) ⇒ Object
16 17 18 |
# File 'lib/sqa/portfolio.rb', line 16 def profit_loss(current_price) (current_price - avg_cost) * shares end |
#profit_loss_percent(current_price) ⇒ Object
20 21 22 23 |
# File 'lib/sqa/portfolio.rb', line 20 def profit_loss_percent(current_price) return 0.0 if avg_cost.zero? ((current_price - avg_cost) / avg_cost) * 100.0 end |
#value(current_price) ⇒ Object
12 13 14 |
# File 'lib/sqa/portfolio.rb', line 12 def value(current_price) shares * current_price end |