- Load the Trained Model: Replace the
...
with the method you use to load your trained model (e.g., withpickle
or TensorFlow). - Retrieve Market Data: The Alpaca API is used to fetch the latest market data for the specific stock.
- Predict Actions: The model predicts the action (buy/sell/hold) based on the current market data.
- Execute Trades: The predicted action is executed via the Alpaca API.
- Scheduler: You can automate the execution of this script using a task scheduler like
cron
on Unix-based systems or Task Scheduler on Windows. - Daily Updates: Make sure to run this script at the start of each trading day to decide the actions for that day.
This is a basic example. Depending on your strategy, you may need to handle more complexities like position sizing, multiple assets, risk management, etc.
*Yahoo Finance (through the yfinance library)*
*Yahoo Finance (only up to last 7 days), through the yfinance library. It is the only option besides scraping (or paying for a service provider)*
*No, as this is more of an execution strategy related to risk control. You can use it as part of your system, adding the risk control part as a separate component*
*Yes, you can add it. Remember to check on the code that this additional feature is being fed to the model (state)*
*No, you'll have to use a paid service or library/code to scrape news and obtain the sentiment from them (normally, using deep learning and NLP)*
*Yes, it does*
*Yes, because the current parameters are defined for daily data. You'll have to tune the model for intraday trading*
*Not many yet, but we're working on providing different reward functions and an easy way to set your own reward function*
*Yes, but none is available at the moment. Sometimes in the literature you'll find this referred to as transfer learning*
*Each model has its own hyperparameters,
but the most important is the total_timesteps (think of it as epochs in a neural network:
even if all the other hyperparameters are optimal,
with few epochs the model will have a bad performance). The other important hyperparameters,
in general, are: learning_rate, batch_size, ent_coef, buffer_size, policy, and reward scaling
*There are several, such as: Ray Tune and Optuna. You can start from our examples in the tutorials
*We suggest using ElegantRL or Stable Baselines 3. We tested the following models with success:
A2C, A3C, DDPG, PPO, SAC, TD3, TRPO. You can also create your own algorithm,
with an OpenAI Gym-style market environment*
check if the hyperparameters used were not outside a normal range (ex: learning rate too high), and run the code again. If you still have problems, please check Section 2 (What to do when you experience problems)*
- :raw-html: `<font color="#A52A2A">What to do when you experience problems? ***
*1. Check if it is not already answered on this FAQ 2. Check if it is posted on the GitHub repo* `issues <https://github.com/AI4Finance-LLC/the softwre-Library/issues>`_. If not, welcome to submit an issue on GitHub 3. Use the correct channel on the AI4Finance slack or Wechat group.*
- :raw-html: `<font color="#A52A2A">Does anyone know if there is a trading environment for a single stock? There is one in the docs, but the collab link seems to be broken. ***
*We did not update the single stock for long time. The performance for single stock is not very good, since the state space is too small so that the agent extract little information from the environment. Please use the multi stock environment, and after training only use the single stock to trade.*
.. _Section-3:
*Not exactly. Depending on the period, the asset, the model chosen, and the hyperparameters used, BH may be very difficult to beat (it's almost never beaten on stocks/periods with low volatility and steady growth). Nevertheless, update the library and its dependencies (the github repo has the most recent version), and check the example notebook for the specific environment type (single, multi, portfolio optimization) to see if the code is running correctly*
*We use the Pyfolio backtest library from Quantopian ( https://github.com/quantopian/pyfolio ), especially the simple tear sheet and its charts. In general, the most important metrics are: annual returns, cumulative returns, annual volatility, sharpe ratio, calmar ratio, stability, and max drawdown*
*There are several metrics, but we recommend the following, as they are the most used in the market: annual returns, cumulative returns, annual volatility, sharpe ratio, calmar ratio, stability, and max drawdown*
*We recommend using buy and hold (BH), as it is a strategy that can be followed on any market and tends to provide good results in the long run. You can also compare with other DRL models and trading strategies such as the minimum variance portfolio*
*Not yet. We're developing this functionality*
*Not yet. We're developing this functionality*
*Not yet. We're developing this functionality*
*Not yet*