Class: RMarket::Trader
- Inherits:
-
Object
- Object
- RMarket::Trader
- Defined in:
- lib/rmarket/trader.rb
Instance Attribute Summary collapse
-
#beliefs ⇒ Object
readonly
Returns the value of attribute beliefs.
-
#cash ⇒ Object
readonly
Returns the value of attribute cash.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#shares ⇒ Object
readonly
Returns the value of attribute shares.
-
#trading_strategy ⇒ Object
Returns the value of attribute trading_strategy.
-
#value_function ⇒ Object
readonly
Returns the value of attribute value_function.
Instance Method Summary collapse
-
#initialize(cash = 0, shares = {}, value_function = nil, trading_strategy = nil, beliefs = nil, id = nil) ⇒ Trader
constructor
A new instance of Trader.
- #submit_orders(order_book) ⇒ Object
- #update_account(cash, shares, asset_label) ⇒ Object
- #update_beliefs(news) ⇒ Object
Constructor Details
#initialize(cash = 0, shares = {}, value_function = nil, trading_strategy = nil, beliefs = nil, id = nil) ⇒ Trader
Returns a new instance of Trader.
6 7 8 |
# File 'lib/rmarket/trader.rb', line 6 def initialize(cash=0, shares={}, value_function=nil, trading_strategy=nil, beliefs=nil, id=nil) @cash, @shares, @trading_strategy, @value_function, @beliefs, @id = cash, shares, trading_strategy, value_function, beliefs, id end |
Instance Attribute Details
#beliefs ⇒ Object (readonly)
Returns the value of attribute beliefs.
3 4 5 |
# File 'lib/rmarket/trader.rb', line 3 def beliefs @beliefs end |
#cash ⇒ Object (readonly)
Returns the value of attribute cash.
3 4 5 |
# File 'lib/rmarket/trader.rb', line 3 def cash @cash end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
3 4 5 |
# File 'lib/rmarket/trader.rb', line 3 def id @id end |
#shares ⇒ Object (readonly)
Returns the value of attribute shares.
3 4 5 |
# File 'lib/rmarket/trader.rb', line 3 def shares @shares end |
#trading_strategy ⇒ Object
Returns the value of attribute trading_strategy.
4 5 6 |
# File 'lib/rmarket/trader.rb', line 4 def trading_strategy @trading_strategy end |
#value_function ⇒ Object (readonly)
Returns the value of attribute value_function.
3 4 5 |
# File 'lib/rmarket/trader.rb', line 3 def value_function @value_function end |
Instance Method Details
#submit_orders(order_book) ⇒ Object
17 18 19 |
# File 'lib/rmarket/trader.rb', line 17 def submit_orders(order_book) @trading_strategy.construct_orders(@cash, @shares, @value_function, @beliefs, order_book.snapshot).each {|order| order_book.submit_order(order)} end |
#update_account(cash, shares, asset_label) ⇒ Object
10 11 12 13 |
# File 'lib/rmarket/trader.rb', line 10 def update_account(cash, shares, asset_label) @shares[asset_label] = @shares[asset_label].to_f + shares @cash += cash end |
#update_beliefs(news) ⇒ Object
15 |
# File 'lib/rmarket/trader.rb', line 15 def update_beliefs(news); @beliefs.update(news); end |