Git Product home page Git Product logo

rl_trading's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

rl_trading's Issues

Make sense modify environment responses?

Make the library closer to OpenAI gym's behavior. Currently, all updates happened inside environment step, including the agent's update. Would be clearer if it was performed outside step. So, following the Gym's behavior, we would do:

import gym
env = gym.make('YieldCurve')
for i_episode in range(20):
   # here I am not so sure. 
    observation = env.reset()
    for t in range(100):
        # it is equivalent to do a random action
        action = env.action_space.sample()
       # the environment step would answer with all info needed
       # now, the environment answer with the msgs generated by the
       # interaction between env and agent
        observation, reward, done, info = env.step(action)
       # the flag done could be used by different reasons
        if done:
            print("Episode finished after {} timesteps".format(t+1))
            break

My only concern is that the Enrironment handles when the agent need to hedge positions. Where should I perform that action if not in the env.step?

check if there is a primary agent set in environment.py

Around the line 134, in environment.py, change:

if self.primary_agent == agent:
    if carry_pos and f_pos != 0:
        # set up d_pos variable properly
        if s_instr not in d_pos:
            d_pos[s_instr] = {}
        d_pos[s_instr]['Q'] = f_pos
        d_pos[s_instr]['P'] = f_price_adj

to

if self.primary_agent:  # include this line
    if self.primary_agent == agent:
        if carry_pos and f_pos != 0:
            # set up d_pos variable properly
            if s_instr not in d_pos:
                d_pos[s_instr] = {}
            d_pos[s_instr]['Q'] = f_pos
            d_pos[s_instr]['P'] = f_price_adj

bug: issue when log the final PnL

The f_pnl in the loop should be changed in this piece of code in log_trial() method from Environment class:

            # log metrics
            f_pnl = float('{:0.2f}'.format(d_info['pnl']))
            na_pnl = filterout_outliers(d_info['pnl_hist'], d_info['time'])

            # calculate the MDD
            f_max = 0.
            l_aux = []
            for f_pnl in na_pnl:
                if f_pnl > f_max:
                    f_max = f_pnl
                    l_aux.append(f_max-f_pnl)

Implement basic agent simulation in agent.py

Include the method in Run class from agent.py:

    def _basic(self, e, f_aux, s_valfunc=None, i_version=None):
        '''
        '''
        s_fdate = e.order_matching.s_file.split('_')[0].split('/')[-1]
        e.set_reward_function('pnl')
        s_hedging_on = self._get_from_argv('s_hedging_on')

        s1 = e.s_main_intrument[-3:]
        s2 = s_hedging_on[-3:]
        e.set_log_file('basic_{}{}_{}'.format(s1, s2, s_fdate))

        b_hedging = self._get_from_argv('b_hedging')
        b_hedging = True
        # check if there are initial positions
        d_initial_pos = self._get_from_argv('d_initial_pos')
        b_keep_pos = self._get_from_argv('b_keep_pos')
        if not d_initial_pos:
            d_initial_pos = {}
        if not s_hedging_on:
            s_hedging_on = 'DI1F19'
        a = e.create_agent(BasicAgent,
                           f_min_time=f_aux,
                           d_initial_pos=d_initial_pos,
                           f_ttoupdate=30.)

        return a

Modify the set_experiments_opotions(self) to:

    def set_experiments_options(self):
        '''
        '''
        d_experiments = {'_basic': self._basic,
                         '_qlearning': self._qlearning,
                         '_domino_q': self._domino_q,
                         '_random': self._random,
                         '_domino_rand': self._domino_rand}
        return d_experiments

And finally, in the class BasicAgent in agent_frwk.py include in the last line d_rtn['features'] = {'null': None} to the method get_intern_state(self, inputs, state)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.