def __init__(self): self.env_name = 'gaf-environment-v1.0' self.reward_mult = 100000 self.cash = 100000 self.total_loss = 0.0 self.current_action = None self.previous_action = None self.clock = Clock() self.dm = DataManager(self.clock) self.pm = PositionManager(self.clock, self.dm, self.cash, 30) self.benchmark = PositionManager(self.clock, self.dm, self.cash, 1) self.symbols = self.dm.get_symbols() self.action_space = gym.spaces.Discrete(3) self.observation_space = gym.spaces.Box(low=-1, high=1, shape=(4, 30, 180)) self.symbols = None self.final_cash_value = [] #self.print_intro() self.avg_reward = 0 self.episodes_ran = 0 self.perm_symbols = [ self.dm.current_symbol, ] self.returns = pd.DataFrame()
def __init__(self): # Publish robot state (position, orientation, tool) self.niryo_one_robot_state_publisher = NiryoRobotStatePublisher() # Position Manager positions_dir = rospy.get_param("~positions_dir") self.pos_manager = PositionManager(positions_dir) # trajectory_manager trajectories_dir = rospy.get_param("~trajectories_dir") self.traj_manager = TrajectoryManager(trajectories_dir) # robot commander self.robot_commander = RobotCommander(self.pos_manager, self.traj_manager) self.robot_commander.start()
def __init__(self): # Publish robot state (position, orientation, gripper) self.niryo_one_robot_state_publisher = NiryoRobotStatePublisher() # Position Manager positions_dir = rospy.get_param("~positions_dir") self.pos_manager = PositionManager(positions_dir) # robot commander self.robot_commander = RobotCommander(self.pos_manager) # Load ROS action interface self.robot_action_server = RobotActionServer(self.pos_manager) self.robot_action_server.start()
def __init__(self): #init RosLogger self.debug_mode = rospy.get_param("~debug_mode") self.gauss_ros_logger = RosLogger(debug_mode = self.debug_mode) # Publish robot state (position, orientation, tool) self.gauss_robot_state_publisher = GaussRobotStatePublisher() self.simulator_mode = rospy.get_param("~simulator_mode") # Position Manager positions_dir = rospy.get_param("~positions_dir") self.pos_manager = PositionManager(positions_dir, self.gauss_ros_logger) #trajectory_manager trajectories_dir = rospy.get_param("~trajectories_dir") self.traj_manager = TrajectoryManager(trajectories_dir, self.gauss_ros_logger) # robot commander self.robot_commander = RobotCommander(self.simulator_mode, self.pos_manager, self.traj_manager, self.gauss_ros_logger) self.robot_commander.start() self.gauss_ros_logger.publish_log_status("INFO", "GaussCommanderNode start over")
def getExecutorMockWithPM(self): #pm = PositionDBManager(db) pm = PositionManager() e = self.getExecutorMock() e.setPositionManager(pm) return e, pm
class StockEnv(gym.Env): def __init__(self): self.env_name = 'gaf-environment-v1.0' self.reward_mult = 100000 self.cash = 100000 self.total_loss = 0.0 self.current_action = None self.previous_action = None self.clock = Clock() self.dm = DataManager(self.clock) self.pm = PositionManager(self.clock, self.dm, self.cash, 30) self.benchmark = PositionManager(self.clock, self.dm, self.cash, 1) self.symbols = self.dm.get_symbols() self.action_space = gym.spaces.Discrete(3) self.observation_space = gym.spaces.Box(low=-1, high=1, shape=(4, 30, 180)) self.symbols = None self.final_cash_value = [] #self.print_intro() self.avg_reward = 0 self.episodes_ran = 0 self.perm_symbols = [ self.dm.current_symbol, ] self.returns = pd.DataFrame() def get_frame(self): return self.dm.get_frame() def reset(self): self.total_loss = 0.0 if self.episodes_ran > 0: self.print_returns() self.clock.reset() self.cash = 100000 self.perm_symbols = [] self.dm.reset() frame = self.dm.get_frame() self.first_frame = frame self.episodes_ran += 1 return frame def position_to_close(self, index): return self.pm.position_expired(index) def close_positions(self): return self.pm.close_positions() def update_action_count(self, action): if action == actions.Actions.BUY: buy_count += 1 elif action == actions.Actions.SELL: sell_count += 1 elif action == actions.Actions.HOLD: hold_count += 1 def calculate_ma(self, reward, period=14): return reward def step(self, action): self.update_action_count(action) done = self.clock.done() frame = self.dm.get_frame() if not done else self.first_frame reward = self.pm.close_position() * self.reward_mult info = {} if not np.isfinite(reward): reward = 0 if done == self.dm.INCR_FLAG: self.final_cash_value.append(self.cash) self.dm.increment_symbol() self.perm_symbols.append(self.dm.current_symbol) print(self.cash) self.cash = 100000 done = False self.pm.open_position(action, self.clock.index) self.clock.tick() elif done == False: self.pm.open_position(action, self.clock.index) self.update_cash(reward) self.clock.tick() else: self.returns.append(pd.Series(reward), ignore_index=True) self.update_cash(reward) self.final_cash_value.append(self.cash) if self.cash < 0.0: print('Total Loss of Capital') self.total_loss += 100000 self.cash = 100000 reward = -5 return frame, reward, done, info def update_cash(self, reward): reward /= self.reward_mult self.old_cash = self.cash self.cash = (1 + reward) * self.cash def print_intro(self): start = self.dm.get_date() end = self.dm.get_ending_date() delta = end - start print('Preparing environment for:', fg('red'), self.dm.get_symbol() + attr('reset')) print('Starting date:', start, 'Ending Date:', end) print("Time period:", delta.days, 'days') print('Starting Balance:', fg('green'), self.get_cash(), attr('reset')) def get_cash(self, value=None): source = float(self.cash if value is None else value) return '${value:,.2f}'.format(value=source)