Giter VIP home page Giter VIP logo

Comments (4)

martin0 avatar martin0 commented on May 25, 2024

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.

martin0 avatar martin0 commented on May 25, 2024

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.

martin0 avatar martin0 commented on May 25, 2024

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.

martin0 avatar martin0 commented on May 25, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.