Comments (1)
use code:
import os
import pandas as pd
# from my_env_stocktrading import StockTradingEnv
from finrl.meta.env_stock_trading.env_stocktrading import StockTradingEnv
from finrl.agents.stablebaselines3.models import DRLAgent
from stable_baselines3.common.logger import configure
from finrl import config_tickers
from finrl.main import check_and_make_directories
from finrl.config import INDICATORS, TRAINED_MODEL_DIR, RESULTS_DIR
check_and_make_directories([TRAINED_MODEL_DIR])
fn = 'train_data.csv'
# fn = 'my_train.csv'
train = pd.read_csv(fn, dtype={'tic': str})
print(train)
# If you are not using the data generated from part 1 of this tutorial, make sure
# it has the columns and index in the form that could be make into the environment.
# Then you can comment and skip the following two lines.
train = train.set_index(train.columns[0])
train.index.names = ['']
print(train)
stock_dimension = len(train.tic.unique())
state_space = 1 + 2*stock_dimension + len(INDICATORS)*stock_dimension
print(f"Stock Dimension: {stock_dimension}, State Space: {state_space}")
buy_cost_list = sell_cost_list = [0.001] * stock_dimension
num_stock_shares = [0] * stock_dimension
env_kwargs = {
"hmax": 100,
"initial_amount": 1000000,
"num_stock_shares": num_stock_shares,
"buy_cost_pct": buy_cost_list,
"sell_cost_pct": sell_cost_list,
"state_space": state_space,
"stock_dim": stock_dimension,
"tech_indicator_list": INDICATORS,
"action_space": stock_dimension,
"reward_scaling": 1e-4,
"model_name": "ddpg",
"mode": f"{stock_dimension}stocks",
"make_plots": True,
}
e_train_gym = StockTradingEnv(df = train, **env_kwargs)
env_train, _ = e_train_gym.get_sb_env()
print(type(env_train))
# Set the corresponding values to 'True' for the algorithms that you want to use
if_using_a2c = True
if_using_ddpg = True
if_using_ppo = False
if_using_td3 = False
if_using_sac = False
agent = DRLAgent(env = env_train)
model_ddpg = agent.get_model("ddpg")
if if_using_ddpg:
# set up logger
tmp_path = RESULTS_DIR + '/ddpg'
new_logger_ddpg = configure(tmp_path, ["stdout", "csv", "tensorboard"])
# Set new logger
model_ddpg.set_logger(new_logger_ddpg)
trained_ddpg = agent.train_model(model=model_ddpg,
tb_log_name='ddpg',
total_timesteps=50000) if if_using_ddpg else None
trained_ddpg.save(TRAINED_MODEL_DIR + "/agent_ddpg") if if_using_ddpg else None
from finrl.
Related Issues (20)
- Same reward thought the training in DDPG
- backtest_plot() have internal problem associated with pandas version HOT 1
- YahooFinanceProcessor failure to download the market data HOT 2
- Full dataset normalization biases test set HOT 1
- Some Technical indicators not supported HOT 1
- Proof of RL viability for trading with data leakage HOT 2
- could not import finrl in google colab HOT 2
- SAC model on testing set is allocating same weights to a given TIC on consecutive days HOT 1
- Value error after running 50000 timesteps HOT 1
- how to save the model ? HOT 1
- Is there a way to look at the Expected Rewards of each timestamp in the testing set? HOT 3
- Is there a way to prevent the FinRL model from doing any Short selling HOT 1
- all the input array dimensions except for the concatenation axis must match exactly when running FinRL_PortfolioOptimizationEnv_Demo with CAC40 Data HOT 1
- Do train and test dataframes have to have the same column ordering ? HOT 1
- Can't reproduce test results with FinRL after restarting Jupyter Notebook Kernel HOT 3
- Does each TIC get access to ONLY its own technical features or does it get access to technical features of other TIC`s as well
- How does the tech_indicator_list work in the env_kwargs of FinRL?
- Question about portfolio optimization steps
- 'NoneType' object is not subscriptable in DRL_prediction.
- SAC model using FinRL retrained after 1.5 months gap is showing different results. Was anything changed in the SAC architecture in the last 1.5 months? HOT 1
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 finrl.