class Market < ActiveRecord::Base belongs_to :team has_many :holdings def b # the market depth return 1000.to_f end def value(num_shares) if num_shares < 0 real_price = 1 - price else real_price = price end num_shares = -num_shares return ( b * Math.log( Math.exp( num_shares.to_f / b ) * real_price + ( 1 - real_price) ) ).abs end def cost(num_shares) if num_shares < 0 num_shares = -num_shares real_price = 1 - price else real_price = price end return b * Math.log( Math.exp( num_shares.to_f / b ) * real_price + ( 1-real_price) ) end def num_shares(wager) if wager < 0 real_price = 1 - price else real_price = price end shares = b*Math.log((real_price+Math.exp(wager.abs/b)-1)/real_price) if wager < 0 return -shares else return shares end end end