(self,
data_provider: BaseDataProvider,
reward_strategy: BaseRewardStrategy = IncrementalProfit,
trade_strategy: BaseTradeStrategy = SimulatedTradeStrategy,
initial_balance: int = 10000,
commissionPercent: float = 0.25,
maxSlippagePercent: float = 2.0,
**kwargs)
| 26 | viewer = None |
| 27 | |
| 28 | def __init__(self, |
| 29 | data_provider: BaseDataProvider, |
| 30 | reward_strategy: BaseRewardStrategy = IncrementalProfit, |
| 31 | trade_strategy: BaseTradeStrategy = SimulatedTradeStrategy, |
| 32 | initial_balance: int = 10000, |
| 33 | commissionPercent: float = 0.25, |
| 34 | maxSlippagePercent: float = 2.0, |
| 35 | **kwargs): |
| 36 | super(TradingEnv, self).__init__() |
| 37 | |
| 38 | self.logger = kwargs.get('logger', init_logger(__name__, show_debug=kwargs.get('show_debug', True))) |
| 39 | |
| 40 | self.base_precision: int = kwargs.get('base_precision', 2) |
| 41 | self.asset_precision: int = kwargs.get('asset_precision', 8) |
| 42 | self.min_cost_limit: float = kwargs.get('min_cost_limit', 1E-3) |
| 43 | self.min_amount_limit: float = kwargs.get('min_amount_limit', 1E-3) |
| 44 | |
| 45 | self.initial_balance = round(initial_balance, self.base_precision) |
| 46 | self.commissionPercent = commissionPercent |
| 47 | self.maxSlippagePercent = maxSlippagePercent |
| 48 | |
| 49 | self.data_provider = data_provider |
| 50 | self.reward_strategy = reward_strategy() |
| 51 | self.trade_strategy = trade_strategy(commissionPercent=self.commissionPercent, |
| 52 | maxSlippagePercent=self.maxSlippagePercent, |
| 53 | base_precision=self.base_precision, |
| 54 | asset_precision=self.asset_precision, |
| 55 | min_cost_limit=self.min_cost_limit, |
| 56 | min_amount_limit=self.min_amount_limit) |
| 57 | |
| 58 | self.render_benchmarks: List[Dict] = kwargs.get('render_benchmarks', []) |
| 59 | self.normalize_obs: bool = kwargs.get('normalize_obs', True) |
| 60 | self.stationarize_obs: bool = kwargs.get('stationarize_obs', True) |
| 61 | self.normalize_rewards: bool = kwargs.get('normalize_rewards', False) |
| 62 | self.stationarize_rewards: bool = kwargs.get('stationarize_rewards', True) |
| 63 | |
| 64 | self.n_discrete_actions: int = kwargs.get('n_discrete_actions', 24) |
| 65 | self.action_space = spaces.Discrete(self.n_discrete_actions) |
| 66 | |
| 67 | self.n_features = 6 + len(self.data_provider.columns) |
| 68 | self.obs_shape = (1, self.n_features) |
| 69 | self.observation_space = spaces.Box(low=0, high=1, shape=self.obs_shape, dtype=np.float16) |
| 70 | |
| 71 | self.observations = pd.DataFrame(None, columns=self.data_provider.columns) |
| 72 | |
| 73 | def _current_price(self, ohlcv_key: str = 'Close'): |
| 74 | return float(self.current_ohlcv[ohlcv_key]) |
nothing calls this directly
no test coverage detected