its starting to get stable
This commit is contained in:
+4
-3
@@ -4,13 +4,14 @@ spec:
|
|||||||
max_world_price: 100
|
max_world_price: 100
|
||||||
|
|
||||||
- name: "Food"
|
- name: "Food"
|
||||||
max_world_price: 5
|
max_world_price: 10
|
||||||
|
|
||||||
|
|
||||||
- name: "Grain"
|
- name: "Grain"
|
||||||
max_world_price: 5
|
max_world_price: 5
|
||||||
|
|
||||||
|
- name: "Fuel"
|
||||||
|
max_world_price: 1
|
||||||
|
|
||||||
- name: "Fruit"
|
- name: "Fruit"
|
||||||
max_world_price: 1
|
max_world_price: 1
|
||||||
|
|
||||||
@@ -3,3 +3,5 @@ spec:
|
|||||||
- name: basic
|
- name: basic
|
||||||
res:
|
res:
|
||||||
- 'Food': 1
|
- 'Food': 1
|
||||||
|
- 'Fruit': 0.1
|
||||||
|
- 'Fuel': 0.1
|
||||||
|
|||||||
+16
-6
@@ -2,19 +2,29 @@ kind: production
|
|||||||
spec:
|
spec:
|
||||||
|
|
||||||
- name: Grain
|
- name: Grain
|
||||||
amount: 10
|
amount: 100
|
||||||
prod:
|
prod:
|
||||||
- Raw_Agriculture_Plot: 1
|
- Raw_Agriculture_Plot: 1
|
||||||
- name: Fruit
|
- name: Fruit
|
||||||
amount: 10
|
amount: 10
|
||||||
prod:
|
prod:
|
||||||
- Raw_Agriculture_Plot: 1
|
- Raw_Agriculture_Plot: 1
|
||||||
|
- name: Wood
|
||||||
|
amount: 10
|
||||||
|
prod:
|
||||||
|
- Raw_Forrest: 1
|
||||||
|
|
||||||
|
- name: Fuel
|
||||||
|
amount: 10
|
||||||
|
prod:
|
||||||
|
- Wood: 1
|
||||||
|
|
||||||
- name: Food
|
- name: Food
|
||||||
amount: 5
|
amount: 5
|
||||||
prod:
|
prod:
|
||||||
- Fruit: 1
|
- Fuel: 1
|
||||||
- Grain: 1
|
- Fruit: 1
|
||||||
|
- Grain: 2
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+4
-2
@@ -6,10 +6,12 @@ spec:
|
|||||||
|
|
||||||
- name: grass
|
- name: grass
|
||||||
res:
|
res:
|
||||||
- 'Raw_Agriculture_Plot': 100
|
- 'Raw_Agriculture_Plot': 1
|
||||||
|
- 'Raw_Forrest': 1
|
||||||
|
|
||||||
- name: forrest
|
- name: forrest
|
||||||
res:
|
res:
|
||||||
- 'Raw_Agriculture_Plot': 100
|
- 'Raw_Agriculture_Plot': 1
|
||||||
|
- 'Raw_Forrest': 2
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+10
-1
@@ -12,7 +12,16 @@ services:
|
|||||||
networks:
|
networks:
|
||||||
- postgres-network
|
- postgres-network
|
||||||
|
|
||||||
|
pgadmin:
|
||||||
|
image: dpage/pgadmin4
|
||||||
|
environment:
|
||||||
|
PGADMIN_DEFAULT_EMAIL: admin@pgadmin.com
|
||||||
|
PGADMIN_DEFAULT_PASSWORD: password
|
||||||
|
PGADMIN_LISTEN_PORT: 80
|
||||||
|
ports:
|
||||||
|
- 15433:80
|
||||||
|
depends_on:
|
||||||
|
- database
|
||||||
networks:
|
networks:
|
||||||
postgres-network:
|
postgres-network:
|
||||||
driver: bridge
|
driver: bridge
|
||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -17,6 +17,7 @@ class Base_Distribution_Agent(BaseAgent,ABC):
|
|||||||
self.orders={i: {} for i in range(len(self.exchanges))}
|
self.orders={i: {} for i in range(len(self.exchanges))}
|
||||||
self.target=0
|
self.target=0
|
||||||
self.min_price=-1
|
self.min_price=-1
|
||||||
|
self.max_batch_qty=10
|
||||||
super().__init__(simulation)
|
super().__init__(simulation)
|
||||||
|
|
||||||
def set_target(self,target: int):
|
def set_target(self,target: int):
|
||||||
@@ -54,7 +55,8 @@ class Base_Distribution_Agent(BaseAgent,ABC):
|
|||||||
|
|
||||||
if not self.business.inventory[self.resource]>=amount:
|
if not self.business.inventory[self.resource]>=amount:
|
||||||
return False # we dont have enough balance
|
return False # we dont have enough balance
|
||||||
|
if amount>self.max_batch_qty:
|
||||||
|
amount=self.max_batch_qty
|
||||||
self.business.inventory[self.resource]-=amount
|
self.business.inventory[self.resource]-=amount
|
||||||
cx.add_to_account(self.id,self.resource,amount) # prepaid charge account for cx
|
cx.add_to_account(self.id,self.resource,amount) # prepaid charge account for cx
|
||||||
order=cx.submit_order(self.id,self.resource,amount,price_per,Side.SELL)
|
order=cx.submit_order(self.id,self.resource,amount,price_per,Side.SELL)
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ class Price_Believe_Distribiute_Agent(Base_Distribution_Agent):
|
|||||||
self.open_orders={i: [] for i in range(len(self.exchanges))}
|
self.open_orders={i: [] for i in range(len(self.exchanges))}
|
||||||
self.open_qty=0
|
self.open_qty=0
|
||||||
|
|
||||||
|
|
||||||
def tick(self,step,episode):
|
def tick(self,step,episode):
|
||||||
|
|
||||||
order_error=self.target_error()
|
order_error=self.target_error()
|
||||||
|
|||||||
Binary file not shown.
+1
-1
@@ -24,7 +24,7 @@ class Cell:
|
|||||||
exchange: None
|
exchange: None
|
||||||
|
|
||||||
def __init__(self,name,x,y,area,pop,demand,world) -> None:
|
def __init__(self,name,x,y,area,pop,demand,world) -> None:
|
||||||
pop=pop*1000
|
pop=pop*100
|
||||||
self.name=name
|
self.name=name
|
||||||
self.loc_x=x
|
self.loc_x=x
|
||||||
self.loc_y=y
|
self.loc_y=y
|
||||||
|
|||||||
+31
-17
@@ -270,7 +270,7 @@ class Exchange():
|
|||||||
data={}
|
data={}
|
||||||
data["cxid"]=name
|
data["cxid"]=name
|
||||||
data["episode"]=episode
|
data["episode"]=episode
|
||||||
data["step"]=step
|
#data["step"]=step
|
||||||
data["tstep"]=timepoint
|
data["tstep"]=timepoint
|
||||||
data["instrm"]=instrm
|
data["instrm"]=instrm
|
||||||
data["best_ask"]=0
|
data["best_ask"]=0
|
||||||
@@ -283,21 +283,21 @@ class Exchange():
|
|||||||
## add best ask/best bid
|
## add best ask/best bid
|
||||||
for item , value in self.best_ask.items():
|
for item , value in self.best_ask.items():
|
||||||
if value!=None:
|
if value!=None:
|
||||||
localStepDB[item]["best_ask"]=value
|
localStepDB[item]["best_ask"]=int(value)
|
||||||
for item , value in self.best_bid.items():
|
for item , value in self.best_bid.items():
|
||||||
if value!=None:
|
if value!=None:
|
||||||
localStepDB[item]["best_bid"]=value
|
localStepDB[item]["best_bid"]=int(value)
|
||||||
#demand supply
|
#demand supply
|
||||||
for item , value in self.total_demand.items():
|
for item , value in self.total_demand.items():
|
||||||
if value!=None:
|
if value!=None:
|
||||||
localStepDB[item]["total_demand"]=value
|
localStepDB[item]["total_demand"]=int(value)
|
||||||
for item , value in self.total_supply.items():
|
for item , value in self.total_supply.items():
|
||||||
if value!=None:
|
if value!=None:
|
||||||
localStepDB[item]["total_supply"]=value
|
localStepDB[item]["total_supply"]=int(value)
|
||||||
#last market rate
|
#last market rate
|
||||||
for item , value in self.market_rate.items():
|
for item , value in self.market_rate.items():
|
||||||
if value!=None:
|
if value!=None:
|
||||||
localStepDB[item]["market_rate"]=value
|
localStepDB[item]["market_rate"]=int(value)
|
||||||
|
|
||||||
if autolog:
|
if autolog:
|
||||||
for id,item in localStepDB.items():
|
for id,item in localStepDB.items():
|
||||||
@@ -305,15 +305,29 @@ class Exchange():
|
|||||||
return localStepDB
|
return localStepDB
|
||||||
|
|
||||||
def log_episode(self,name,episode):
|
def log_episode(self,name,episode):
|
||||||
for t in self.executed_trades:
|
transformed={}
|
||||||
data={}
|
|
||||||
data["id"]=uuid.uuid4()
|
for t in self.executed_trades:
|
||||||
data["cxid"]=name
|
if t.trade_side==1:
|
||||||
data["episode"]=episode
|
# will get logged twice so only log one side
|
||||||
data["order_id"]=t.order_id
|
if t.instmt not in transformed:
|
||||||
data["instmt"]=t.instmt
|
transformed[t.instmt]={}
|
||||||
data["price"]=t.trade_price
|
|
||||||
data["qty"]=t.trade_qty
|
if t.trade_price not in transformed[t.instmt]:
|
||||||
data["side"]=t.trade_side
|
transformed[t.instmt][t.trade_price]=0
|
||||||
log.EXTradeData.append(data)
|
transformed[t.instmt][t.trade_price]+=t.trade_qty
|
||||||
|
|
||||||
|
for inst,stats in transformed.items():
|
||||||
|
for price,qty in stats.items():
|
||||||
|
data={}
|
||||||
|
#data["id"]=uuid.uuid4()
|
||||||
|
data["cxid"]=name
|
||||||
|
data["episode"]=int(episode)
|
||||||
|
#data["order_id"]=t.order_id
|
||||||
|
data["instmt"]=t.instmt
|
||||||
|
data["price"]=int(price)
|
||||||
|
data["qty"]=int(qty)
|
||||||
|
|
||||||
|
#data["side"]=int(t.trade_side)
|
||||||
|
log.EXTradeData.append(data)
|
||||||
|
|
||||||
|
|||||||
+5
-4
@@ -79,8 +79,7 @@ class Simulation():
|
|||||||
agentstep=time.time()
|
agentstep=time.time()
|
||||||
for b in self.businesses:
|
for b in self.businesses:
|
||||||
b.tick(self.tick_count)
|
b.tick(self.tick_count)
|
||||||
if b.balance<=0:
|
|
||||||
self.remove_business(b.id)
|
|
||||||
busstep=time.time()
|
busstep=time.time()
|
||||||
self.tick_count+=1
|
self.tick_count+=1
|
||||||
self.log_cxs_tick(episode_length)
|
self.log_cxs_tick(episode_length)
|
||||||
@@ -103,7 +102,9 @@ class Simulation():
|
|||||||
v(self.episode_count)
|
v(self.episode_count)
|
||||||
for cell_id,cell in self.cells.items():
|
for cell_id,cell in self.cells.items():
|
||||||
cell.setup_supply_for_episode()
|
cell.setup_supply_for_episode()
|
||||||
|
for b in self.businesses:
|
||||||
|
if b.balance<=0:
|
||||||
|
self.remove_business(b.id)
|
||||||
self.tick_count=0
|
self.tick_count=0
|
||||||
self.episode_count+=1
|
self.episode_count+=1
|
||||||
|
|
||||||
@@ -170,7 +171,7 @@ class Simulation():
|
|||||||
profit[id]=0
|
profit[id]=0
|
||||||
profit[id]+=diff
|
profit[id]+=diff
|
||||||
best=None
|
best=None
|
||||||
bestv=0
|
bestv=-1000000000000
|
||||||
for k,v in profit.items():
|
for k,v in profit.items():
|
||||||
if bestv<v:
|
if bestv<v:
|
||||||
bestv=v
|
bestv=v
|
||||||
|
|||||||
+14
-10
@@ -23,19 +23,23 @@ def get_client():
|
|||||||
return write_client
|
return write_client
|
||||||
def writeEXData():
|
def writeEXData():
|
||||||
db = create_engine(posturl)
|
db = create_engine(posturl)
|
||||||
conn = db.connect()
|
|
||||||
df=pd.DataFrame(EXBooksData)
|
df=pd.DataFrame(EXBooksData)
|
||||||
df.to_sql('cx_books', con=conn, if_exists='replace',
|
types=df.dtypes
|
||||||
index=False)
|
start=time.time()
|
||||||
|
df.to_sql('cx_books', con=db, if_exists='replace',
|
||||||
|
index=False,chunksize=200000)
|
||||||
|
t1=time.time()
|
||||||
|
print(f"cx_books completed: {t1-start}/{df.size}")
|
||||||
df=pd.DataFrame(EXTradeData)
|
df=pd.DataFrame(EXTradeData)
|
||||||
df.to_sql("cx_trades",con=conn, if_exists='replace',
|
df.to_sql("cx_trades",con=db, if_exists='replace',
|
||||||
index=False)
|
index=False,chunksize=10000)
|
||||||
conn.close()
|
t2=time.time()
|
||||||
|
print(f"cx_trades completed: {t2-t1}/{df.size}")
|
||||||
|
|
||||||
def writeBusinessData():
|
def writeBusinessData():
|
||||||
db = create_engine(posturl)
|
db = create_engine(posturl)
|
||||||
conn = db.connect()
|
|
||||||
df=pd.DataFrame(BUSINESSData)
|
df=pd.DataFrame(BUSINESSData)
|
||||||
df.to_sql('business', con=conn, if_exists='replace',
|
df.to_sql('business', con=db, if_exists='replace',
|
||||||
index=False)
|
index=False,chunksize=10000)
|
||||||
conn.close()
|
print(f"business completed: {df.size}")
|
||||||
|
|||||||
Binary file not shown.
@@ -25,12 +25,12 @@ cxs=[cx]
|
|||||||
# Init World
|
# Init World
|
||||||
|
|
||||||
# Create Demand
|
# Create Demand
|
||||||
cx.submit_order(w,"Wood",0,1000,Side.BUY)
|
#cx.submit_order(w,"Wood",0,1000,Side.BUY)
|
||||||
cx.submit_order(2,"Gem",1,10,Side.SELL)
|
#cx.submit_order(2,"Gem",1,10,Side.SELL)
|
||||||
|
|
||||||
sim=Simulation()
|
sim=Simulation()
|
||||||
sim.seed(45223)
|
sim.seed(55)
|
||||||
sim.set_cells(cells)
|
sim.set_cells(cells[:10])
|
||||||
sim.reset()
|
sim.reset()
|
||||||
#sim.tick(1)
|
#sim.tick(1)
|
||||||
# create info
|
# create info
|
||||||
@@ -41,7 +41,7 @@ for a in tqdm(range(50)):
|
|||||||
for i in range(100):
|
for i in range(100):
|
||||||
sim.tick(100)
|
sim.tick(100)
|
||||||
sim.reset()
|
sim.reset()
|
||||||
sim.create_bussiness(1)
|
sim.create_bussiness(2)
|
||||||
log.writeEXData()
|
log.writeEXData()
|
||||||
log.writeBusinessData()
|
log.writeBusinessData()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user