Comments (4)
Looking a bit deeper (no pun intended). When creating the environment, I got a warning about which perhaps is relevant.
Cell
trading_environment = gym.make('trading-v0', ticker='AAPL', max_episode_steps=trading_days, trading_days=trading_days, trading_cost_bps=trading_cost_bps, time_cost_bps=time_cost_bps) trading_environment.seed(42)
Output
`INFO:gymenvs.machine_learning_for_trading.trading_env:gymenvs.machine_learning_for_trading.trading_env logger started.
INFO:gymenvs.machine_learning_for_trading.trading_env:loading data for AAPL...
INFO:gymenvs.machine_learning_for_trading.trading_env:got data for AAPL...
INFO:gymenvs.machine_learning_for_trading.trading_env:None
<class 'pandas.core.frame.DataFrame'>
MultiIndex: 9367 entries, (Timestamp('1981-01-30 00:00:00'), 'AAPL') to (Timestamp('2018-03-27 00:00:00'), 'AAPL')
Data columns (total 10 columns):
Column Non-Null Count Dtype
0 returns 9367 non-null float64
1 ret_2 9367 non-null float64
2 ret_5 9367 non-null float64
3 ret_10 9367 non-null float64
4 ret_21 9367 non-null float64
5 rsi 9367 non-null float64
6 macd 9367 non-null float64
7 atr 9367 non-null float64
8 stoch 9367 non-null float64
9 ultosc 9367 non-null float64
dtypes: float64(10)
memory usage: 1.5+ MB
/usr/local/lib/python3.10/dist-packages/gym/core.py:317: DeprecationWarning: WARN: Initializing wrapper in old step API which returns one bool instead of two. It is recommended to set new_step_api=True
to use new step API. This will be the default behaviour in future.
deprecation(
/usr/local/lib/python3.10/dist-packages/gym/wrappers/step_api_compatibility.py:39: DeprecationWarning: WARN: Initializing environment in old step API which returns one bool instead of two. It is recommended to set new_step_api=True
to use new step API. This will be the default behaviour in future.
deprecation(
[42]`
from machine-learning-for-trading.
piplist.txt
Listing from command Google Colab command !pip list
Some debug information
Some reason, I can't add new comment without "Close with comment"??
Some debug info just before the line
q_values[[self.idx, actions]] = targets
ipdb> len(rewards)
4096
ipdb> len(not_done)
4096
ipdb> self.gamma
(0.99,)
ipdb> target_q_values
<tf.Tensor: shape=(4096,), dtype=float32, numpy=
array([ 0.05242079, -0.00775741, -0.23272878, ..., 0.01323538,
-0.13362771, -0.28871116], dtype=float32)>
ipdb> states.shape
(4096, 10)
ipdb> q_values.shape
(4096, 3)
ipdb> actions
array([0, 0, 2, ..., 0, 1, 1])
ipdb> len(actions)
4096
ipdb> self.idx
<tf.Tensor: shape=(4096,), dtype=int32, numpy=array([ 0, 1, 2, ..., 4093, 4094, 4095], dtype=int32)>
Thought I would try the preceeding notebook, but it has this comment...
See the notebook 04_q_learning_for_trading.ipynb for instructions on upgrading TensorFlow to version 2.2, required by the code below..
I see no information about upgrading to Tensorflow version 2.2. Is that the problem?
from machine-learning-for-trading.
Here is a link to a gpt4 conversation I had about the issue. I haven't tried the suggestion yet.
https://chat.openai.com/share/5469961d-7b58-4f8e-a176-a937ae132a3f
(bard said it was beyond its capabilities at present, even though Google demonstrated competitive coding with gemini last month)
from machine-learning-for-trading.
Following ChatGPT suggestion 1 (see above)
the following mods to experience_replay() seems to result in the ability to run the model :-)
# Reshape targets to be a 2D array with the same second dimension as q_values
targets_np = targets.numpy().reshape(-1, 1)
# Create a mask for the actions taken
mask = tf.one_hot(actions, self.num_actions)
# Update the q_values for the actions taken
q_values = q_values * (1 - mask) + targets_np * mask
from machine-learning-for-trading.
Related Issues (20)
- %load_ext zipline HOT 1
- problem in Long-Short Strategy, Part 1: Preparing Alpha Factors and Features HOT 1
- rsi HOT 1
- Daily historical return deciles HOT 1
- back testing is not working HOT 1
- Chapter 7 - Evaluating signals using alphalens HOT 1
- Chapter 8 02_backtesting_with_zipline HOT 1
- 01_parse_itch_order_flow_messages HOT 3
- Chapter 8 02_backtesting_with_zipline custom_loader not working HOT 1
- --
- installation get stuck / mamba env update -n ml4t -f installation/ml4t-base.yml
- No object named P in the file HOT 3
- Twitter data gone? Broken link in "data/twitter_sentiment.ipynb"
- Unable to replicate backtest performance | Chapter 8 02_backtesting_with_zipline HOT 1
- TypeError: download() got multiple values for argument 'start' when using pandas_datareader.data
- MultipleTimeSeriesCV, why does it iterate backwards in time? HOT 1
- KeyError: 'No object named quandl/wiki/prices in the file' HOT 1
- Install instructions for windows and linux suck - no offence
- Chapter 22_deep_reinforcement_learning Google Colab Python 3.10 03_lunar_lander
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from machine-learning-for-trading.