示例#1
0
    def get_T_table(self):
        params = self.app.get_agent_params(['Insts'])
        self.curr_insts = params['Insts']
        inst_labels = [
            'Name', 'Price', 'BidPrice', 'BidVol', 'AskPrice', 'AskVol',
            'Volume', 'OI', 'PV', 'Delta', 'Gamma', 'Vega', 'Theta'
        ]
        under_labels = [
            'Name', 'Price', 'BidPrice', 'BidVol', 'AskPrice', 'AskVol',
            'Volume', 'OI', 'UpLimit', 'DownLimit'
        ]
        for inst in self.underliers:
            for instlbl in under_labels:
                value = self.curr_insts[inst][instlbl]
                self.root.stringvars[inst][instlbl].set(keepdigit(value, 4))
        for inst in self.option_insts:
            for instlbl in inst_labels:
                value = self.curr_insts[inst][instlbl]
                self.root.stringvars[inst][instlbl].set(keepdigit(value, 4))

        vol_labels = [
            'Expiry', 'Under', 'Df', 'Fwd', 'Atm', 'V90', 'V75', 'V25', 'V10',
            'Updated'
        ]
        params = self.app.get_agent_params(['Volgrids.' + self.name])
        results = params['Volgrids'][self.name]
        for expiry in results:
            if expiry in self.stringvars['Volgrid']:
                for vlbl in vol_labels:
                    value = results[expiry][vlbl]
                    self.stringvars['Volgrid'][expiry][vlbl].set(
                        keepdigit(value, 5))
            vn = self.volgrid.volnode[expiry]
            vn.setFwd(results[expiry]['Fwd'])
            vn.setToday(results[expiry]['Updated'])
            vn.setAtm(results[expiry]['Atm'])
            vn.setD90Vol(results[expiry]['V90'])
            vn.setD75Vol(results[expiry]['V75'])
            vn.setD25Vol(results[expiry]['V25'])
            vn.setD10Vol(results[expiry]['V10'])
            vn.initialize()

        for key in self.opt_dict:
            inst = self.opt_dict[key]
            bid_price = self.curr_insts[inst]['BidPrice']
            ask_price = self.curr_insts[inst]['AskPrice']
            idx = self.cont_mth.index(key[0])
            expiry = self.expiries[idx]
            fwd = self.volgrid.volnode[expiry].fwd_()
            strike = key[2]
            otype = key[1]
            Texp = self.volgrid.volnode[expiry].expiry_()
            bvol = pyktlib.BlackImpliedVol(bid_price, fwd, strike, self.rf,
                                           Texp, otype) if bid_price > 0 else 0
            avol = pyktlib.BlackImpliedVol(ask_price, fwd, strike, self.rf,
                                           Texp, otype) if bid_price > 0 else 0
            self.root.stringvars[inst]['BidIV'].set(keepdigit(bvol, 4))
            self.curr_insts[inst]['BidIV'] = bvol
            self.root.stringvars[inst]['AskIV'].set(keepdigit(avol, 4))
            self.curr_insts[inst]['AskIV'] = avol
示例#2
0
    def get_T_table(self):
        params = self.app.get_agent_params(['Insts'])
        inst_labels = ['Name', 'Price','BidPrice', 'BidVol','AskPrice', 'AskVol']
        under_labels = ['Name', 'Price','BidPrice','BidVol','AskPrice','AskVol','UpLimit','DownLimit']
        for inst in self.underliers:
            if inst not in self.curr_insts:
                self.curr_insts[inst] = {}
            for instlbl in under_labels:
                value = params['Insts'][inst][instlbl]
                self.curr_insts[inst][instlbl] = value
                #value = type2str(value, value.__class__.__name__)
                self.root.stringvars[inst][instlbl].set(keepdigit(value,4))        
        for inst in self.opt_dict.values():
            if inst not in self.curr_insts:
                self.curr_insts[inst] = {}
            for instlbl in inst_labels:
                value = params['Insts'][inst][instlbl]
                self.curr_insts[inst][instlbl] = value
                #value = type2str(value, value.__class__.__name__)
                self.root.stringvars[inst][instlbl].set(keepdigit(value,4))

        vol_labels = ['Expiry', 'Under', 'Df', 'Fwd', 'Atm', 'V90', 'V75', 'V25', 'V10','Updated']
        params = self.app.get_strat_params(self.name, ['Volgrid'])
        for expiry in params['Volgrid']:
            if expiry in self.stringvars['Volgrid']:
                for vlbl in vol_labels:
                    value = params['Volgrid'][expiry][vlbl]
                    #value = type2str(value, value.__class__.__name__)
                    self.stringvars['Volgrid'][expiry][vlbl].set(keepdigit(value,5))
            self.volgrids[expiry].setFwd(params['Volgrid'][expiry]['Fwd'])
            self.volgrids[expiry].setAtm(params['Volgrid'][expiry]['Atm'])
            self.volgrids[expiry].setD90Vol(params['Volgrid'][expiry]['V90'])
            self.volgrids[expiry].setD75Vol(params['Volgrid'][expiry]['V75'])
            self.volgrids[expiry].setD25Vol(params['Volgrid'][expiry]['V25'])
            self.volgrids[expiry].setD10Vol(params['Volgrid'][expiry]['V10'])
            self.volgrids[expiry].initialize()
            
        for key in self.opt_dict:
            inst = self.opt_dict[key]
            bid_price = self.curr_insts[inst]['BidPrice']
            ask_price = self.curr_insts[inst]['AskPrice']
            idx = self.cont_mth.index(key[1])
            expiry = self.expiries[idx]
            fwd = self.volgrids[expiry].fwd_()
            strike = key[3]
            otype = key[2]
            Texp =  self.volgrids[expiry].expiry_()
            bvol = pyktlib.BlackImpliedVol(bid_price, fwd, strike, self.rf, Texp, otype) if bid_price > 0 else 0
            avol = pyktlib.BlackImpliedVol(ask_price, fwd, strike, self.rf, Texp, otype) if bid_price > 0 else 0 
            self.stringvars[inst]['BidIV'].set(keepdigit(bvol,4))
            self.curr_insts[inst]['BidIV'] = bvol
            self.stringvars[inst]['AskIV'].set(keepdigit(avol,4))
            self.curr_insts[inst]['AskIV'] = avol
        return