Exemplo n.º 1
0
 def delta_hedger(self):
     tot_deltas = self.group_risk.pdelta.sum()
     cum_vol = 0
     if (self.spot_model == False) and (self.proxy_flag['delta'] == False):
         for idx, inst in enumerate(self.underliers):
             if idx == self.main_cont:
                 continue
             multiple = self.option_map[inst, 'multiple']
             cont_mth = self.option_map[inst, 'cont_mth']
             pdelta = self.group_risk[cont_mth, 'delta']
             volume = int(-pdelta / multiple + 0.5)
             cum_vol += volume
             if volume != 0:
                 curr_price = self.agent.instruments[inst].price
                 buysell = 1 if volume > 0 else -1
                 valid_time = self.agent.tick_id + 600
                 etrade = trade.XTrade( [inst], [volume], [self.hedge_config['order_type']], curr_price*buysell, [self.hedge_config['num_tick']], \
                                            valid_time, self.name, self.agent.name)
                 self.submitted_pos[inst].append(etrade)
                 self.agent.submit_trade(etrade)
     inst = self.underliers[self.main_cont]
     multiple = self.option_map[inst, 'multiple']
     tot_deltas += cum_vol
     volume = int(tot_deltas / multiple + 0.5)
     if volume != 0:
         curr_price = self.agent.instruments[inst].price
         buysell = 1 if volume > 0 else -1
         etrade = trade.XTrade( [inst], [volume], [self.hedge_config['order_type']], curr_price*buysell, [self.hedge_config['num_tick']], \
                             valid_time, self.name, self.agent.name)
         self.submitted_pos[inst].append(etrade)
         self.agent.submit_trade(etrade)
     return
Exemplo n.º 2
0
 def close_tradepos(self, idx, tradepos, price):
     start_time = self.agent.tick_id
     xtrade = trade.XTrade( instIDs = tradepos.insts, units = tradepos.volumes, \
                            vol = -tradepos.pos, limit_price = price, \
                            price_unit = self.price_unit[idx], start_time = start_time, \
                            strategy = self.name, book = str(idx))
     xtrade.set_agent(self.agent)
     exec_algo = eval(self.exec_class)(xtrade, **self.exec_args[idx])
     xtrade.set_algo(exec_algo)
     tradepos.exit_tradeid = xtrade.id
     self.submit_trade(idx, xtrade)
Exemplo n.º 3
0
 def delta_hedge(self, under):
     ndata = self.risk_table.data
     curr_pdelta = ndata['pdelta'][ndata['under'] == under].sum()
     multiple = ndata['multiple'][self.inst_map[under]]
     volume = int((self.risk_bias['pdelta'] - curr_pdelta)/multiple)
     if volume!=0:
         curr_price = self.agent.instruments[under].mid_price
         start_time = self.agent.tick_id
         xtrade = trade.XTrade([under], [1], volume, curr_price,
                               strategy=self.name,
                               book = 'DeltaHedge', agent=self.agent, start_time=start_time)
         self.submit_trade(xtrade)
Exemplo n.º 4
0
 def vega_hedge(self, opt_inst):
     ndata = self.risk_table.data
     under = ndata['under'][self.inst_map[opt_inst]]
     inst_vega = ndata['vega'][self.inst_map[opt_inst]]
     if inst_vega == 0:
         return
     multiple = ndata['multiple'][self.inst_map[opt_inst]]
     curr_pvega = ndata['pvega'][ndata['under'] == under].sum()
     volume = int((self.risk_bias['pvega'] - curr_pvega)/multiple/inst_vega)
     if volume!=0:
         curr_price = self.agent.instruments[opt_inst].mid_price
         start_time = self.agent.tick_id
         xtrade = trade.XTrade([opt_inst], [1], volume, curr_price,
                               strategy=self.name,
                               book = 'VegaHedge', agent=self.agent, start_time=start_time)
         self.submit_trade(xtrade)
Exemplo n.º 5
0
 def close_tradepos(self, idx, tradepos, price):
     start_time = self.agent.tick_id
     xtrade = trade.XTrade(tradepos.insts,
                           tradepos.volumes,
                           -tradepos.pos,
                           price,
                           price_unit=self.price_unit[idx],
                           strategy=self.name,
                           book=str(idx),
                           agent=self.agent,
                           start_time=start_time)
     exec_algo = eval(self.exec_class)(xtrade, **self.exec_args[idx])
     xtrade.set_algo(exec_algo)
     tradepos.exit_tradeid = xtrade.id
     self.submit_trade(idx, xtrade)
     return
Exemplo n.º 6
0
 def open_tradepos(self, idx, direction, price, volume=0):
     tunit = self.trade_unit[idx] if volume == 0 else volume
     start_time = self.agent.tick_id
     xtrade = trade.XTrade( instIDs = self.tradables[idx], units = self.volumes[idx], \
                            vol = direction * tunit, limit_price = price, \
                            price_unit = self.price_unit[idx], start_time = start_time, \
                            strategy=self.name, book= str(idx))
     xtrade.set_agent(self.agent)
     exec_algo = eval(self.exec_class)(xtrade, **self.exec_args[idx])
     xtrade.set_algo(exec_algo)
     tradepos = eval(self.pos_class)(insts = self.tradables[idx], \
                     volumes = self.volumes[idx], pos = direction * tunit, \
                     entry_target = price, exit_target = price, \
                     multiple = self.underlying[idx].multiple, **self.pos_args)
     tradepos.entry_tradeid = xtrade.id
     self.submit_trade(idx, xtrade)
     self.positions[idx].append(tradepos)
Exemplo n.º 7
0
 def open_tradepos(self, idx, direction, price, volume=0):
     tunit = self.trade_unit[idx] if volume == 0 else volume
     start_time = self.agent.tick_id
     xtrade = trade.XTrade(self.tradables[idx],
                           self.volumes[idx],
                           direction * tunit,
                           price,
                           price_unit=self.price_unit[idx],
                           strategy=self.name,
                           book=str(idx),
                           agent=self.agent,
                           start_time=start_time)
     exec_algo = eval(self.exec_class)(xtrade, **self.exec_args[idx])
     xtrade.set_algo(exec_algo)
     tradepos = eval(self.pos_class)(self.tradables[idx], self.volumes[idx], direction * tunit, \
                             price, price, self.underlying[idx].multiple, **self.pos_args)
     tradepos.entry_tradeid = xtrade.id
     self.submit_trade(idx, xtrade)
     self.positions[idx].append(tradepos)