def sell_handler(self,tender,session,tick):
     print('hit the sell handler')
     price = tender['price']
     volume = tender['quantity']
     ticker = tender['ticker']
     curr_price = self.data[ticker]['current_price']
     volatility = self.data[ticker]['std']
     max_vol = self.data[ticker]['estimated_max_vol']
     print(price,volume,ticker)
     print('Current Price',curr_price)
     print('Estimated Volatility',volatility)
     print('Maximum Volume', max_vol)
     print('Tick', tick)
     if tick < 200:
         time = 100
     else:
         time = 300-tick
     temp_impact = 0.142*(volatility)*(volume/(max_vol*(time/300)))**(0.6)
     expected_cost = volume*price*temp_impact
     expected_profit = volume*(price-curr_price)
     print('Expected Cost', expected_cost)
     print('Expected Profit', expected_profit)
     print(temp_impact) 
     if expected_profit>expected_cost:
         if self.limit_check(tender)== True:
             self.trade_limit[ticker] = True
             api_calls.accept_tender(session, tender['tender_id'])
             if self.data[ticker]['current_stock']<0:
                 print("Stock Already Exists adding additional stock")
                 print("Previous Time to Sell", self.data[ticker]['time_to_sell'])
                 new_volume = self.data[ticker]['current_stock'] - volume
                 print("Volume", volume)
                 print("New_Volume", new_volume)
                 print("Time", time)
                 self.data[ticker]['time_to_sell'] = (-volume/new_volume)*time + abs((self.data[ticker]['current_stock']/new_volume))*self.data[ticker]['time_to_sell'] 
                 self.data[ticker]['current_stock'] = new_volume
                 self.data[ticker]['time_to_sell'] = round(self.data[ticker]['time_to_sell'],0)
                 print("Now Time to Sell", self.data[ticker]['time_to_sell'])
             elif self.data[ticker]['current_stock']==0:
                 self.data[ticker]['current_stock'] = -volume
                 self.data[ticker]['time_to_sell'] = time
             else:
                 print("Can offset stock")
                 print("Previous Time to Sell", self.data[ticker]['time_to_sell'])
                 #if we have more than we can offload
                 if abs(self.data[ticker]['current_stock']) > volume:
                     old_volume = abs(self.data[ticker]['current_stock'])
                     self.data[ticker]['current_stock'] = self.data[ticker]['current_stock'] - volume
                     self.data[ticker]['time_to_sell'] = (self.data[ticker]['current_stock']/old_volume)*self.data[ticker]['time_to_sell']
                 else:
                     self.data[ticker]['current_stock'] = self.data[ticker]['current_stock'] - volume
                     self.data[ticker]['time_to_sell'] = (self.data[ticker]['current_stock']/-volume)*time
                 self.data[ticker]['time_to_sell'] = round(self.data[ticker]['time_to_sell'],0)
                 print("Now Time to Sell", self.data[ticker]['time_to_sell'])
         else:
             print("Rejected Due to Limit Constraints")
Beispiel #2
0
 def buy_handler(self, tender, session):
     print('hit the buy handler')
     price = tender['price']
     volume = tender['quantity']
     ticker = tender['ticker']
     print(price, volume, ticker)
     print('Calculated VWAP', self.data[ticker]['VWAP'])
     if self.limit_check(tender):
         if price <= self.data[ticker]['VWAP']:
             if (volume + self.data[ticker]['current_stock']
                 ) < self.data[ticker]['estimated_max_vol'] / 10:
                 api_calls.accept_tender(session, tender['tender_id'])
                 self.data[ticker]['current_stock'] += volume
             else:
                 print('failed due to stock constaints')
         else:
             print('failed due to VWAP constaints')
     else:
         print('failed due to limit constaints')
 def buy_handler(self, tender, session, tick):
     print('hit the buy handler')
     price = tender['price']
     volume = tender['quantity']
     ticker = tender['ticker']
     curr_price = self.data[ticker]['current_price']
     volatility = self.data[ticker]['std']
     max_vol = self.data[ticker]['estimated_max_vol']
     print(price, volume, ticker)
     print('Current Price', curr_price)
     print('Estimated Volatility', volatility)
     print('Maximum Volume', max_vol)
     print('Tick', tick)
     if tick < 240:
         time = 60
     else:
         time = 300 - tick
     temp_impact = 0.142 * (volatility) * (volume / (max_vol *
                                                     (time / 300)))**(0.6)
     expected_cost = volume * price * temp_impact
     expected_profit = volume * (curr_price - price)
     print('Expected Cost', expected_cost)
     print('Expected Profit', expected_profit)
     if expected_profit > expected_cost:
         if self.limit_check(tender) == True:
             api_calls.accept_tender(session, tender['tender_id'])
             if self.data[ticker]['current_stock'] > 0:
                 print("Stock Already Exists adding additional stock")
                 print("Previous Time to Sell",
                       self.data[ticker]['time_to_sell'])
                 new_volume = self.data[ticker]['current_stock'] + volume
                 print("Volume", volume)
                 print("New_Volume", new_volume)
                 print("Time", time)
                 self.data[ticker]['time_to_sell'] = (
                     volume / new_volume) * time + (
                         self.data[ticker]['current_stock'] /
                         new_volume) * self.data[ticker]['time_to_sell']
                 self.data[ticker]['current_stock'] = new_volume
                 self.data[ticker]['time_to_sell'] = round(
                     self.data[ticker]['time_to_sell'], 0)
                 print("Time to sell now",
                       self.data[ticker]['time_to_sell'])
             elif self.data[ticker]['current_stock'] == 0:
                 self.data[ticker]['current_stock'] = volume
                 self.data[ticker]['time_to_sell'] = time
             else:
                 print("Negative stock exists offsetting")
                 print("Previous Time to Sell",
                       self.data[ticker]['time_to_sell'])
                 if abs(self.data[ticker]['current_stock']) > volume:
                     old_volume = abs(self.data[ticker]['current_stock'])
                     self.data[ticker]['current_stock'] = self.data[ticker][
                         'current_stock'] + volume
                     self.data[ticker]['time_to_sell'] = (
                         self.data[ticker]['current_stock'] /
                         old_volume) * self.data[ticker]['time_to_sell']
                 else:
                     self.data[ticker]['current_stock'] = self.data[ticker][
                         'current_stock'] + volume
                     self.data[ticker]['time_to_sell'] = (
                         self.data[ticker]['current_stock'] / volume) * time
                 self.data[ticker]['time_to_sell'] = round(
                     self.data[ticker]['time_to_sell'], 0)
                 print("Time to sell now",
                       self.data[ticker]['time_to_sell'])
         else:
             print("Rejected Due to Limit Constraints")