Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Action order management #125

Merged
merged 99 commits into from Dec 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
99 commits
Select commit Hold shift + click to select a range
d7b6bda
Added the initial code for an action-order management system.
mwbrulhardt Nov 27, 2019
7960c27
Added notebook in temporary directory showing initial ideas for chang…
mwbrulhardt Dec 2, 2019
3516fc8
Merge branch 'master' of github.com:notadamking/tensortrade into acti…
notadamking Dec 3, 2019
6f96aac
Simplify action schemes to and
notadamking Dec 3, 2019
332230a
Clean up Instrument, Quantity, and Trade classes.
notadamking Dec 4, 2019
a003c57
Remove exchange from Instrument, add TradingPair, and move locked qua…
notadamking Dec 4, 2019
fdc636f
Simplify ActionScheme to an OrderCriteria and tradeable_amounts.
notadamking Dec 4, 2019
f6172fc
Simplify OrderCriteria to the list of enabled pairs and an is_executa…
notadamking Dec 4, 2019
fe55349
Flesh out order execution logic and event handling.
notadamking Dec 4, 2019
ddb452c
Added the implementation of quantities and wallets.
mwbrulhardt Dec 5, 2019
f25fef7
Remove Trade requirement from RewardScheme
notadamking Dec 6, 2019
0a5f20c
Move trade back to /trades
notadamking Dec 6, 2019
e3128b4
Complete Order lifecycle and add MultiStepOrder
notadamking Dec 6, 2019
ac58a3f
Syntax changes.
notadamking Dec 6, 2019
d0a7ea6
Add Broker/Orders to TradingEnvironment
notadamking Dec 6, 2019
cd0137b
Create abstract ActionScheme and MultiActionScheme to allow for combi…
notadamking Dec 6, 2019
817ef1b
Complete StandardNormalizer, because why is not yet done yet?
notadamking Dec 6, 2019
bf5fd6b
Move Wallets demo to /examples
notadamking Dec 6, 2019
cb4b658
Simplify Orders and OrderCriteria
notadamking Dec 6, 2019
adfa053
Only complete order if trades all executed on the same exchange.
notadamking Dec 6, 2019
960b987
Initial Wallet/Portfolio integration
notadamking Dec 6, 2019
0635135
Made some name changes and cleaned up some methods.
mwbrulhardt Dec 7, 2019
27ae8bc
Made some minor code changes and name changes. Fixed problem with imp…
mwbrulhardt Dec 7, 2019
03d1e04
Clean up syntax
notadamking Dec 7, 2019
73287fb
Renamed /portfolio -> /wallets
notadamking Dec 7, 2019
cc3c681
Re-apply 27ae8bce0ffff51bc1e0a84cb2dfc35e9af72242
mwbrulhardt Dec 7, 2019
e6f51f1
Rename account -> portfolio
notadamking Dec 7, 2019
6b63b8c
Made changes to portfolio and simulated exchange.
mwbrulhardt Dec 7, 2019
cd62abc
Merged new changes.
mwbrulhardt Dec 7, 2019
cc25d7f
Made changes to portfolio to carry all wallets and made some name cha…
mwbrulhardt Dec 7, 2019
c8791c8
Allow wallet balances to be automatically added to `observation_space`.
notadamking Dec 7, 2019
257731f
Add locked_balance property to Wallet.
notadamking Dec 7, 2019
8597806
Merge remote
notadamking Dec 7, 2019
dc3b3fd
Fleshed out the Portfolio implementation and Exchange connection.
notadamking Dec 7, 2019
2001a0a
Move all abstract implementation methods to the bottom of Exchange - …
notadamking Dec 7, 2019
6b908b0
Update SimulatedExchange and SlippageModel to new paradigm.
notadamking Dec 8, 2019
118bba3
Merge branch 'master' of github.com:notadamking/tensortrade into acti…
notadamking Dec 8, 2019
b92ad2c
Update CCXTExchange and SimulatedExchange to new Exchange spec.
notadamking Dec 8, 2019
5c30c49
Update MultiActionScheme to always submit MARKET orders.
notadamking Dec 8, 2019
b64eaab
Clean out /examples
notadamking Dec 8, 2019
46a8a68
Bug fixes, improvements, etc.
notadamking Dec 8, 2019
8f38b89
Made the test files and made changes to code for organizing the broke…
mwbrulhardt Dec 8, 2019
e4cc5e2
More bug fixes and portfolio management.
notadamking Dec 8, 2019
babafad
Lots of bug fixes, ux improvements, refactoring, etc.
mwbrulhardt Dec 8, 2019
ad32dbe
Finish notebook testing.
notadamking Dec 8, 2019
8738ef9
Added stop-loss order criteria.
mwbrulhardt Dec 8, 2019
129440b
Incorporated new changes from remote branch.
mwbrulhardt Dec 8, 2019
00215d3
Added code for enabling proper quantity locking.
mwbrulhardt Dec 8, 2019
e98b130
Bug fixes, syntax updates, __str__ functions, and lots of debug logs.
notadamking Dec 9, 2019
b96383e
Improve debug logs
notadamking Dec 9, 2019
882c8f9
Fix slippage and SimulatedExchange order execution.
notadamking Dec 9, 2019
bae27b6
Clean up strategies and criteria.
notadamking Dec 9, 2019
92326ad
Remove debug logs
notadamking Dec 9, 2019
f36fa23
Fix observation space issues - commented out feature pipeline tempora…
notadamking Dec 9, 2019
9979dc1
Added support for path orders still needs verification of functionality.
mwbrulhardt Dec 10, 2019
5eff73c
Changed type for criteria parameter of order and change criteria class.
mwbrulhardt Dec 10, 2019
e0e90f3
Merge feature pipeline updates and replace path order w/ Order.follow…
notadamking Dec 10, 2019
adb5839
Remove pending dictionary.
notadamking Dec 10, 2019
81f2ce4
Update orders and brokers to support multiple following orders, add D…
notadamking Dec 10, 2019
ba5f643
Update orders, criteria, and action schemes to better support risk ma…
notadamking Dec 10, 2019
19f8652
Add random slices to SimulatedExchange.
notadamking Dec 10, 2019
b003473
Bug fixes, commission improvements, more logging.
notadamking Dec 10, 2019
a159e90
Added more code for order handling and quantity management. Also adde…
mwbrulhardt Dec 11, 2019
32ae162
Merge remote branch
notadamking Dec 11, 2019
5a6b32b
Bug fixes and order management updates.
notadamking Dec 11, 2019
1c12f87
Calculation fixes, amount -> size, bug fixes, etc.
notadamking Dec 11, 2019
4a8129e
Fix render chart
notadamking Dec 11, 2019
acc8ad1
Fix Matplotlib chart rendering.
notadamking Dec 11, 2019
f29c6a4
Added support for framework wide clock.
mwbrulhardt Dec 11, 2019
fc77811
Remove massive notebook output.
notadamking Dec 11, 2019
bafe6aa
Integrated the clock into all classes for tracking time in the system.
mwbrulhardt Dec 11, 2019
38244d7
Merge branch 'action-order-management' of https://github.com/notadamk…
mwbrulhardt Dec 11, 2019
3923b6d
Add warning for steps < exchange._min_time_slice
notadamking Dec 12, 2019
382a482
Clean up Clock changes.
notadamking Dec 12, 2019
5b33144
Fix clock incrementing.
notadamking Dec 12, 2019
187f332
Made clock changes and fixed wallet bug.
mwbrulhardt Dec 13, 2019
e948232
Added unit tests for Quantity.
mwbrulhardt Dec 13, 2019
efe5a85
Fix Quantity calculation bugs.
notadamking Dec 13, 2019
ecdc20f
Completed unit tests for intruments package. All are passing.
mwbrulhardt Dec 13, 2019
8baa7d0
Expect normalized values in observation space unless observation_lows…
notadamking Dec 13, 2019
64e9196
Improve MinMaxNormalize to use real min/max +- an random amount to pr…
notadamking Dec 13, 2019
f826ff4
Minor comment and code cleanup.
mwbrulhardt Dec 13, 2019
a2d1967
Merge branch 'action-order-management' of github.com:notadamking/tens…
notadamking Dec 13, 2019
41a3a6f
Merge branch 'action-order-management' into action-order-management-2
notadamking Dec 13, 2019
27dd05d
Added allocation methods to wallets.
mwbrulhardt Dec 13, 2019
93404a6
Merge branch 'action-order-management' of https://github.com/notadamk…
mwbrulhardt Dec 13, 2019
12f761b
Nevermind about the wallet allocation. There was a much simpler fix.
mwbrulhardt Dec 13, 2019
dfaa904
Added unit tests for wallet. All are passing.
mwbrulhardt Dec 13, 2019
979e809
Portfolio partially unit tested.
mwbrulhardt Dec 13, 2019
5f4bc0b
Added some more implementation of tests to portfolio. Still incomplete.
mwbrulhardt Dec 14, 2019
a78fb13
Setup complete /tests file structure.
notadamking Dec 15, 2019
e9af0b7
Move file to regisitry
notadamking Dec 15, 2019
eb056fc
Add necessary Portfolio methods back.
notadamking Dec 15, 2019
1908be4
Fix MinMaxNormalizer bug.
notadamking Dec 15, 2019
aa56630
Fix Portfolio bugs.
notadamking Dec 15, 2019
3002d3d
Finished testing portfolio. All except for reset method.
mwbrulhardt Dec 15, 2019
a0d409d
Improve logging/listening capabilities.
notadamking Dec 17, 2019
90e9566
Merge branch 'action-order-management' of github.com:notadamking/tens…
notadamking Dec 17, 2019
00a4608
Fix test errors.
notadamking Dec 17, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/source/components/actions/ContinuousActions.md
@@ -1,6 +1,6 @@
# ContinuousActions

Simple continuous scheme, which calculates the trade amount as a fraction of the total balance.
Simple continuous scheme, which calculates the trade size as a fraction of the total balance.

## Key Variables

Expand All @@ -9,7 +9,7 @@ Simple continuous scheme, which calculates the trade amount as a fraction of the
- `instrument`
- The number of bins to divide the total balance by. Defaults to 20 (i.e. 1/20, 2/20, ..., 20/20).
- `instrument`
- The maximum amount above the current price the scheme will pay for an instrument. Defaults to 1.0 (i.e. 1%).
- The maximum size above the current price the scheme will pay for an instrument. Defaults to 1.0 (i.e. 1%).

## Setters & Properties

Expand Down
6 changes: 3 additions & 3 deletions docs/source/components/actions/DiscreteActions.md
@@ -1,6 +1,6 @@
# DiscreteActions

Simple discrete scheme, which calculates the trade amount as a fraction of the total balance.
Simple discrete scheme, which calculates the trade size as a fraction of the total balance.

## Key Variables

Expand All @@ -9,7 +9,7 @@ Simple discrete scheme, which calculates the trade amount as a fraction of the t
- `actions_per_instrument`
- The number of bins to divide the total balance by. Defaults to 20 (i.e. 1/20, 2/20, ..., 20/20).
- `max_allowed_slippage_percent`
- The maximum amount above the current price the scheme will pay for an instrument. Defaults to 1.0 (i.e. 1%).
- The maximum size above the current price the scheme will pay for an instrument. Defaults to 1.0 (i.e. 1%).

## Setters & Properties

Expand Down Expand Up @@ -40,4 +40,4 @@ from tensortrade.actions import DiscreteActions
action_scheme = DiscreteActions(n_actions=20, instrument='BTC')
```

_This discrete action scheme uses 20 discrete actions, which equates to 4 discrete amounts for each of the 5 trade types (market buy/sell, limit buy/sell, and hold). E.g. [0,5,10,15]=hold, 1=market buy 25%, 2=market sell 25%, 3=limit buy 25%, 4=limit sell 25%, 6=market buy 50%, 7=market sell 50%, etc…_
_This discrete action scheme uses 20 discrete actions, which equates to 4 discrete sizes for each of the 5 trade types (market buy/sell, limit buy/sell, and hold). E.g. [0,5,10,15]=hold, 1=market buy 25%, 2=market sell 25%, 3=limit buy 25%, 4=limit sell 25%, 6=market buy 50%, 7=market sell 50%, etc…_
8 changes: 4 additions & 4 deletions docs/source/components/actions/MultiDiscreteActions.md
@@ -1,8 +1,8 @@
# MultiDiscreteActions

Discrete scheme, which calculates the trade amount as a fraction of the total balance for each instrument provided.
Discrete scheme, which calculates the trade size as a fraction of the total balance for each instrument provided.

The trade type is determined by `action % len(TradeType)`, and the trade amount is determined by the multiplicity of the action.
The trade type is determined by `action % len(TradeType)`, and the trade size is determined by the multiplicity of the action.
For example, `0 = HOLD`, `1 = LIMIT_BUY|0.25`, `2 = MARKET_BUY|0.25`, `5 = HOLD`, `6 = LIMIT_BUY|0.5`, 7 = `MARKET_BUY|0.5`, etc.

## Key Variables
Expand All @@ -12,7 +12,7 @@ For example, `0 = HOLD`, `1 = LIMIT_BUY|0.25`, `2 = MARKET_BUY|0.25`, `5 = HOLD`
- `_actions_per_instrument`
- The number of bins to divide the total balance by. Defaults to 20 (i.e. 1/20, 2/20, ..., 20/20).
- `_max_allowed_slippage_percent`
- The maximum amount above the current price the scheme will pay for an instrument. Defaults to 1.0 (i.e. 1%).
- The maximum size above the current price the scheme will pay for an instrument. Defaults to 1.0 (i.e. 1%).

## Setters & Properties

Expand Down Expand Up @@ -42,4 +42,4 @@ from tensortrade.actions import MultiDiscreteActions
action_scheme = MultiDiscreteActions(n_actions=20, instrument='BTC')
```

_This discrete action scheme uses 20 discrete actions, which equates to 4 discrete amounts for each of the 5 trade types (market buy/sell, limit buy/sell, and hold). E.g. [0,5,10,15]=hold, 1=market buy 25%, 2=market sell 25%, 3=limit buy 25%, 4=limit sell 25%, 6=market buy 50%, 7=market sell 50%, etc…_
_This discrete action scheme uses 20 discrete actions, which equates to 4 discrete sizes for each of the 5 trade types (market buy/sell, limit buy/sell, and hold). E.g. [0,5,10,15]=hold, 1=market buy 25%, 2=market sell 25%, 3=limit buy 25%, 4=limit sell 25%, 6=market buy 50%, 7=market sell 50%, etc…_
2 changes: 1 addition & 1 deletion docs/source/components/component_types/action_scheme.md
Expand Up @@ -12,4 +12,4 @@ from tensortrade.actions import DiscreteActions
action_scheme = DiscreteActions(n_actions=20, instrument='BTC')
```

_This discrete action scheme uses 20 discrete actions, which equates to 4 discrete amounts for each of the 5 trade types (market buy/sell, limit buy/sell, and hold). E.g. [0,5,10,15]=hold, 1=market buy 25%, 2=market sell 25%, 3=limit buy 25%, 4=limit sell 25%, 6=market buy 50%, 7=market sell 50%, etc…_
_This discrete action scheme uses 20 discrete actions, which equates to 4 discrete sizes for each of the 5 trade types (market buy/sell, limit buy/sell, and hold). E.g. [0,5,10,15]=hold, 1=market buy 25%, 2=market sell 25%, 3=limit buy 25%, 4=limit sell 25%, 6=market buy 50%, 7=market sell 50%, etc…_
2 changes: 1 addition & 1 deletion docs/source/components/exchanges/Exchange.md
Expand Up @@ -71,7 +71,7 @@ Inside of the [README](../README.md), you'll have seen the reason why we have th
- The performance of the active account on the exchange since the last reset.
- `generated_space`
- The initial shape of the observations generated by the exchange, before feature transformations.
- `generated_columns`
- `observation_columns`
- The list of column names of the observation data frame generated by the exchange, before feature transformations.
- `observation_space`
- The final shape of the observations generated by the exchange, after feature transformations.
Expand Down
2 changes: 1 addition & 1 deletion docs/source/components/exchanges/live/CCXTExchange.md
Expand Up @@ -35,7 +35,7 @@ An exchange for trading on CCXT-supported cryptocurrency exchanges.
- The performance of the active account on the exchange since the last reset.
- `generated_space`
- The initial shape of the observations generated by the exchange, before feature transformations.
- `generated_columns`
- `observation_columns`
- The list of column names of the observation data frame generated by the exchange, before feature transformations.
- `observation_space`
- The final shape of the observations generated by the exchange, after feature transformations.
Expand Down
Expand Up @@ -35,7 +35,7 @@ An exchange for trading using the Interactive Brokers API.
- The performance of the active account on the exchange since the last reset.
- `generated_space`
- The initial shape of the observations generated by the exchange, before feature transformations.
- `generated_columns`
- `observation_columns`
- The list of column names of the observation data frame generated by the exchange, before feature transformations.
- `observation_space`
- The final shape of the observations generated by the exchange, after feature transformations.
Expand Down
2 changes: 1 addition & 1 deletion docs/source/components/exchanges/simulated/FBMExchange.md
Expand Up @@ -47,7 +47,7 @@ We generate prices, and train on that. Simple.
- The performance of the active account on the exchange since the last reset.
- `generated_space`
- The initial shape of the observations generated by the exchange, before feature transformations.
- `generated_columns`
- `observation_columns`
- The list of column names of the observation data frame generated by the exchange, before feature transformations.
- `observation_space`
- The final shape of the observations generated by the exchange, after feature transformations.
Expand Down
Expand Up @@ -39,7 +39,7 @@ The reason we create simulated exchanges is so we create more robust models quic
- The performance of the active account on the exchange since the last reset.
- `generated_space`
- The initial shape of the observations generated by the exchange, before feature transformations.
- `generated_columns`
- `observation_columns`
- The list of column names of the observation data frame generated by the exchange, before feature transformations.
- `observation_space`
- The final shape of the observations generated by the exchange, after feature transformations.
Expand Down
6 changes: 3 additions & 3 deletions docs/source/components/rewards/SimpleProfit.md
Expand Up @@ -37,7 +37,7 @@ When the bot says buy, it sets the variable `_is_holding_instrument` to `True`,
We see that inside of this line of code here. This allows us to check to see if we've made a profit later.

```py
elif trade.is_buy and trade.amount > 0:
elif trade.is_buy and trade.size > 0:
self._purchase_price = trade.price
self._is_holding_instrument = True

Expand All @@ -48,10 +48,10 @@ elif trade.is_buy and trade.amount > 0:
We then sell afterward using the original trade price as a reference. Which is suggested in the lines below:

```py
if trade.is_sell and trade.amount > 0:
if trade.is_sell and trade.size > 0:
self._is_holding_instrument = False
profit_per_instrument = trade.price - self._purchase_price
profit = trade.amount * profit_per_instrument
profit = trade.size * profit_per_instrument
profit_sign = np.sign(profit)

return profit_sign * (1 + (5 ** np.log10(abs(profit))))
Expand Down
6 changes: 3 additions & 3 deletions docs/source/examples/overview.md
Expand Up @@ -15,7 +15,7 @@ The beginning of the code in [Exchange](https://github.com/notadamking/tensortra
class Exchange(object, metaclass=ABCMeta):
"""An abstract exchange for use within a trading environment."""

def __init__(self, base_instrument: str = 'USD', dtype: TypeString = np.float32, feature_pipeline: FeaturePipeline = None):
def __init__(self, base_instrument: str = 'USD', dtype: Union[type, str] = np.float32, feature_pipeline: FeaturePipeline = None):
"""
Arguments:
base_instrument: The exchange symbol of the instrument to store/measure value in.
Expand Down Expand Up @@ -50,8 +50,8 @@ class SimulatedExchange(Exchange):
self._commission_percent = self.default('commission_percent', 0.3, kwargs)
self._base_precision = self.default('base_precision', 2, kwargs)
self._instrument_precision = self.default('instrument_precision', 8, kwargs)
self._min_trade_amount = self.default('min_trade_amount', 1e-6, kwargs)
self._max_trade_amount = self.default('max_trade_amount', 1e6, kwargs)
self._min_trade_size = self.default('min_trade_size', 1e-6, kwargs)
self._max_trade_size = self.default('max_trade_size', 1e6, kwargs)

self._initial_balance = self.default('initial_balance', 1e4, kwargs)
self._observation_columns = self.default(
Expand Down
8 changes: 4 additions & 4 deletions docs/source/examples/trading_context.json
Expand Up @@ -178,8 +178,8 @@
" api_secret_key: \"do8u43hgiurwfnlveio\"\n",
" min_trade_price: 1e-7\n",
" max_trade_price: 1e7\n",
" min_trade_amount: 1e-4\n",
" max_trade_amount: 1e4\n",
" min_trade_size: 1e-4\n",
" max_trade_size: 1e4\n",
"```\n",
"\n",
"\n",
Expand All @@ -195,8 +195,8 @@
" \"instrument_precision\": 10,\n",
" \"min_trade_price\": 1e-7,\n",
" \"max_trade_price\": 1e7,\n",
" \"min_trade_amount\": 1e-4,\n",
" \"max_trade_amount\": 1e4,\n",
" \"min_trade_size\": 1e-4,\n",
" \"max_trade_size\": 1e4,\n",
" \"initial_balance\": 1e5,\n",
" \"window_size\": 5,\n",
" \"should_pretransform_obs\": true,\n",
Expand Down