-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
46 lines (34 loc) · 1.41 KB
/
main.py
File metadata and controls
46 lines (34 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import random
from models import Session, IPO, Bid, InvestorType
from engine import IPOEngine
from auditor import Auditor
def run_simulation():
session = Session()
engine = IPOEngine(session)
auditor = Auditor(session)
new_ipo = IPO(symbol="TECH_AI", total_shares_offered=10000, price_band_low=100, price_band_high=120)
session.add(new_ipo)
session.commit()
print(f"Created IPO: {new_ipo.symbol} (ID: {new_ipo.id})")
print("Simulating Bid Ingestion...")
investors = [f"INV_{i}" for i in range(1001, 1101)]
my_bid_id = None
for inv in investors:
category = random.choice([InvestorType.RETAIL, InvestorType.HNI, InvestorType.QIB])
price = random.choice([100, 110, 115, 120])
qty = random.randint(10, 500)
try:
bid_id = engine.place_bid(new_ipo.id, inv, category, price, qty)
if inv == "INV_1050":
my_bid_id = bid_id
print(f">> Placed OUR Bid (ID: {bid_id}): {qty} shares @ {price}")
except ValueError as e:
pass
engine.close_book_and_allocate(new_ipo.id)
if my_bid_id:
auditor.explain_allocation(my_bid_id)
rejected_bid = session.query(Bid).filter(Bid.rejection_reason.like("%Price%")).first()
if rejected_bid:
auditor.explain_allocation(rejected_bid.id)
if __name__ == "__main__":
run_simulation()