Class: IB::PortfolioValue
Instance Method Summary
collapse
#as_table, #content_attributes, #default_attributes, #invariant_attributes, #set_attribute_defaults, #update_missing
Instance Method Details
#==(other) ⇒ Object
19
20
21
22
23
24
25
26
27
28
|
# File 'lib/models/ib/portfolio_value.rb', line 19
def == other
super(other) ||
other.is_a?(self.class) &&
market_price == other.market_price &&
average_cost == other.average_cost &&
position == other.position &&
unrealized_pnl == other.unrealized_pnl &&
realized_pnl == other.realized_pnl &&
contract == other.contract
end
|
50
51
52
53
54
55
56
|
# File 'lib/models/ib/portfolio_value.rb', line 50
def
if block_given?
[ '' , yield , 'pos', 'entry', 'market', 'value', 'unrealized', 'realized' ]
else
[ '' , '', 'pos', 'entry', 'market', 'value', 'unrealized', 'realized' ]
end
end
|
#table_row ⇒ Object
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
# File 'lib/models/ib/portfolio_value.rb', line 58
def table_row
outprice= ->( item ) { { value: item.nil? ? "--" : item , alignment: :right } }
the_account = if account.present?
if account.is_a?(String)
account + " "
else
account.account+" "
end
else
""
end
entry = average_cost.to_f / (contract.multiplier.to_i.zero? ? 1 : contract.multiplier.to_i)
[ the_account,
contract.to_human[1..-2],
outprice[position.to_i],
outprice[entry.to_f.round(3)],
outprice[market_price.to_f.round(3)],
outprice[market_value.to_f.round(2)],
unrealized_pnl.to_i.zero? ? "": outprice[unrealized_pnl],
realized_pnl.to_i.zero? ? "" : outprice[realized_pnl]
]
end
|
#to_human ⇒ Object
Also known as:
to_s
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
# File 'lib/models/ib/portfolio_value.rb', line 29
def to_human
the_account = if account.present?
if account.is_a?(String)
account + " "
else
account.account+" "
end
else
""
end
"<PortfolioValue: "+
the_account +
"Pos=#{ position.to_i } @ #{market_price.to_f.round(3)};" +
"Value=#{market_value.to_f.round(2)};PNL=" +
( unrealized_pnl.to_i.zero? ? "": "#{unrealized_pnl} unrealized;") +
( realized_pnl.to_i.zero? ? "" : "#{realized_pnl} realized;>" ) +
contract.to_human
end
|