Example #1
0
def test_position():
    from jaqs.data.basic import Position, GoalPosition
    pos = Position()
    df = pd.DataFrame({'symbol': ['SPY', 'WTI'], 'current_size': [12, 15]})
    l = Position.create_from_df(df)
    for p in l:
        str(p)

    gp = GoalPosition()
    str(gp)
Example #2
0
 def _update_position_by_trade_ind(self, ind):
     # ignore no fill_size (which should not be)
     if ind.fill_size == 0:
         print("WARNING: no fill_size TradeInd found!")
         return
     
     # get position, if no, create a new one.
     pos_key = self._make_position_key(ind.symbol)
     pos = self.positions.get(pos_key, None)
     if pos is None:
         pos = Position(symbol=ind.symbol)
     
     if common.ORDER_ACTION.is_positive(ind.entrust_action):
         pos.current_size += ind.fill_size
     elif common.ORDER_ACTION.is_negative(ind.entrust_action):
         pos.current_size -= ind.fill_size
     
     self.positions[pos_key] = pos
     
     # if no holding, remove the position from the dict
     if pos.current_size == 0:
         self.positions.pop(pos_key)
         # TODO : remove holding_securities field
         self.holding_securities.remove(ind.symbol)
     else:
         self.holding_securities.add(ind.symbol)
Example #3
0
def test_position():
    from jaqs.data.basic import Position, GoalPosition
    pos = Position()
    df = pd.DataFrame({'symbol': ['SPY', 'WTI'],
                       'current_size': [12, 15]})
    l = Position.create_from_df(df)
    for p in l:
        str(p)
    
    gp = GoalPosition()
    str(gp)
Example #4
0
    def init_positions(self):
        #df_acc, msg = self.ctx.trade_api.query_account()
        #if not msg.split(',')[0] == '0':
        #    print(msg)
        #    raise RuntimeError("Query account failed")
        #account_info = df_acc.set_index('type').to_dict(orient='index')
        #
        #df_univ, msg = self.ctx.trade_api.query_universe()
        #df_univ = df_univ.rename(columns={'security': 'symbol'})
        #univ = df_univ['symbol'].values.copy()
        ## self.ctx.init_universe(univ)

        df_pos, msg = self.ctx.trade_api.query_position()
        df_pos = df_pos.rename(columns={'security': 'symbol'})
        pos_list = Position.create_from_df(df_pos)
        pos_dic = {p.symbol: p for p in pos_list}
        self.positions.update(pos_dic)
Example #5
0
    def init_positions(self):
        query_account_res = self.ctx.trade_api.query_account()
        if query_account_res is None:
            return

        df_acc, msg = self.ctx.trade_api.query_account()
        if msg != '0,':
            print(msg)
            raise RuntimeError("Query account failed")
        account_info = df_acc.set_index('type').to_dict(orient='index')

        df_univ, msg = self.ctx.trade_api.query_universe()
        df_univ = df_univ.rename(columns={'security': 'symbol'})
        univ = df_univ['symbol'].values.copy()
        # self.ctx.init_universe(univ)

        df_pos, msg = self.ctx.trade_api.query_position()
        df_pos = df_pos.rename(columns={'security': 'symbol'})
        pos_list = Position.create_from_df(df_pos)
        pos_dic = {p.symbol: p for p in pos_list}
        self.positions.update(pos_dic)