Class: RMarket::Trader

Inherits:
Object
  • Object
show all
Defined in:
lib/rmarket/trader.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#beliefsObject (readonly)

Returns the value of attribute beliefs.



3
4
5
# File 'lib/rmarket/trader.rb', line 3

def beliefs
  @beliefs
end

#cashObject (readonly)

Returns the value of attribute cash.



3
4
5
# File 'lib/rmarket/trader.rb', line 3

def cash
  @cash
end

#idObject (readonly)

Returns the value of attribute id.



3
4
5
# File 'lib/rmarket/trader.rb', line 3

def id
  @id
end

#sharesObject (readonly)

Returns the value of attribute shares.



3
4
5
# File 'lib/rmarket/trader.rb', line 3

def shares
  @shares
end

#trading_strategyObject

Returns the value of attribute trading_strategy.



4
5
6
# File 'lib/rmarket/trader.rb', line 4

def trading_strategy
  @trading_strategy
end

#value_functionObject (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 (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