コード例 #1
0
ファイル: agent_gui.py プロジェクト: ifzz/pyktrader2
    def __init__(self, vg, app, master):
        all_insts = app.agent.instruments
        self.root = master
        self.name = vg.name
        self.app = app
        self.expiries = vg.underlier.keys()
        self.expiries.sort()
        self.underliers = [vg.underlier[expiry] for expiry in self.expiries] 
        self.option_insts = list(set().union(*vg.option_insts.values()))
        self.spot_model = vg.spot_model
        self.cont_mth = list(set([ all_insts[inst].cont_mth for inst in self.option_insts]))
        self.cont_mth.sort()
        self.strikes = [list(set([ all_insts[inst].strike for inst in vg.option_insts[expiry]])) for expiry in self.expiries]
        for idx in range(len(self.strikes)):
            self.strikes[idx].sort()
        self.opt_dict = {}
        for inst in self.option_insts:
            key = (all_insts[inst].cont_mth, all_insts[inst].otype, all_insts[inst].strike)
            self.opt_dict[key] = inst
        self.canvas = None
        self.pos_canvas = None
        self.frame = None
        self.pos_frame = None

        #vol_labels = ['Expiry', 'Under', 'Df', 'Fwd', 'Atm', 'V90', 'V75', 'V25', 'V10', 'Updated']
        self.volgrid = instrument.copy_volgrid(vg)
        self.curr_insts = {} 
        self.rf = app.agent.irate
        self.entries = {}
        self.option_map = {}
        self.group_risk = {}
        self.stringvars = {'Insts':{}, 'Volgrid':{}}
        self.entry_fields = []
        self.status_fields = [] 
        self.field_types = {}
        inst_labels = ['Name', 'Price', 'BidPrice', 'BidVol', 'BidIV', 'AskPrice','AskVol','AskIV', 'Volume', 'OI', 'PV', 'Delta', 'Gamma','Vega', 'Theta']
        inst_types  = ['string','float', 'float', 'int', 'float', 'float', 'int','float','float', 'int', 'int', 'float', 'float', 'float', 'float', 'float']
        for inst in self.option_insts:
            if inst not in self.root.stringvars:
                self.root.stringvars[inst] = {}
            for lbl, itype in zip(inst_labels, inst_types):
                self.root.stringvars[inst][lbl] = get_type_var(itype)                
        under_labels = ['Name', 'Price','BidPrice','BidVol','AskPrice','AskVol','UpLimit','DownLimit', 'Volume', 'OI']
        under_types = ['string', 'float', 'float', 'int', 'float', 'int', 'float', 'float',  'int', 'int']        
        for inst in list(set(self.underliers)):
            if inst not in self.root.stringvars:
                self.root.stringvars[inst] = {}
            for ulbl, utype in zip(under_labels, under_types):
                self.root.stringvars[inst][ulbl] = get_type_var(utype)                 
        vol_labels = ['Expiry', 'Under', 'Df', 'Fwd', 'Atm', 'V90', 'V75', 'V25', 'V10','Updated']
        vol_types =  ['string', 'string', 'float','float','float','float','float','float','float','float']
        for expiry in self.expiries:
            self.stringvars['Volgrid'][expiry] = {}
            for vlbl, vtype in zip(vol_labels, vol_types):
                self.stringvars['Volgrid'][expiry][vlbl] = get_type_var(vtype)
コード例 #2
0
ファイル: agent_gui.py プロジェクト: afanxia/pyktrader
    def __init__(self, vg, app, master):
        all_insts = app.agent.instruments
        self.root = master
        self.name = vg.name
        self.app = app
        self.expiries = vg.underlier.keys()
        self.expiries.sort()
        self.underliers = [vg.underlier[expiry] for expiry in self.expiries] 
        self.option_insts = list(set().union(*vg.option_insts.values()))
        self.spot_model = vg.spot_model
        self.cont_mth = list(set([ all_insts[inst].cont_mth for inst in self.option_insts]))
        self.cont_mth.sort()
        self.strikes = [list(set([ all_insts[inst].strike for inst in vg.option_insts[expiry]])) for expiry in self.expiries]
        for idx in range(len(self.strikes)):
            self.strikes[idx].sort()
        self.opt_dict = {}
        for inst in self.option_insts:
            key = (all_insts[inst].cont_mth, all_insts[inst].otype, all_insts[inst].strike)
            self.opt_dict[key] = inst
        self.canvas = None
        self.pos_canvas = None
        self.frame = None
        self.pos_frame = None

        #vol_labels = ['Expiry', 'Under', 'Df', 'Fwd', 'Atm', 'V90', 'V75', 'V25', 'V10', 'Updated']
        self.volgrid = instrument.copy_volgrid(vg)
        self.curr_insts = {} 
        self.rf = app.agent.irate
        self.entries = {}
        self.option_map = {}
        self.group_risk = {}
        self.stringvars = {'Insts':{}, 'Volgrid':{}}
        self.entry_fields = []
        self.status_fields = [] 
        self.field_types = {}
        inst_labels = ['Name', 'Price', 'BidPrice', 'BidVol', 'BidIV', 'AskPrice','AskVol','AskIV', 'Volume', 'OI', 'PV', 'Delta', 'Gamma','Vega', 'Theta']
        inst_types  = ['string','float', 'float', 'int', 'float', 'float', 'int','float','float', 'int', 'int', 'float', 'float', 'float', 'float', 'float']
        for inst in self.option_insts:
            if inst not in self.root.stringvars:
                self.root.stringvars[inst] = {}
            for lbl, itype in zip(inst_labels, inst_types):
                self.root.stringvars[inst][lbl] = get_type_var(itype)                
        under_labels = ['Name', 'Price','BidPrice','BidVol','AskPrice','AskVol','UpLimit','DownLimit', 'Volume', 'OI']
        under_types = ['string', 'float', 'float', 'int', 'float', 'int', 'float', 'float',  'int', 'int']        
        for inst in list(set(self.underliers)):
            if inst not in self.root.stringvars:
                self.root.stringvars[inst] = {}
            for ulbl, utype in zip(under_labels, under_types):
                self.root.stringvars[inst][ulbl] = get_type_var(utype)                 
        vol_labels = ['Expiry', 'Under', 'Df', 'Fwd', 'Atm', 'V90', 'V75', 'V25', 'V10','Updated']
        vol_types =  ['string', 'string', 'float','float','float','float','float','float','float','float']
        for expiry in self.expiries:
            self.stringvars['Volgrid'][expiry] = {}
            for vlbl, vtype in zip(vol_labels, vol_types):
                self.stringvars['Volgrid'][expiry][vlbl] = get_type_var(vtype)
コード例 #3
0
ファイル: agent_gui.py プロジェクト: winning1120xx/pyktrader
    def __init__(self, vg, app, master):
        all_insts = app.agent.instruments
        self.root = master
        self.name = vg.name
        self.app = app
        self.expiries = vg.underlier.keys()
        self.expiries.sort()
        self.underliers = [vg.underlier[expiry] for expiry in self.expiries]
        self.option_insts = list(set().union(*vg.option_insts.values()))
        self.spot_model = vg.spot_model
        self.cont_mth = list(set([all_insts[inst].cont_mth for inst in self.option_insts]))
        self.cont_mth.sort()
        self.strikes = [
            list(set([all_insts[inst].strike for inst in vg.option_insts[expiry]])) for expiry in self.expiries
        ]
        for idx in range(len(self.strikes)):
            self.strikes[idx].sort()
        self.opt_dict = {}
        for inst in self.option_insts:
            key = (all_insts[inst].cont_mth, all_insts[inst].otype, all_insts[inst].strike)
            self.opt_dict[key] = inst
        self.canvas = None
        self.pos_canvas = None
        self.frame = None
        self.pos_frame = None

        # vol_labels = ['Expiry', 'Under', 'Df', 'Fwd', 'Atm', 'V90', 'V75', 'V25', 'V10', 'Updated']
        self.volgrid = instrument.copy_volgrid(vg)
        self.curr_insts = {}
        self.rf = app.agent.irate
        self.entries = {}
        self.option_map = {}
        self.group_risk = {}
        self.stringvars = {"Insts": {}, "Volgrid": {}}
        self.entry_fields = []
        self.status_fields = []
        self.field_types = {}
        inst_labels = [
            "Name",
            "Price",
            "BidPrice",
            "BidVol",
            "BidIV",
            "AskPrice",
            "AskVol",
            "AskIV",
            "Volume",
            "OI",
            "PV",
            "Delta",
            "Gamma",
            "Vega",
            "Theta",
        ]
        inst_types = [
            "string",
            "float",
            "float",
            "int",
            "float",
            "float",
            "int",
            "float",
            "float",
            "int",
            "int",
            "float",
            "float",
            "float",
            "float",
            "float",
        ]
        for inst in self.option_insts:
            if inst not in self.root.stringvars:
                self.root.stringvars[inst] = {}
            for lbl, itype in zip(inst_labels, inst_types):
                self.root.stringvars[inst][lbl] = get_type_var(itype)
        under_labels = [
            "Name",
            "Price",
            "BidPrice",
            "BidVol",
            "AskPrice",
            "AskVol",
            "UpLimit",
            "DownLimit",
            "Volume",
            "OI",
        ]
        under_types = ["string", "float", "float", "int", "float", "int", "float", "float", "int", "int"]
        for inst in list(set(self.underliers)):
            if inst not in self.root.stringvars:
                self.root.stringvars[inst] = {}
            for ulbl, utype in zip(under_labels, under_types):
                self.root.stringvars[inst][ulbl] = get_type_var(utype)
        vol_labels = ["Expiry", "Under", "Df", "Fwd", "Atm", "V90", "V75", "V25", "V10", "Updated"]
        vol_types = ["string", "string", "float", "float", "float", "float", "float", "float", "float", "float"]
        for expiry in self.expiries:
            self.stringvars["Volgrid"][expiry] = {}
            for vlbl, vtype in zip(vol_labels, vol_types):
                self.stringvars["Volgrid"][expiry][vlbl] = get_type_var(vtype)
コード例 #4
0
ファイル: gui_option.py プロジェクト: yzk19930501/pyktrader2
    def __init__(self, vg, app, master):
        all_insts = app.agent.instruments
        self.root = master
        self.name = vg.name
        self.app = app
        self.option_style = 'EU' if self.name in product_code['CFFEX'] else 'AM'
        if self.option_style == 'EU':
            self.iv_func = pyktlib.BlackImpliedVol
        else:
            self.iv_func = pyktlib.AmericanImpliedVol
        self.iv_steps = 40
        self.iv_tol = 1e-5
        self.expiries = vg.underlier.keys()
        self.expiries.sort()
        self.underliers = [vg.underlier[expiry] for expiry in self.expiries]
        opt_insts = list(set().union(*vg.option_insts.values()))
        self.option_insts = {}
        for inst in opt_insts:
            self.option_insts[inst] = (all_insts[inst].cont_mth, all_insts[inst].otype, all_insts[inst].strike)
        self.spot_model = vg.spot_model
        self.cont_mth = list(set([ all_insts[inst].cont_mth for inst in self.option_insts]))
        self.cont_mth.sort()
        self.strikes = [list(set([ all_insts[inst].strike for inst in vg.option_insts[expiry]])) for expiry in self.expiries]
        for idx in range(len(self.strikes)):
            self.strikes[idx].sort()
        self.opt_dict = {v: k for k, v in self.option_insts.iteritems()}
        self.volgrid = instrument.copy_volgrid(vg)
        self.rf = app.agent.irate.get(vg.ccy, 0.0)
        self.vm_figure = {}
        self.vm_lines = dict([(exp, {}) for exp in self.expiries])
        self.vm_ax = {}
        self.otype_selector = {}
        self.cbbox = {}
        self.strike_selector = {}
        self.stringvars = {'Insts': {}, 'Volgrid': {}, 'NewVolParam': {}, 'TheoryVol': {}, 'NewVol': {}, 'DiffVol': {},\
                           'Selected': {}, 'ArbStatus': {}}
        self.new_volnode = {}
        self.curr_insts = {}
        self.option_map = {}
        self.group_risk = {}

        inst_labels = ['Name', 'Price', 'BidPrice', 'BidVol', 'BidIV', 'AskPrice','AskVol','AskIV', 'MidIV', 'TheoryVol', 'Intrinsic', \
                        'Volume', 'OI', 'Updated', 'PV', 'Delta', 'Gamma','Vega', 'Theta', 'RiskPrice', 'RiskUpdated']
        inst_types  = ['string', 'float', 'float', 'int', 'float', 'float', 'int', 'float', 'float', 'float', 'float', \
                        'int', 'int', 'int', 'float', 'float', 'float', 'float', 'float', 'float', 'float']
        for inst in self.option_insts:
            if inst not in self.stringvars:
                self.stringvars[inst] = {}
            for lbl, itype in zip(inst_labels, inst_types):
                self.stringvars[inst][lbl] = get_type_var(itype)
        under_labels = ['Name', 'Price', 'MidPrice', 'BidPrice','BidVol','AskPrice','AskVol','UpLimit','DownLimit', 'Volume', 'OI', 'Updated']
        under_types = ['string', 'float', 'float', 'float', 'int', 'float', 'int', 'float', 'float',  'int', 'int', 'int']
        for inst in list(set(self.underliers)):
            if inst not in self.stringvars:
                self.stringvars[inst] = {}
            for ulbl, utype in zip(under_labels, under_types):
                self.stringvars[inst][ulbl] = get_type_var(utype)
        vol_labels = ['Expiry', 'Under', 'Df', 'Fwd', 'Atm', 'V90', 'V75', 'V25', 'V10', 'T2expiry', 'Updated' ]
        vol_types =  ['string', 'string', 'float', 'float', 'float', 'float', 'float', 'float', 'float', 'float', 'float']
        self.combobox_choices = ['C-BidIV', 'C-MidIV', 'C-AskIV', 'P-BidIV', 'P-MidIV', 'P-AskIV']
        for strikes, expiry in zip(self.strikes, self.expiries):
            self.stringvars['Volgrid'][expiry] = {}
            self.stringvars['NewVolParam'][expiry] = {}
            self.stringvars['Selected'][expiry] = {}
            self.stringvars['ArbStatus'][expiry] = get_type_var('string')
            self.stringvars['TheoryVol'][expiry] = {}
            self.stringvars['NewVol'][expiry] = {}
            self.stringvars['DiffVol'][expiry] = {}
            self.otype_selector[expiry] = {}
            self.cbbox[expiry] = {}
            self.strike_selector[expiry] = {}
            vn = self.volgrid.volnode[expiry]
            self.new_volnode[expiry] = pyktlib.Delta5VolNode(vn.expiry_(), vn.fwd_(), vn.atmVol_(), vn.d90Vol_(), vn.d75Vol_(), vn.d25Vol_(), vn.d10Vol_(), vn.accrual_())
            for vlbl, vtype in zip(vol_labels, vol_types):
                self.stringvars['Volgrid'][expiry][vlbl] = get_type_var(vtype)
            for vlbl in ['Atm', 'V90', 'V75', 'V25', 'V10']:
                val = self.stringvars['Volgrid'][expiry][vlbl].get()
                self.stringvars['NewVolParam'][expiry][vlbl] = get_type_var('float')
                self.stringvars['NewVolParam'][expiry][vlbl].set(keepdigit(val,4))
            fwd = vn.fwd_()
            for strike in strikes:
                self.otype_selector[expiry][strike] = tk.StringVar()
                self.strike_selector[expiry][strike] = tk.BooleanVar()
                iv = self.volgrid.volnode[expiry].GetVolByStrike(strike)
                self.stringvars['Selected'][expiry][strike] = get_type_var('float')
                self.stringvars['Selected'][expiry][strike].set(0.0)
                self.stringvars['TheoryVol'][expiry][strike] = get_type_var('float')
                self.stringvars['TheoryVol'][expiry][strike].set(keepdigit(iv, 4))
                self.stringvars['NewVol'][expiry][strike] = get_type_var('float')
                self.stringvars['NewVol'][expiry][strike].set(keepdigit(iv, 4))
                self.stringvars['DiffVol'][expiry][strike] = get_type_var('float')
                self.stringvars['DiffVol'][expiry][strike].set(0.0)
        self.stringvars['FigSetup'] = dict([(exp, {'YLow': get_type_var('float'), 'YHigh': get_type_var('float')}) for exp in self.expiries])
        for exp in self.expiries:
            for key, ylim in zip(['YLow', 'YHigh'], [0.1, 0.8]):
                self.stringvars['FigSetup'][exp][key].set(ylim)