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

Merging Updated Docs #88

Merged
merged 8 commits into from Nov 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -16,6 +16,7 @@ tags
# developer environments
.idea
.vscode
Pipfile

# agent storage
examples/agents
358 changes: 358 additions & 0 deletions Pipfile.lock

Large diffs are not rendered by default.

Binary file added docs/source/_static/images/TestingDashboard.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/source/_static/images/agents.jpeg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/source/_static/images/alphastar.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/source/_static/images/banner.jpeg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/source/_static/images/cartpole.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/source/_static/images/commits.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/source/_static/images/components.jpeg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/source/_static/images/environment.jpeg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/source/_static/images/logo.jpeg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/source/_static/images/min_max_scaling.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/source/_static/images/pipeline.jpeg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/source/_static/images/primer.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/source/_static/images/sharpe.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/source/_static/images/sortino.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/source/_static/images/stochastic.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/source/_static/images/talib_transform.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/source/_static/images/talib_transform.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/source/_static/images/trading.jpeg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/source/_static/images/tuning.jpeg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions docs/source/api/tensortrade.base.component.rst
@@ -0,0 +1,7 @@
tensortrade.base.component module
=================================

.. automodule:: tensortrade.base.component
:members:
:undoc-members:
:show-inheritance:
7 changes: 7 additions & 0 deletions docs/source/api/tensortrade.base.context.rst
@@ -0,0 +1,7 @@
tensortrade.base.context module
===============================

.. automodule:: tensortrade.base.context
:members:
:undoc-members:
:show-inheritance:
7 changes: 7 additions & 0 deletions docs/source/api/tensortrade.base.registry.rst
@@ -0,0 +1,7 @@
tensortrade.base.registry module
================================

.. automodule:: tensortrade.base.registry
:members:
:undoc-members:
:show-inheritance:
16 changes: 16 additions & 0 deletions docs/source/api/tensortrade.base.rst
@@ -0,0 +1,16 @@
tensortrade.base package
========================

.. automodule:: tensortrade.base
:members:
:undoc-members:
:show-inheritance:

Submodules
----------

.. toctree::

tensortrade.base.component
tensortrade.base.context
tensortrade.base.registry
1 change: 1 addition & 0 deletions docs/source/api/tensortrade.rst
Expand Up @@ -12,6 +12,7 @@ Subpackages
.. toctree::

tensortrade.actions
tensortrade.base
tensortrade.environments
tensortrade.exchanges
tensortrade.features
Expand Down
44 changes: 44 additions & 0 deletions docs/source/components/actions/ActionStrategy.md
@@ -0,0 +1,44 @@
# ActionStrategy

Action strategies define the action space of the environment and convert an agent's actions into executable trades.

For example, if we were using a discrete action space of 3 actions (0 = hold, 1 = buy 100 %, 2 = sell 100%), our learning agent does not need to know that returning an action of 1 is equivalent to buying an instrument. Rather, our agent needs to know the reward for returning an action of 1 in specific circumstances, and can leave the implementation details of converting actions to trades to the `ActionStrategy`.

Each action strategy has a get_trade method, which will transform the agent's specified action into an executable `Trade`. It is often necessary to store additional state within the strategy, for example to keep track of the currently traded position. This state should be reset each time the action strategy's reset method is called, which is done automatically when the parent `TradingEnvironment` is reset.

## What is an Action?

This is a review of what was mentioned inside of the overview section. It explains how a RL operates. You'll better understand what an action is in context of an observation space and reward. At the same time, hopefully this will be a proper refresher.

An action is a predefined value of how the machine should move inside of the world. To better summarize, its a *command that a player would give inside of a video game in respose to a stimuli*. The commands usually come in the form of an `action_space`. An `action_space` is something that represents how to make the user move inside of an environment. While it might not be easily interpretable by humans, it can easily be interpreted by a machine.

Let's look at a good example. Lets say we're trying to balance a cart with a pole on it (cartpole). We can choose to move the cart left and right. This is a `Discrete(2)` action type.

* 0 - Push cart to the left
* 1 - Push cart to the right

When we get the action from the RL agent, the environment will see that number instead of a name. We can create lists, tuples, and a box.

![Watch Link Run Around In Circles](../../_static/images/cartpole.gif)


## Setters & Properties

Each property and property setter.

* `dtype`
* A type or str corresponding to the dtype of the `action_space`.
* `exchange`
* The exchange being used by the current trading environment.
* This will be set by the trading environment upon initialization. Setting the exchange causes the strategy to reset.
* `action_space`
* The shape of the actions produced by the strategy. This takes in a `gym.space` and is different for each given strategy.


## Functions

* reset
* Optionally implementable method for resetting stateful strategies.
* get_trade
* Get the trade to be executed on the exchange based on the action provided.
* Usually this is the way we distill the information generated from the `action_space`.
40 changes: 40 additions & 0 deletions docs/source/components/actions/ContinuousActionStrategy.md
@@ -0,0 +1,40 @@
# ContinuousActionStrategy

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

## Key Variables


* `max_allowed_slippage`
* The exchange symbols of the instruments being traded.
* `instrument_symbol`
* The number of bins to divide the total balance by. Defaults to 20 (i.e. 1/20, 2/20, ..., 20/20).
* `instrument_symbol`
* The maximum amount above the current price the strategy will pay for an instrument. Defaults to 1.0 (i.e. 1%).



## Setters & Properties

Each property and property setter.

* `dtype`
* A type or str corresponding to the dtype of the `action_space`.
* `exchange`
* The exchange being used by the current trading environment.
* This will be set by the trading environment upon initialization. Setting the exchange causes the strategy to reset.
* `action_space`
* The shape of the actions produced by the strategy. This takes in a `gym.space` and is different for each given strategy.

## Functions

* `reset`
* Optionally implementable method for resetting stateful strategies.
* `get_trade`
* Get the trade to be executed on the exchange based on the action provided.
* Usually this is the way we distill the information generated from the `action_space`.


## Use Cases

TODO: Place Use Case Here
45 changes: 45 additions & 0 deletions docs/source/components/actions/DiscreteActionStrategy.md
@@ -0,0 +1,45 @@
# DiscreteActionStrategy

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

## Key Variables

* `instrument_symbols`
* The exchange symbols of the instruments being traded.
* `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 strategy will pay for an instrument. Defaults to 1.0 (i.e. 1%).


## Setters & Properties

Each property and property setter.

* `dtype`
* A type or str corresponding to the dtype of the `action_space`.
* `exchange`
* The exchange being used by the current trading environment.
* This will be set by the trading environment upon initialization. Setting the exchange causes the strategy to reset.
* `action_space`
* The shape of the actions produced by the strategy. This takes in a `gym.space` and is different for each given strategy.

## Functions

* `reset`
* Optionally implementable method for resetting stateful strategies.
* `get_trade`
* Get the trade to be executed on the exchange based on the action provided.
* Usually this is the way we distill the information generated from the `action_space`.

## Use Cases

```py
from tensortrade.actions import DiscreteActionStrategy

action_strategy = DiscreteActionStrategy(n_actions=20,
instrument_symbol='BTC')
```


_This discrete action strategy 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…_
53 changes: 53 additions & 0 deletions docs/source/components/actions/MultiDiscreteActionStrategy.md
@@ -0,0 +1,53 @@
# MultiDiscreteActionStrategy

Discrete strategy, which calculates the trade amount 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.
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


* `_instrument_symbols`
* The exchange symbols of the instruments being traded.
* `_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 strategy will pay for an instrument. Defaults to 1.0 (i.e. 1%).



## Setters & Properties

Each property and property setter.

* `dtype`
* A type or str corresponding to the dtype of the `action_space`.
* `exchange`
* The exchange being used by the current trading environment.
* This will be set by the trading environment upon initialization. Setting the exchange causes the strategy to reset.
* `action_space`
* The shape of the actions produced by the strategy. This takes in a `gym.space` and is different for each given strategy.

## Functions

* `reset`
* Optionally implementable method for resetting stateful strategies.
* `get_trade`
* Get the trade to be executed on the exchange based on the action provided.
* Usually this is the way we distill the information generated from the `action_space`.


## Use Cases

```py
from tensortrade.actions import MultiDiscreteActionStrategy

action_strategy = MultiDiscreteActionStrategy(n_actions=20,
instrument_symbol='BTC')
```


_This discrete action strategy 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…_
Expand Up @@ -13,4 +13,4 @@ action_strategy = DiscreteActionStrategy(n_actions=20,
instrument_symbol='BTC')
```

_This discrete action strategy 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 strategy 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…_
Expand Up @@ -25,4 +25,4 @@ feature_pipeline = FeaturePipeline(steps=[normalize_price,
exchange.feature_pipeline = feature_pipeline
```

_This feature pipeline normalizes the price values between 0 and 1, before adding some moving average columns and making the entire time series stationary by fractionally differencing consecutive values._
_This feature pipeline normalizes the price values between 0 and 1, before adding some moving average columns and making the entire time series stationary by fractionally differencing consecutive values._
Expand Up @@ -32,4 +32,4 @@ from tensortrade.exchanges.simulated import SimulatedExchange

df = pd.read_csv('./data/btc_ohclv_1h.csv')
exchange = SimulatedExchange(data_frame=df, base_instrument='USD')
```
```
Expand Up @@ -12,4 +12,4 @@ from tensortrade.rewards import SimpleProfitStrategy
reward_strategy = SimpleProfitStrategy()
```

_The simple profit strategy returns a reward of -1 for not holding a trade, 1 for holding a trade, 2 for purchasing an instrument, and a value corresponding to the (positive/negative) profit earned by a trade if an instrument was sold._
_The simple profit strategy returns a reward of -1 for not holding a trade, 1 for holding a trade, 2 for purchasing an instrument, and a value corresponding to the (positive/negative) profit earned by a trade if an instrument was sold._
Expand Up @@ -22,4 +22,4 @@ environment = TradingEnvironment(exchange=exchange,
action_strategy=action_strategy,
reward_strategy=reward_strategy,
feature_pipeline=feature_pipeline)
```
```
Expand Up @@ -30,4 +30,4 @@ a_strategy = TensorforceTradingStrategy(environment=environment,
b_strategy = StableBaselinesTradingStrategy(environment=environment,
model=PPO2,
policy='MlpLnLSTMPolicy')
```
```
1 change: 1 addition & 0 deletions docs/source/components/components.md
Expand Up @@ -3,3 +3,4 @@
TensorTrade is built around modular components that together make up a trading strategy. Trading strategies combine reinforcement learning agents with composable trading logic in the form of a `gym` environment. A trading environment is made up of a set of modular components that can be mixed and matched to create highly diverse trading and investment strategies.

Just like electrical components, the purpose of TensorTrade components is to be able to mix and match them as necessary.