### Install and Install Pre-commit Hooks Source: https://finrl.readthedocs.io/en/latest/developer_guide/contributing.html Install the pre-commit tool and then install the pre-commit hooks for the project. This ensures code quality and consistency before committing. ```bash pip install pre-commit pre-commit install ``` -------------------------------- ### Install FinRL on Windows Source: https://finrl.readthedocs.io/en/latest/start/installation.html Installs FinRL and its dependencies after cloning the repository on a Windows system. ```bash cd FinRL pip install . ``` -------------------------------- ### Install box2d Alternative Source: https://finrl.readthedocs.io/en/latest/start/installation.html Provides an alternative installation command for box2d if the initial installation results in an AttributeError. ```bash pip install box2d box2d-kengz ``` -------------------------------- ### Install Ubuntu Dependencies Source: https://finrl.readthedocs.io/en/latest/start/installation.html Installs essential packages required for FinRL on Ubuntu systems. ```bash sudo apt-get update && sudo apt-get install cmake libopenmpi-dev python3-dev zlib1g-dev libgl1-mesa-glx swig ``` -------------------------------- ### Test FinRL Installation Source: https://finrl.readthedocs.io/en/latest/start/installation.html Runs a sample stock trading script to test the FinRL installation, particularly useful if using YahooFinance in China. ```bash python Stock_NeurIPS2018.py ``` -------------------------------- ### Install System Dependencies with Homebrew Source: https://finrl.readthedocs.io/en/latest/start/installation.html Installs cmake and openmpi, which are required system packages for FinRL on macOS. ```bash brew install cmake openmpi ``` -------------------------------- ### Install Ubuntu Dependencies Source: https://finrl.readthedocs.io/en/latest/start/installation.html Installs essential packages for OpenAI and other libraries within an Ubuntu terminal. ```bash sudo apt-get update && sudo apt-get install cmake libopenmpi-dev python3-dev zlib1g-dev libgl1-mesa-glx ``` -------------------------------- ### Install FinRL Development Version Source: https://finrl.readthedocs.io/en/latest/start/installation.html Installs the unstable development version of FinRL directly from its GitHub repository using pip. ```bash pip install git+https://github.com/AI4Finance-Foundation/FinRL.git ``` -------------------------------- ### Install box2d-py and Box2D Source: https://finrl.readthedocs.io/en/latest/start/installation.html Installs the box2d-py and Box2D Python packages, along with system dependencies swig. ```bash brew install swig ``` ```bash pip install box2d-py ``` ```bash pip install box2d ``` ```bash pip install Box2D ``` -------------------------------- ### Install Homebrew Package Manager Source: https://finrl.readthedocs.io/en/latest/start/installation.html Installs Homebrew, a package manager for macOS, which is required for installing system dependencies. ```bash /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" ``` -------------------------------- ### Create and Activate Conda Environment Source: https://finrl.readthedocs.io/en/latest/developer_guide/development_setup.html Create a new Conda environment named 'ai4finance' with Python 3.8 and activate it. Then, navigate to the FinRL directory and install its dependencies. ```bash cd ~/ai4finance conda create --name ai4finance python=3.8 conda activate ai4finance cd FinRL pip install -r requirements.txt ``` -------------------------------- ### Verify Anaconda Python Path Source: https://finrl.readthedocs.io/en/latest/start/installation.html Check if your system's Python interpreter is correctly linked to the Anaconda installation. ```bash /Users/your_user_name/opt/anaconda3/bin/python ``` -------------------------------- ### Clone AI4Finance Repositories Source: https://finrl.readthedocs.io/en/latest/developer_guide/development_setup.html Clone the FinRL, ElegantRL, and FinRL-Meta repositories to your local machine. Ensure you replace '[your_github_username]' with your actual GitHub username. ```bash mkdir ~/ai4finance cd ~/ai4finance git clone https://github.com/[your_github_username]/FinRL.git git clone https://github.com/[your_github_username]/ElegantRL.git git clone https://github.com/[your_github_username]/FinRL-Meta.git ``` -------------------------------- ### Build and Test Docker Container Source: https://finrl.readthedocs.io/en/latest/developer_guide/contributing.html Build the Docker container for the project and then run the tests within that container. This provides a consistent testing environment. ```bash ./docker/bin/build_container.sh ./docker/bin/test.sh ``` -------------------------------- ### FinRL Main Script for Training, Testing, and Trading Source: https://finrl.readthedocs.io/en/latest/start/quick_start.html This script orchestrates the FinRL workflow. It parses command-line arguments to determine the mode (train, test, or trade) and configures the environment and training parameters accordingly. Ensure necessary directories are created before execution. ```python import os from typing import List from argparse import ArgumentParser from finrl import config from finrl.config_tickers import DOW_30_TICKER from finrl.config import ( DATA_SAVE_DIR, TRAINED_MODEL_DIR, TENSORBOARD_LOG_DIR, RESULTS_DIR, INDICATORS, TRAIN_START_DATE, TRAIN_END_DATE, TEST_START_DATE, TEST_END_DATE, TRADE_START_DATE, TRADE_END_DATE, ERL_PARAMS, RLlib_PARAMS, SAC_PARAMS, ALPACA_API_KEY, ALPACA_API_SECRET, ALPACA_API_BASE_URL, ) # construct environment from finrl.meta.env_stock_trading.env_stocktrading_np import StockTradingEnv def build_parser(): parser = ArgumentParser() parser.add_argument( "--mode", dest="mode", help="start mode, train, download_data" " backtest", metavar="MODE", default="train", ) return parser # "./" will be added in front of each directory def check_and_make_directories(directories: List[str]): for directory in directories: if not os.path.exists("./" + directory): os.makedirs("./" + directory) def main(): parser = build_parser() options = parser.parse_args() check_and_make_directories([DATA_SAVE_DIR, TRAINED_MODEL_DIR, TENSORBOARD_LOG_DIR, RESULTS_DIR]) if options.mode == "train": from finrl import train env = StockTradingEnv # demo for elegantrl kwargs = {} # in current meta, with respect yahoofinance, kwargs is {}. For other data sources, such as joinquant, kwargs is not empty train( start_date=TRAIN_START_DATE, end_date=TRAIN_END_DATE, ticker_list=DOW_30_TICKER, data_source="yahoofinance", time_interval="1D", technical_indicator_list=INDICATORS, drl_lib="elegantrl", env=env, model_name="ppo", cwd="./test_ppo", erl_params=ERL_PARAMS, break_step=1e5, kwargs=kwargs, ) elif options.mode == "test": from finrl import test env = StockTradingEnv # demo for elegantrl kwargs = {} # in current meta, with respect yahoofinance, kwargs is {}. For other data sources, such as joinquant, kwargs is not empty account_value_erl = test( start_date=TEST_START_DATE, end_date=TEST_END_DATE, ticker_list=DOW_30_TICKER, data_source="yahoofinance", time_interval="1D", technical_indicator_list=INDICATORS, drl_lib="elegantrl", env=env, model_name="ppo", cwd="./test_ppo", net_dimension=512, kwargs=kwargs, ) elif options.mode == "trade": from finrl import trade env = StockTradingEnv kwargs = {} trade( start_date=TRADE_START_DATE, end_date=TRADE_END_DATE, ticker_list=DOW_30_TICKER, data_source="yahoofinance", time_interval="1D", technical_indicator_list=INDICATORS, drl_lib="elegantrl", env=env, model_name="ppo", API_KEY=ALPACA_API_KEY, API_SECRET=ALPACA_API_SECRET, API_BASE_URL=ALPACA_API_BASE_URL, trade_mode='backtesting', if_vix=True, kwargs=kwargs, ) else: raise ValueError("Wrong mode.") if __name__ == "__main__": main() ``` -------------------------------- ### Create and Checkout a New Git Branch Source: https://finrl.readthedocs.io/en/latest/developer_guide/development_setup.html Navigate to the FinRL directory, create a new branch named 'branch_xxx' (replace with your desired branch name), and checkout this new branch for development. ```bash cd ~/ai4finance cd ./FinRL git checkout -b branch_xxx ``` -------------------------------- ### FinRL Project Structure Source: https://finrl.readthedocs.io/en/latest/developer_guide/file_architecture.html Overview of the FinRL library's file organization, illustrating the placement of core modules and applications within a three-layer architecture. ```text FinRL ├── finrl (the main folder) │ ├── applications │ ├── cryptocurrency_trading │ ├── high_frequency_trading │ ├── portfolio_allocation │ └── stock_trading │ ├── agents │ ├── elegantrl │ ├── rllib │ └── stablebaseline3 │ ├── meta │ ├── data_processors │ ├── env_cryptocurrency_trading │ ├── env_portfolio_allocation │ ├── env_stock_trading │ ├── preprocessor │ ├── data_processor.py │ └── finrl_meta_config.py │ ├── config.py │ ├── config_tickers.py │ ├── main.py │ ├── train.py │ ├── test.py │ ├── trade.py └───└── plot.py ``` -------------------------------- ### Run Unit Tests Locally Source: https://finrl.readthedocs.io/en/latest/developer_guide/contributing.html Execute the project's unit tests locally using the Python unittest module. This helps verify code correctness before submitting changes. ```bash python3 -m unittest discover ``` -------------------------------- ### Running FinRL from Terminal Source: https://finrl.readthedocs.io/en/latest/start/quick_start.html These commands demonstrate how to execute the FinRL main script with different modes. The default ticker list is DOW_30_TICKER. For trade mode, ensure your Alpaca API credentials are set in config.py. ```bash python main.py --mode=train ``` ```bash python main.py --mode=test ``` ```bash python main.py --mode=trade ``` -------------------------------- ### Clone FinRL Repository Source: https://finrl.readthedocs.io/en/latest/start/installation.html Clones the FinRL GitHub repository to your local machine using git. ```bash git clone https://github.com/AI4Finance-Foundation/FinRL.git ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.