Class: StockPriceImitation::Generator::Step
- Inherits:
-
Object
- Object
- StockPriceImitation::Generator::Step
- Defined in:
- lib/stock_price_imitation/generator.rb
Instance Method Summary collapse
- #closing_price ⇒ Object
- #high_price ⇒ Object
-
#initialize(seed_price, volatility) ⇒ Step
constructor
A new instance of Step.
- #low_price ⇒ Object
- #opening_price ⇒ Object
- #to_hash ⇒ Object
- #to_zero_if_negative(number) ⇒ Object
Constructor Details
#initialize(seed_price, volatility) ⇒ Step
Returns a new instance of Step.
40 41 42 43 44 45 46 47 |
# File 'lib/stock_price_imitation/generator.rb', line 40 def initialize(seed_price, volatility) bell = RandomBell.new @seed_price = seed_price prices = 2.times.map{ @seed_price * bell.rand } @low_price, @high_price = prices.sort end |
Instance Method Details
#closing_price ⇒ Object
61 62 63 |
# File 'lib/stock_price_imitation/generator.rb', line 61 def closing_price to_zero_if_negative (rand low_price..high_price) end |
#high_price ⇒ Object
53 54 55 |
# File 'lib/stock_price_imitation/generator.rb', line 53 def high_price to_zero_if_negative @high_price end |
#low_price ⇒ Object
49 50 51 |
# File 'lib/stock_price_imitation/generator.rb', line 49 def low_price to_zero_if_negative @low_price end |
#opening_price ⇒ Object
57 58 59 |
# File 'lib/stock_price_imitation/generator.rb', line 57 def opening_price to_zero_if_negative (rand low_price..high_price) end |
#to_hash ⇒ Object
73 74 75 76 77 78 79 80 |
# File 'lib/stock_price_imitation/generator.rb', line 73 def to_hash { opening_price: self.opening_price, closing_price: self.closing_price, low_price: self.low_price, high_price: self.high_price, } end |
#to_zero_if_negative(number) ⇒ Object
65 66 67 68 69 70 71 |
# File 'lib/stock_price_imitation/generator.rb', line 65 def to_zero_if_negative(number) if number < 0 return 0 end number end |