simulates price change on a stock market given supply and demand of shares
import sys
"""
Formula to simulate price change in a stock market
"""
class PriceChange(object):
def __init__(self, buy_shares, sell_shares, owned_shares, price):
assert owned_shares
assert price
assert sell_shares <= owned_shares
self.buy_shares = buy_shares
self.sell_shares = sell_shares
if self.buy_shares == self.sell_shares:
self.price_change = 0.0
return
self.owned_shares = owned_shares
self.price = price
self.start_price = price
self.bs_ratio = self.buy_shares / self.sell_shares
self.price *= self.bs_ratio
self.price_change = self.price - self.start_price
def __repr__(self):
return str(self.__dict__)
if __name__ == '__main__':
print(PriceChange(40, 10, 500, 40.5))
print(PriceChange(40, 400, 500, 40.8))
print(PriceChange(4, 1, 50, 50.0))
print(PriceChange(4432, 7584, 50032, 50.0))
print(PriceChange(3200, 2000, 7000, 100.0))
print("for splunk stock")
print(PriceChange(500000, 510000, 1014000, 123.56))
print("regular examples")
print(PriceChange(43000, 39400, 101423, 120.7))