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

Win env #21

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 3 additions & 10 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ MANIFEST
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec
*.csv

# Installer logs
pip-log.txt
pip-delete-this-directory.txt
Expand Down Expand Up @@ -100,15 +100,9 @@ celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
venv/
env.bak/
.venv/
venv.bak/
tvenv/
backup/

# Spyder project settings
.spyderproject
Expand All @@ -127,5 +121,4 @@ dmypy.json

# Pyre type checker
.pyre/

# cove998 list

3 changes: 0 additions & 3 deletions .vscode/settings.json

This file was deleted.

4 changes: 0 additions & 4 deletions CONTRIBUTING.md

This file was deleted.

8 changes: 0 additions & 8 deletions LICENSE

This file was deleted.

1 change: 0 additions & 1 deletion VERSION

This file was deleted.

29 changes: 24 additions & 5 deletions __init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,28 @@
__version__="0.0.2"
from gym.wrappers import TimeLimit
from gym.envs.registration import register
import pandas as pd
f='./data/split/GBPUSD/weekly/GBPUSD_2017_0.csv'
file ="./data/split/GBPUSD/weekly/GBPUSD_2017_2.csv"
df = pd.read_csv(file)

register(
id='forex-trading-v0',
entry_point='tradinggym.environments:tgym',
kwargs={'df':pd.read_csv(f) }
id='TradingGym-v0',
entry_point='env.env_fx:tgym',
kwargs={'df': df,
'env_config_file':'./env/config/gdbusd-test-1.json'
},
max_episode_steps = 1440, # (Optional[int]): The maximum number of steps that an episode can consist of
reward_threshold=20000.0, # (Optional[int]): The reward threshold before the task is considered solved
nondeterministic=False, # (bool): Whether this environment is non-deterministic even after seeding
# order_enforce = True, # (Optional[int]): Whether to wrap the environment in an orderEnforcing wrapper
)

register(
id='TradingGym-v1',
entry_point='env.env_fx:tgym',
kwargs={'df': df,
'env_config_file':'./env/config/gdbusd-test-1.json'
},
max_episode_steps = 1440 * 5,
reward_threshold=30000.0,
nondeterministic=False,
)
1 change: 0 additions & 1 deletion _config.yml

This file was deleted.

Binary file removed abc.png
Binary file not shown.
Empty file removed bs3/__init__.py
Empty file.
28 changes: 0 additions & 28 deletions bs3/main.py

This file was deleted.

1 change: 1 addition & 0 deletions data/data_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ def add_time_feature(df,symbol, dt_col_name = 'time'):
df['symbol'] = symbol
df['dt'] = pd.to_datetime(df[dt_col_name])
df.index = df['dt']
df.index.names = ['step']
df['minute'] =df['dt'].dt.minute
df['hour'] =df['dt'].dt.hour
df['weekday'] = df['dt'].dt.dayofweek
Expand Down
77 changes: 77 additions & 0 deletions data/data_processor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import pandas as pd
import os
# use pd.csv_read() load file to panads dataframe, column name: ["time","Open","High","Low", "Close"] from ./raw/{file_name}
# add column "symbol" based on file name split by "-", use first part of file name as symbol
# check if any rows missing in dataframe based on time interval, if so, use last row to fill in missing data
# example:
# before:
# 2010-01-01 22:00:00,1.43293,1.43287,1.43296,1.43277
# 2010-01-01 22:05:00,1.43294,1.43296,1.43304,1.43281
# 2010-01-01 22:15:00,1.43295,1.43304,1.43305,1.43278
# 2010-01-01 22:20:00,1.43292,1.43294,1.43296,1.43240
#
# missing timestamp 2010-01-01 22:10:00 so use last row to fill in missing data
# after:
# 2010-01-01 22:00:00,1.43293,1.43287,1.43296,1.43277
# 2010-01-01 22:05:00,1.43294,1.43296,1.43304,1.43281
# 2010-01-01 22:10:00,1.43294,1.43296,1.43304,1.43281
# 2010-01-01 22:15:00,1.43295,1.43304,1.43305,1.43278
# 2010-01-01 22:20:00,1.43292,1.43294,1.43296,1.43240
# save dataframe to ./processed/{file_name}

def data_processor(file_name) -> None:
df = pd.read_csv("./raw/"+file_name, names=["time","Open","High","Low", "Close"])
symbol = file_name.split("-")[0]
df["symbol"] = symbol
df = df.set_index("time")
df = df.sort_index()
df = df.asfreq("5T")
df = df.fillna(method="ffill")
df.to_csv("./processed/"+file_name)

def compare_rows(df, index1, index2) -> int:
time1 = df.index[index1]
time2 = df.index[index2]
return (time2-time1).seconds

# test cases for compare_rows(file_name)
def test_compare_rows(file_name):
series = pd.Series([0.0, None, 2.0, 3.0], index=index)
df = pd.DataFrame({{'s': series}})
df
df = pd.read_csv("./raw/"+file_name, names=["time","Open","High","Low", "Close"])
symbol = file_name.split("-")[0]
df["symbol"] = symbol
df = df.set_index("time")
df = df.sort_index()
index = pd.date_range(df["time"], periods=4, freq='T')
print(df)
df1 = df.asfreq("5T")
df = pd.merge(df1,df, left_index=True, right_index=True, how="left")
print('---------',df)
# df1 left join df on time

if not os.path.exists("./processed/"):
os.makedirs("./processed/")

df.to_csv("./processed/EURUSD-2010_01_01-2012_12_31-test.csv.csv")
assert compare_rows(df, 0, 1) == 5
assert compare_rows(df, 0, 2) == 10
assert compare_rows(df, 0, 3) == 15
assert compare_rows(df, 0, 4) == 20
assert compare_rows(df, 0, 5) == 25
assert compare_rows(df, 0, 6) == 30
assert compare_rows(df, 0, 7) == 35
assert compare_rows(df, 0, 8) == 40
assert compare_rows(df, 0, 9) == 45
assert compare_rows(df, 0, 10) == 50
assert compare_rows(df, 0, 11) == 55
assert compare_rows(df, 0, 12) == 60
assert compare_rows(df, 0, 13) == 65
assert compare_rows(df, 0, 14) == 70
print(df)

if __name__ == "__main__":
file_name = "EURUSD-2010_01_01-2012_12_31-test.csv"
test_compare_rows(file_name)

16 changes: 16 additions & 0 deletions data/idea.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Github Pull Request (PR) Label
The Github label is an addition feature of github to imporove your productivity. Labels can be applied to PR to signify priority, category, or any other information that you find useful. a label bot that will automatically adds labels to PR on iag-edh-data(https://github.customerlabs.com.au/iagcl/iag-edh-data), iag-edh-sor(https://github.customerlabs.com.au/iagcl/iag-edh-sor) and iag-data-transformation-engineering-sql (https://github.customerlabs.com.au/iagcl/iag-data-transformation-engineering-sql) repositories. At release 1.0, it will add checkbot and intergation testing status labels to pull requests like following example;


What does this mean to me?
The label is a value added feature for user to filter out the pull requests that they are interested in. The following example shows how to use the label feature.


What is next step?
We will add more labels based on user's feedback. such as:
- code review status (reviewer assigned, reviewer needed, approved, rejected)
- PR size (S, M, L, XL, XXL)
- PR type (rebase, merge-only, etc)
- project name (project name, off-shore project, hotfix, etc)

NLP AI, like GPT-3, achieved astonishing progress in recent years. There are open source version of GPT (GPT-J w/ 6 billion parameters) available on github, which we can fine tune the pre-trained model to our needs. Imagining that if we use our iag confluence pages or github data to train a model, and create a human-like bot to answer questions, that could be really cool, right?
Binary file removed data/log/GBPUSD-20211027165755.png
Binary file not shown.
Binary file removed data/log/GBPUSD-20211027170145.png
Binary file not shown.
Binary file removed data/log/GBPUSD-20211027170330.png
Binary file not shown.
35 changes: 35 additions & 0 deletions data/markdown.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
have you think about two steps traning DRL?
    since intuitively most of time, the bot (model) shall do nothing just observe.
    so the first stage, we shall train our model by doing nothing with rewards. so the model will output all actions with the same probability to do nothing.

    the second stage, we shall train our model by high epsilon with normal rewards, since PPO is update the model slowly, hopefully it can get some good strategy upgraded of the model.

How to tune hyperparameters?

1. make sure the model is good enough to learn the task.
* choose the simplest mode and data possible.
* once model runs, overfit a single batch and reproduce result.
2. Explore before exploit.
* explore by playing the game.
* swee[ pver hyper-parameters: use coarse-fine random search.
3. Ask yourself: Am I overfitting or underfitting?
* make your model bigger if you underfit.
* make your model smaller if you overfit.
* how to train the model?
* how to evaluate the model?
* how to test the model?
* how to improve the model?

Hope this message reach you well. I am the developer of the forex gym environment project (https://github.com/AI4Finance-Foundation/FinRL-Metaverse/tree/main/neo_finrl/env_fx_trading) . The initial version passed basic unit test. Now we are working on the model training. Since the approach of forex is different from stock, we are facing some challenges of parallel training and hyper-parameter tuning. I know you have a lot of experience in this area. I will try to help you. Would you like to join us?

A couple of developers approach me and show me their interest in the forex project. Just wondering how to leverage and build a core team for the project. Would you like to have a chat sometime?

In a continuous action space, your agent must output some real-valued number, possibly in multiple dimensions. A good example is the MountianCar problem where you must output the force to apply as a real number.

There are a few ways continuous control can be tackled:

Just break the output up into segments, and treat each one as a discrete action. This doesn't work if extreme precision is required (and often is in robotics) or if space if very large (or potentially infinite)

Output parameters to a parametric model, i.e. mean and standard deviation to a normal distribution, then sample from it. I'm not so familiar with this one, but I beleive it's used to encourage exploration.

Directly output the value you want. i.e. in the case of a neural network, instead of outputting the log-probabilities for each action, just output the real-valued directly.
Binary file removed data/models/GBPUSD-week-20211021135753.zip
Binary file not shown.
Binary file removed data/models/GBPUSD-week-20211022103117.zip
Binary file not shown.
Binary file removed data/models/GBPUSD-week-20211022110714.zip
Binary file not shown.
Binary file removed data/models/GBPUSD-week-20211022112546.zip
Binary file not shown.
Binary file removed data/models/GBPUSD-week-20211023081447.zip
Binary file not shown.
Binary file removed data/models/GBPUSD-week-20211025224025.zip
Binary file not shown.
56 changes: 56 additions & 0 deletions data/plan.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
Hi Dr Liu and Rui
I am grateful to have the opportunity to meet you and AI4Finance community here. It's great to see so many passionate scholars and programmers who are willing to share their knowledge and experience in the community.

To further our mission, we shall have a road map and plan for NeoFinRL, and once we completed it, we shall share it within the community. This will bring more people to join us, keep our progress in control, more people actively involved into its development and it will be able to build a better AI4Finance ecosystem.

I have some ideas, interesting topics related to the forex environment development so far I would like to share with you. Hopefully, this also aligns with the direction of the NeoFinRL project.

1. Environment Development
    build a abstract class for all environments.
    * implement fundamental methods for all environments.
        * inherit from gym.Env
        * define action_space and observation_space wrap to gym.Space
        * range define and conversion.
        * balance, reward, transaction fee, penalty, and other methods.
        * multi-pair trading vector and its methods.
        * buy, sell, close, limit order and limit expiration logic.
        * sb3, eRL or any other DRL related parameters and methods.
        * common check and validation methods.
    * implement render
        * log
        * plot
        * print
        * finance analysis report

2. model training and validation
    * remove correlated features
    * normalize features for better observation
    * add features not derived from price, such news (spark), sentiment, etc.
    * quantify all the features and unify then into range of 0.0 - 1.0 for better training.
    * hyperparameter tuning log (use w&b or tensorboard for better visibility)

3. historical dataset/live stream
    * maintain a historical dataset pool
    * unify data format for env API
    * data processor
        * use pd.asfreq as base frequency to group data from any source (tick or bar)
        * add historical data from pool, live stream, etc.
        * add necessary technical indicators
        * add correlated news, sentiment and etc

4. unit test
* setup unit test
* cicd pipeline

5. project management
* core team setup and training


This is a draft. We can work together on it. I would know you thought.

Should we have a regular meeting on zoom? To more effectively communicate, we limit it to 30 mins, must have agenda/topic for each speakers. anyone can drop off at any time if the topic is not interesting to them.

Notice:
This repo is no longer maintained. All my forex enviroment development is moved to https://github.com/AI4Finance-Foundation/FinRL-Metaverse.git. Please join us there, a bigger and more active community.

metaverse is a hottest buzzword.
Loading