diff --git a/examples/FinRL_PaperTrading_Demo_refactored.py b/examples/FinRL_PaperTrading_Demo_refactored.py
new file mode 100644
index 000000000..40af3d16c
--- /dev/null
+++ b/examples/FinRL_PaperTrading_Demo_refactored.py
@@ -0,0 +1,199 @@
+# Disclaimer: Nothing herein is financial advice, and NOT a recommendation to trade real money. Many platforms exist for simulated trading (paper trading) which can be used for building and developing the methods discussed. Please use common sense and always first consult a professional before trading or investing.
+# install finrl library
+# %pip install --upgrade git+https://github.com/AI4Finance-Foundation/FinRL.git
+# Alpaca keys
+from __future__ import annotations
+
+import argparse
+
+parser = argparse.ArgumentParser()
+parser.add_argument("data_key", help="data source api key")
+parser.add_argument("data_secret", help="data source api secret")
+parser.add_argument("data_url", help="data source api base url")
+parser.add_argument("trading_key", help="trading api key")
+parser.add_argument("trading_secret", help="trading api secret")
+parser.add_argument("trading_url", help="trading api base url")
+args = parser.parse_args()
+DATA_API_KEY = args.data_key
+DATA_API_SECRET = args.data_secret
+DATA_API_BASE_URL = args.data_url
+TRADING_API_KEY = args.trading_key
+TRADING_API_SECRET = args.trading_secret
+TRADING_API_BASE_URL = args.trading_url
+
+print("DATA_API_KEY: ", DATA_API_KEY)
+print("DATA_API_SECRET: ", DATA_API_SECRET)
+print("DATA_API_BASE_URL: ", DATA_API_BASE_URL)
+print("TRADING_API_KEY: ", TRADING_API_KEY)
+print("TRADING_API_SECRET: ", TRADING_API_SECRET)
+print("TRADING_API_BASE_URL: ", TRADING_API_BASE_URL)
+
+from finrl.meta.env_stock_trading.env_stocktrading_np import StockTradingEnv
+from finrl.meta.paper_trading.alpaca import PaperTradingAlpaca
+from finrl.meta.paper_trading.common import train, test, alpaca_history, DIA_history
+from finrl.config import INDICATORS
+
+# Import Dow Jones 30 Symbols
+from finrl.config_tickers import DOW_30_TICKER
+
+ticker_list = DOW_30_TICKER
+env = StockTradingEnv
+# if you want to use larger datasets (change to longer period), and it raises error, please try to increase "target_step". It should be larger than the episode steps.
+ERL_PARAMS = {
+ "learning_rate": 3e-6,
+ "batch_size": 2048,
+ "gamma": 0.985,
+ "seed": 312,
+ "net_dimension": [128, 64],
+ "target_step": 5000,
+ "eval_gap": 30,
+ "eval_times": 1,
+}
+
+# Set up sliding window of 6 days training and 2 days testing
+import datetime
+from pandas.tseries.offsets import BDay # BDay is business day, not birthday...
+
+today = datetime.datetime.today()
+
+TEST_END_DATE = (today - BDay(1)).to_pydatetime().date()
+TEST_START_DATE = (TEST_END_DATE - BDay(1)).to_pydatetime().date()
+TRAIN_END_DATE = (TEST_START_DATE - BDay(1)).to_pydatetime().date()
+TRAIN_START_DATE = (TRAIN_END_DATE - BDay(5)).to_pydatetime().date()
+TRAINFULL_START_DATE = TRAIN_START_DATE
+TRAINFULL_END_DATE = TEST_END_DATE
+
+TRAIN_START_DATE = str(TRAIN_START_DATE)
+TRAIN_END_DATE = str(TRAIN_END_DATE)
+TEST_START_DATE = str(TEST_START_DATE)
+TEST_END_DATE = str(TEST_END_DATE)
+TRAINFULL_START_DATE = str(TRAINFULL_START_DATE)
+TRAINFULL_END_DATE = str(TRAINFULL_END_DATE)
+
+print("TRAIN_START_DATE: ", TRAIN_START_DATE)
+print("TRAIN_END_DATE: ", TRAIN_END_DATE)
+print("TEST_START_DATE: ", TEST_START_DATE)
+print("TEST_END_DATE: ", TEST_END_DATE)
+print("TRAINFULL_START_DATE: ", TRAINFULL_START_DATE)
+print("TRAINFULL_END_DATE: ", TRAINFULL_END_DATE)
+
+train(
+ start_date=TRAIN_START_DATE,
+ end_date=TRAIN_END_DATE,
+ ticker_list=ticker_list,
+ data_source="alpaca",
+ time_interval="1Min",
+ technical_indicator_list=INDICATORS,
+ drl_lib="elegantrl",
+ env=env,
+ model_name="ppo",
+ if_vix=True,
+ API_KEY=DATA_API_KEY,
+ API_SECRET=DATA_API_SECRET,
+ API_BASE_URL=DATA_API_BASE_URL,
+ erl_params=ERL_PARAMS,
+ cwd="./papertrading_erl", # current_working_dir
+ break_step=1e5,
+)
+
+account_value_erl = test(
+ start_date=TEST_START_DATE,
+ end_date=TEST_END_DATE,
+ ticker_list=ticker_list,
+ data_source="alpaca",
+ time_interval="1Min",
+ technical_indicator_list=INDICATORS,
+ drl_lib="elegantrl",
+ env=env,
+ model_name="ppo",
+ if_vix=True,
+ API_KEY=DATA_API_KEY,
+ API_SECRET=DATA_API_SECRET,
+ API_BASE_URL=DATA_API_BASE_URL,
+ cwd="./papertrading_erl",
+ net_dimension=ERL_PARAMS["net_dimension"],
+)
+
+train(
+ start_date=TRAINFULL_START_DATE, # After tuning well, retrain on the training and testing sets
+ end_date=TRAINFULL_END_DATE,
+ ticker_list=ticker_list,
+ data_source="alpaca",
+ time_interval="1Min",
+ technical_indicator_list=INDICATORS,
+ drl_lib="elegantrl",
+ env=env,
+ model_name="ppo",
+ if_vix=True,
+ API_KEY=DATA_API_KEY,
+ API_SECRET=DATA_API_SECRET,
+ API_BASE_URL=DATA_API_BASE_URL,
+ erl_params=ERL_PARAMS,
+ cwd="./papertrading_erl_retrain",
+ break_step=2e5,
+)
+
+action_dim = len(DOW_30_TICKER)
+state_dim = (
+ 1 + 2 + 3 * action_dim + len(INDICATORS) * action_dim
+) # Calculate the DRL state dimension manually for paper trading. amount + (turbulence, turbulence_bool) + (price, shares, cd (holding time)) * stock_dim + tech_dim
+
+paper_trading_erl = PaperTradingAlpaca(
+ ticker_list=DOW_30_TICKER,
+ time_interval="1Min",
+ drl_lib="elegantrl",
+ agent="ppo",
+ cwd="./papertrading_erl_retrain",
+ net_dim=ERL_PARAMS["net_dimension"],
+ state_dim=state_dim,
+ action_dim=action_dim,
+ API_KEY=TRADING_API_KEY,
+ API_SECRET=TRADING_API_SECRET,
+ API_BASE_URL=TRADING_API_BASE_URL,
+ tech_indicator_list=INDICATORS,
+ turbulence_thresh=30,
+ max_stock=1e2,
+)
+
+paper_trading_erl.run()
+
+# Check Portfolio Performance
+# ## Get cumulative return
+df_erl, cumu_erl = alpaca_history(
+ key=DATA_API_KEY,
+ secret=DATA_API_SECRET,
+ url=DATA_API_BASE_URL,
+ start="2022-09-01", # must be within 1 month
+ end="2022-09-12",
+) # change the date if error occurs
+
+df_djia, cumu_djia = DIA_history(start="2022-09-01")
+returns_erl = cumu_erl - 1
+returns_dia = cumu_djia - 1
+returns_dia = returns_dia[: returns_erl.shape[0]]
+
+# plot and save
+import matplotlib.pyplot as plt
+
+plt.figure(dpi=1000)
+plt.grid()
+plt.grid(which="minor", axis="y")
+plt.title("Stock Trading (Paper trading)", fontsize=20)
+plt.plot(returns_erl, label="ElegantRL Agent", color="red")
+# plt.plot(returns_sb3, label = 'Stable-Baselines3 Agent', color = 'blue' )
+# plt.plot(returns_rllib, label = 'RLlib Agent', color = 'green')
+plt.plot(returns_dia, label="DJIA", color="grey")
+plt.ylabel("Return", fontsize=16)
+plt.xlabel("Year 2021", fontsize=16)
+plt.xticks(size=14)
+plt.yticks(size=14)
+ax = plt.gca()
+ax.xaxis.set_major_locator(ticker.MultipleLocator(78))
+ax.xaxis.set_minor_locator(ticker.MultipleLocator(6))
+ax.yaxis.set_minor_locator(ticker.MultipleLocator(0.005))
+ax.yaxis.set_major_formatter(ticker.PercentFormatter(xmax=1, decimals=2))
+ax.xaxis.set_major_formatter(
+ ticker.FixedFormatter(["", "10-19", "", "10-20", "", "10-21", "", "10-22"])
+)
+plt.legend(fontsize=10.5)
+plt.savefig("papertrading_stock.png")
diff --git a/examples/Stock_NeurIPS2018_1_Data.ipynb b/examples/Stock_NeurIPS2018_1_Data.ipynb
index a189e29c3..9712f35f6 100644
--- a/examples/Stock_NeurIPS2018_1_Data.ipynb
+++ b/examples/Stock_NeurIPS2018_1_Data.ipynb
@@ -37,7 +37,7 @@
},
{
"cell_type": "code",
- "execution_count": 1,
+ "execution_count": 2,
"metadata": {
"id": "j37flV31OJGW"
},
@@ -384,1048 +384,297 @@
"height": 206
},
"id": "_TgEjXxhXtT_",
- "outputId": "a8e8a9e2-a1ea-472e-eddf-2227e6c901d8"
- },
- "outputs": [
- {
- "data": {
- "text/html": [
- "\n",
- "
\n",
- "
\n",
- "
\n",
- "\n",
- "
\n",
- " \n",
- " \n",
- " | \n",
- " date | \n",
- " open | \n",
- " high | \n",
- " low | \n",
- " close | \n",
- " volume | \n",
- " tic | \n",
- " day | \n",
- "
\n",
- " \n",
- " \n",
- " \n",
- " 0 | \n",
- " 2020-01-02 | \n",
- " 74.059998 | \n",
- " 75.150002 | \n",
- " 73.797501 | \n",
- " 73.449394 | \n",
- " 135480400 | \n",
- " aapl | \n",
- " 3 | \n",
- "
\n",
- " \n",
- " 1 | \n",
- " 2020-01-03 | \n",
- " 74.287498 | \n",
- " 75.144997 | \n",
- " 74.125000 | \n",
- " 72.735313 | \n",
- " 146322800 | \n",
- " aapl | \n",
- " 4 | \n",
- "
\n",
- " \n",
- " 2 | \n",
- " 2020-01-06 | \n",
- " 73.447502 | \n",
- " 74.989998 | \n",
- " 73.187500 | \n",
- " 73.314888 | \n",
- " 118387200 | \n",
- " aapl | \n",
- " 0 | \n",
- "
\n",
- " \n",
- " 3 | \n",
- " 2020-01-07 | \n",
- " 74.959999 | \n",
- " 75.224998 | \n",
- " 74.370003 | \n",
- " 72.970078 | \n",
- " 108872000 | \n",
- " aapl | \n",
- " 1 | \n",
- "
\n",
- " \n",
- " 4 | \n",
- " 2020-01-08 | \n",
- " 74.290001 | \n",
- " 76.110001 | \n",
- " 74.290001 | \n",
- " 74.143906 | \n",
- " 132079200 | \n",
- " aapl | \n",
- " 2 | \n",
- "
\n",
- " \n",
- "
\n",
- "
\n",
- "
\n",
- " \n",
- " \n",
- "\n",
- " \n",
- "
\n",
- "
\n",
- " "
- ],
- "text/plain": [
- " date open high low close volume tic \\\n",
- "0 2020-01-02 74.059998 75.150002 73.797501 73.449394 135480400 aapl \n",
- "1 2020-01-03 74.287498 75.144997 74.125000 72.735313 146322800 aapl \n",
- "2 2020-01-06 73.447502 74.989998 73.187500 73.314888 118387200 aapl \n",
- "3 2020-01-07 74.959999 75.224998 74.370003 72.970078 108872000 aapl \n",
- "4 2020-01-08 74.290001 76.110001 74.290001 74.143906 132079200 aapl \n",
- "\n",
- " day \n",
- "0 3 \n",
- "1 4 \n",
- "2 0 \n",
- "3 1 \n",
- "4 2 "
- ]
- },
- "execution_count": 7,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "aapl_df_finrl.head()"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {
- "id": "9kcOE5nbic6R"
- },
- "source": [
- "## Data for the chosen tickers"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 4,
- "metadata": {
- "colab": {
- "base_uri": "https://localhost:8080/"
- },
- "id": "FKBjtAo2uIq5",
- "outputId": "927f682a-9cc3-4c11-c3f1-094ae811af6b"
- },
- "outputs": [
- {
- "data": {
- "text/plain": [
- "631"
- ]
- },
- "execution_count": 4,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "len(config_tickers.DOW_30_TICKER+config_tickers.NAS_100_TICKER+config_tickers.SP_500_TICKER)"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 2,
- "metadata": {
- "id": "9xTPG4Fhc-zL"
- },
- "outputs": [],
- "source": [
- "TRAIN_START_DATE = '2000-01-01'\n",
- "TRAIN_END_DATE = '2024-01-01'\n",
- "TRADE_START_DATE = '2023-09-01'\n",
- "TRADE_END_DATE = '2024-09-01'"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 5,
- "metadata": {
- "colab": {
- "base_uri": "https://localhost:8080/"
- },
- "id": "9LblMI8CO0F3",
- "outputId": "7be76385-50eb-4e8d-f2e5-1795d77b70ba"
- },
- "outputs": [
- {
- "name": "stderr",
- "output_type": "stream",
- "text": [
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "\n",
- "1 Failed download:\n",
- "['XLNX']: YFTzMissingError('$%ticker%: possibly delisted; no timezone found')\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "\n",
- "1 Failed download:\n",
- "['CTXS']: YFTzMissingError('$%ticker%: possibly delisted; no timezone found')\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "\n",
- "1 Failed download:\n",
- "['NLOK']: YFTzMissingError('$%ticker%: possibly delisted; no timezone found')\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "\n",
- "1 Failed download:\n",
- "['ATVI']: YFPricesMissingError('$%ticker%: possibly delisted; no price data found (1d 2000-01-01 -> 2024-09-01) (Yahoo error = \"No data found, symbol may be delisted\")')\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "\n",
- "1 Failed download:\n",
- "['CERN']: YFTzMissingError('$%ticker%: possibly delisted; no timezone found')\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "\n",
- "1 Failed download:\n",
- "['MYL']: YFTzMissingError('$%ticker%: possibly delisted; no timezone found')\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "\n",
- "1 Failed download:\n",
- "['ALXN']: YFTzMissingError('$%ticker%: possibly delisted; no timezone found')\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "\n",
- "1 Failed download:\n",
- "['FB']: YFTzMissingError('$%ticker%: possibly delisted; no timezone found')\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "\n",
- "1 Failed download:\n",
- "['MXIM']: YFTzMissingError('$%ticker%: possibly delisted; no timezone found')\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "\n",
- "1 Failed download:\n",
- "['WLTW']: YFTzMissingError('$%ticker%: possibly delisted; no timezone found')\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "\n",
- "1 Failed download:\n",
- "['ABC']: YFTzMissingError('$%ticker%: possibly delisted; no timezone found')\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "\n",
- "1 Failed download:\n",
- "['ABMD']: YFTzMissingError('$%ticker%: possibly delisted; no timezone found')\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "\n",
- "1 Failed download:\n",
- "['ADS']: YFTzMissingError('$%ticker%: possibly delisted; no timezone found')\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "\n",
- "1 Failed download:\n",
- "['AGN']: YFTzMissingError('$%ticker%: possibly delisted; no timezone found')\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "\n",
- "1 Failed download:\n",
- "['ALXN']: YFTzMissingError('$%ticker%: possibly delisted; no timezone found')\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "\n",
- "1 Failed download:\n",
- "['ANTM']: YFTzMissingError('$%ticker%: possibly delisted; no timezone found')\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "\n",
- "1 Failed download:\n",
- "['ARNC']: YFTzMissingError('$%ticker%: possibly delisted; no timezone found')\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "\n",
- "1 Failed download:\n",
- "['ATVI']: YFPricesMissingError('$%ticker%: possibly delisted; no price data found (1d 2000-01-01 -> 2024-09-01) (Yahoo error = \"No data found, symbol may be delisted\")')\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "\n",
- "1 Failed download:\n",
- "['BBT']: YFTzMissingError('$%ticker%: possibly delisted; no timezone found')\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "\n",
- "1 Failed download:\n",
- "['BF.B']: YFPricesMissingError('$%ticker%: possibly delisted; no price data found (1d 2000-01-01 -> 2024-09-01)')\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "\n",
- "1 Failed download:\n",
- "['BHGE']: YFTzMissingError('$%ticker%: possibly delisted; no timezone found')\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "\n",
- "1 Failed download:\n",
- "['BLL']: YFTzMissingError('$%ticker%: possibly delisted; no timezone found')\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "\n",
- "1 Failed download:\n",
- "['BRK.B']: YFTzMissingError('$%ticker%: possibly delisted; no timezone found')\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "\n",
- "1 Failed download:\n",
- "['CBS']: YFTzMissingError('$%ticker%: possibly delisted; no timezone found')\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "\n",
- "1 Failed download:\n",
- "['CELG']: YFTzMissingError('$%ticker%: possibly delisted; no timezone found')\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "\n",
- "1 Failed download:\n",
- "['CERN']: YFTzMissingError('$%ticker%: possibly delisted; no timezone found')\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "\n",
- "1 Failed download:\n",
- "['COG']: YFTzMissingError('$%ticker%: possibly delisted; no timezone found')\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "\n",
- "1 Failed download:\n",
- "['CTL']: YFTzMissingError('$%ticker%: possibly delisted; no timezone found')\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "\n",
- "1 Failed download:\n",
- "['CTXS']: YFTzMissingError('$%ticker%: possibly delisted; no timezone found')\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "\n",
- "1 Failed download:\n",
- "['CXO']: YFTzMissingError('$%ticker%: possibly delisted; no timezone found')\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "\n",
- "1 Failed download:\n",
- "['DISCK']: YFTzMissingError('$%ticker%: possibly delisted; no timezone found')\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "\n",
- "1 Failed download:\n",
- "['DISH']: YFTzMissingError('$%ticker%: possibly delisted; no timezone found')\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "\n",
- "1 Failed download:\n",
- "['DRE']: YFTzMissingError('$%ticker%: possibly delisted; no timezone found')\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "\n",
- "1 Failed download:\n",
- "['ETFC']: YFTzMissingError('$%ticker%: possibly delisted; no timezone found')\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "\n",
- "1 Failed download:\n",
- "['FB']: YFTzMissingError('$%ticker%: possibly delisted; no timezone found')\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "\n",
- "1 Failed download:\n",
- "['FBHS']: YFTzMissingError('$%ticker%: possibly delisted; no timezone found')\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "\n",
- "1 Failed download:\n",
- "['FLIR']: YFTzMissingError('$%ticker%: possibly delisted; no timezone found')\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "\n",
- "1 Failed download:\n",
- "['FLT']: YFTzMissingError('$%ticker%: possibly delisted; no timezone found')\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "\n",
- "1 Failed download:\n",
- "['FRC']: YFTzMissingError('$%ticker%: possibly delisted; no timezone found')\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "\n",
- "1 Failed download:\n",
- "['HFC']: YFTzMissingError('$%ticker%: possibly delisted; no timezone found')\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "\n",
- "1 Failed download:\n",
- "['INFO']: YFTzMissingError('$%ticker%: possibly delisted; no timezone found')\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "\n",
- "1 Failed download:\n",
- "['JEC']: YFTzMissingError('$%ticker%: possibly delisted; no timezone found')\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "\n",
- "1 Failed download:\n",
- "['KSU']: YFTzMissingError('$%ticker%: possibly delisted; no timezone found')\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "\n",
- "1 Failed download:\n",
- "['MXIM']: YFTzMissingError('$%ticker%: possibly delisted; no timezone found')\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "\n",
- "1 Failed download:\n",
- "['MYL']: YFTzMissingError('$%ticker%: possibly delisted; no timezone found')\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "\n",
- "1 Failed download:\n",
- "['NBL']: YFTzMissingError('$%ticker%: possibly delisted; no timezone found')\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "\n",
- "1 Failed download:\n",
- "['NLSN']: YFTzMissingError('$%ticker%: possibly delisted; no timezone found')\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "\n",
- "1 Failed download:\n",
- "['PBCT']: YFTzMissingError('$%ticker%: possibly delisted; no timezone found')\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "\n",
- "1 Failed download:\n",
- "['PKI']: YFTzMissingError('$%ticker%: possibly delisted; no timezone found')\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "\n",
- "1 Failed download:\n",
- "['PXD']: YFTzMissingError('$%ticker%: possibly delisted; no timezone found')\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "\n",
- "1 Failed download:\n",
- "['RE']: YFTzMissingError('$%ticker%: possibly delisted; no timezone found')\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "\n",
- "1 Failed download:\n",
- "['RTN']: YFTzMissingError('$%ticker%: possibly delisted; no timezone found')\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "\n",
- "1 Failed download:\n",
- "['SIVB']: YFPricesMissingError('$%ticker%: possibly delisted; no price data found (1d 2000-01-01 -> 2024-09-01)')\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "\n",
- "1 Failed download:\n",
- "['SYMC']: YFTzMissingError('$%ticker%: possibly delisted; no timezone found')\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "\n",
- "1 Failed download:\n",
- "['TIF']: YFTzMissingError('$%ticker%: possibly delisted; no timezone found')\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "\n",
- "1 Failed download:\n",
- "['TSS']: YFTzMissingError('$%ticker%: possibly delisted; no timezone found')\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "\n",
- "1 Failed download:\n",
- "['TWTR']: YFTzMissingError('$%ticker%: possibly delisted; no timezone found')\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "\n",
- "1 Failed download:\n",
- "['UTX']: YFTzMissingError('$%ticker%: possibly delisted; no timezone found')\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "\n",
- "1 Failed download:\n",
- "['VAR']: YFTzMissingError('$%ticker%: possibly delisted; no timezone found')\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "\n",
- "1 Failed download:\n",
- "['VIAB']: YFTzMissingError('$%ticker%: possibly delisted; no timezone found')\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n",
+ "outputId": "a8e8a9e2-a1ea-472e-eddf-2227e6c901d8"
+ },
+ "outputs": [
+ {
+ "data": {
+ "text/html": [
+ "\n",
+ " \n",
+ "
\n",
+ "
\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " date | \n",
+ " open | \n",
+ " high | \n",
+ " low | \n",
+ " close | \n",
+ " volume | \n",
+ " tic | \n",
+ " day | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " 0 | \n",
+ " 2020-01-02 | \n",
+ " 74.059998 | \n",
+ " 75.150002 | \n",
+ " 73.797501 | \n",
+ " 73.449394 | \n",
+ " 135480400 | \n",
+ " aapl | \n",
+ " 3 | \n",
+ "
\n",
+ " \n",
+ " 1 | \n",
+ " 2020-01-03 | \n",
+ " 74.287498 | \n",
+ " 75.144997 | \n",
+ " 74.125000 | \n",
+ " 72.735313 | \n",
+ " 146322800 | \n",
+ " aapl | \n",
+ " 4 | \n",
+ "
\n",
+ " \n",
+ " 2 | \n",
+ " 2020-01-06 | \n",
+ " 73.447502 | \n",
+ " 74.989998 | \n",
+ " 73.187500 | \n",
+ " 73.314888 | \n",
+ " 118387200 | \n",
+ " aapl | \n",
+ " 0 | \n",
+ "
\n",
+ " \n",
+ " 3 | \n",
+ " 2020-01-07 | \n",
+ " 74.959999 | \n",
+ " 75.224998 | \n",
+ " 74.370003 | \n",
+ " 72.970078 | \n",
+ " 108872000 | \n",
+ " aapl | \n",
+ " 1 | \n",
+ "
\n",
+ " \n",
+ " 4 | \n",
+ " 2020-01-08 | \n",
+ " 74.290001 | \n",
+ " 76.110001 | \n",
+ " 74.290001 | \n",
+ " 74.143906 | \n",
+ " 132079200 | \n",
+ " aapl | \n",
+ " 2 | \n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
\n",
+ "
\n",
+ " \n",
+ " \n",
+ "\n",
+ " \n",
+ "
\n",
+ "
\n",
+ " "
+ ],
+ "text/plain": [
+ " date open high low close volume tic \\\n",
+ "0 2020-01-02 74.059998 75.150002 73.797501 73.449394 135480400 aapl \n",
+ "1 2020-01-03 74.287498 75.144997 74.125000 72.735313 146322800 aapl \n",
+ "2 2020-01-06 73.447502 74.989998 73.187500 73.314888 118387200 aapl \n",
+ "3 2020-01-07 74.959999 75.224998 74.370003 72.970078 108872000 aapl \n",
+ "4 2020-01-08 74.290001 76.110001 74.290001 74.143906 132079200 aapl \n",
+ "\n",
+ " day \n",
+ "0 3 \n",
+ "1 4 \n",
+ "2 0 \n",
+ "3 1 \n",
+ "4 2 "
+ ]
+ },
+ "execution_count": 7,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "aapl_df_finrl.head()"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "id": "9kcOE5nbic6R"
+ },
+ "source": [
+ "## Data for the chosen tickers"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 8,
+ "metadata": {
+ "colab": {
+ "base_uri": "https://localhost:8080/"
+ },
+ "id": "FKBjtAo2uIq5",
+ "outputId": "927f682a-9cc3-4c11-c3f1-094ae811af6b"
+ },
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "['AXP',\n",
+ " 'AMGN',\n",
+ " 'AAPL',\n",
+ " 'BA',\n",
+ " 'CAT',\n",
+ " 'CSCO',\n",
+ " 'CVX',\n",
+ " 'GS',\n",
+ " 'HD',\n",
+ " 'HON',\n",
+ " 'IBM',\n",
+ " 'INTC',\n",
+ " 'JNJ',\n",
+ " 'KO',\n",
+ " 'JPM',\n",
+ " 'MCD',\n",
+ " 'MMM',\n",
+ " 'MRK',\n",
+ " 'MSFT',\n",
+ " 'NKE',\n",
+ " 'PG',\n",
+ " 'TRV',\n",
+ " 'UNH',\n",
+ " 'CRM',\n",
+ " 'VZ',\n",
+ " 'V',\n",
+ " 'WBA',\n",
+ " 'WMT',\n",
+ " 'DIS',\n",
+ " 'DOW']"
+ ]
+ },
+ "execution_count": 8,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "config_tickers.DOW_30_TICKER"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 9,
+ "metadata": {
+ "id": "9xTPG4Fhc-zL"
+ },
+ "outputs": [],
+ "source": [
+ "TRAIN_START_DATE = '2009-01-01'\n",
+ "TRAIN_END_DATE = '2020-07-01'\n",
+ "TRADE_START_DATE = '2020-07-01'\n",
+ "TRADE_END_DATE = '2021-10-29'"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 10,
+ "metadata": {
+ "colab": {
+ "base_uri": "https://localhost:8080/"
+ },
+ "id": "9LblMI8CO0F3",
+ "outputId": "7be76385-50eb-4e8d-f2e5-1795d77b70ba"
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
"[*********************100%***********************] 1 of 1 completed\n",
"[*********************100%***********************] 1 of 1 completed\n",
"[*********************100%***********************] 1 of 1 completed\n",
@@ -1433,37 +682,22 @@
"[*********************100%***********************] 1 of 1 completed\n",
"[*********************100%***********************] 1 of 1 completed\n",
"[*********************100%***********************] 1 of 1 completed\n",
- "\n",
- "1 Failed download:\n",
- "['WCG']: YFTzMissingError('$%ticker%: possibly delisted; no timezone found')\n",
"[*********************100%***********************] 1 of 1 completed\n",
"[*********************100%***********************] 1 of 1 completed\n",
"[*********************100%***********************] 1 of 1 completed\n",
"[*********************100%***********************] 1 of 1 completed\n",
"[*********************100%***********************] 1 of 1 completed\n",
"[*********************100%***********************] 1 of 1 completed\n",
- "\n",
- "1 Failed download:\n",
- "['WLTW']: YFTzMissingError('$%ticker%: possibly delisted; no timezone found')\n",
"[*********************100%***********************] 1 of 1 completed\n",
"[*********************100%***********************] 1 of 1 completed\n",
"[*********************100%***********************] 1 of 1 completed\n",
"[*********************100%***********************] 1 of 1 completed\n",
- "\n",
- "1 Failed download:\n",
- "['WRK']: YFTzMissingError('$%ticker%: possibly delisted; no timezone found')\n",
"[*********************100%***********************] 1 of 1 completed\n",
"[*********************100%***********************] 1 of 1 completed\n",
"[*********************100%***********************] 1 of 1 completed\n",
"[*********************100%***********************] 1 of 1 completed\n",
- "\n",
- "1 Failed download:\n",
- "['XEC']: YFTzMissingError('$%ticker%: possibly delisted; no timezone found')\n",
"[*********************100%***********************] 1 of 1 completed\n",
"[*********************100%***********************] 1 of 1 completed\n",
- "\n",
- "1 Failed download:\n",
- "['XLNX']: YFTzMissingError('$%ticker%: possibly delisted; no timezone found')\n",
"[*********************100%***********************] 1 of 1 completed\n",
"[*********************100%***********************] 1 of 1 completed\n",
"[*********************100%***********************] 1 of 1 completed\n",
@@ -1471,35 +705,14 @@
"[*********************100%***********************] 1 of 1 completed\n",
"[*********************100%***********************] 1 of 1 completed\n",
"[*********************100%***********************] 1 of 1 completed\n",
- "[*********************100%***********************] 1 of 1 completed\n"
- ]
- },
- {
- "ename": "MemoryError",
- "evalue": "Unable to allocate 49.1 MiB for an array with shape (3219026,) and data type complex128",
- "output_type": "error",
- "traceback": [
- "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
- "\u001b[1;31mMemoryError\u001b[0m Traceback (most recent call last)",
- "Cell \u001b[1;32mIn[5], line 3\u001b[0m\n\u001b[0;32m 1\u001b[0m df_raw \u001b[38;5;241m=\u001b[39m \u001b[43mYahooDownloader\u001b[49m\u001b[43m(\u001b[49m\u001b[43mstart_date\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43m \u001b[49m\u001b[43mTRAIN_START_DATE\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 2\u001b[0m \u001b[43m \u001b[49m\u001b[43mend_date\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43m \u001b[49m\u001b[43mTRADE_END_DATE\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m----> 3\u001b[0m \u001b[43m \u001b[49m\u001b[43mticker_list\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43m \u001b[49m\u001b[43mconfig_tickers\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mDOW_30_TICKER\u001b[49m\u001b[38;5;241;43m+\u001b[39;49m\u001b[43mconfig_tickers\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mNAS_100_TICKER\u001b[49m\u001b[38;5;241;43m+\u001b[39;49m\u001b[43mconfig_tickers\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mSP_500_TICKER\u001b[49m\u001b[43m)\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mfetch_data\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n",
- "File \u001b[1;32mD:\\workstation\\quant\\FinRL\\finrl\\meta\\preprocessor\\yahoodownloader.py:85\u001b[0m, in \u001b[0;36mYahooDownloader.fetch_data\u001b[1;34m(self, proxy)\u001b[0m\n\u001b[0;32m 83\u001b[0m data_df[\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mday\u001b[39m\u001b[38;5;124m\"\u001b[39m] \u001b[38;5;241m=\u001b[39m data_df[\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mdate\u001b[39m\u001b[38;5;124m\"\u001b[39m]\u001b[38;5;241m.\u001b[39mdt\u001b[38;5;241m.\u001b[39mdayofweek\n\u001b[0;32m 84\u001b[0m \u001b[38;5;66;03m# convert date to standard string format, easy to filter\u001b[39;00m\n\u001b[1;32m---> 85\u001b[0m data_df[\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mdate\u001b[39m\u001b[38;5;124m\"\u001b[39m] \u001b[38;5;241m=\u001b[39m \u001b[43mdata_df\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mdate\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mapply\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;28;43;01mlambda\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[43mx\u001b[49m\u001b[43m:\u001b[49m\u001b[43m \u001b[49m\u001b[43mx\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mstrftime\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43m%\u001b[39;49m\u001b[38;5;124;43mY-\u001b[39;49m\u001b[38;5;124;43m%\u001b[39;49m\u001b[38;5;124;43mm-\u001b[39;49m\u001b[38;5;132;43;01m%d\u001b[39;49;00m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m)\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m 86\u001b[0m \u001b[38;5;66;03m# drop missing data\u001b[39;00m\n\u001b[0;32m 87\u001b[0m data_df \u001b[38;5;241m=\u001b[39m data_df\u001b[38;5;241m.\u001b[39mdropna()\n",
- "File \u001b[1;32md:\\Users\\Steven Chen\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\pandas\\core\\series.py:4924\u001b[0m, in \u001b[0;36mSeries.apply\u001b[1;34m(self, func, convert_dtype, args, by_row, **kwargs)\u001b[0m\n\u001b[0;32m 4789\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mapply\u001b[39m(\n\u001b[0;32m 4790\u001b[0m \u001b[38;5;28mself\u001b[39m,\n\u001b[0;32m 4791\u001b[0m func: AggFuncType,\n\u001b[1;32m (...)\u001b[0m\n\u001b[0;32m 4796\u001b[0m \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs,\n\u001b[0;32m 4797\u001b[0m ) \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m>\u001b[39m DataFrame \u001b[38;5;241m|\u001b[39m Series:\n\u001b[0;32m 4798\u001b[0m \u001b[38;5;250m \u001b[39m\u001b[38;5;124;03m\"\"\"\u001b[39;00m\n\u001b[0;32m 4799\u001b[0m \u001b[38;5;124;03m Invoke function on values of Series.\u001b[39;00m\n\u001b[0;32m 4800\u001b[0m \n\u001b[1;32m (...)\u001b[0m\n\u001b[0;32m 4915\u001b[0m \u001b[38;5;124;03m dtype: float64\u001b[39;00m\n\u001b[0;32m 4916\u001b[0m \u001b[38;5;124;03m \"\"\"\u001b[39;00m\n\u001b[0;32m 4917\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43mSeriesApply\u001b[49m\u001b[43m(\u001b[49m\n\u001b[0;32m 4918\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[43m,\u001b[49m\n\u001b[0;32m 4919\u001b[0m \u001b[43m \u001b[49m\u001b[43mfunc\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 4920\u001b[0m \u001b[43m \u001b[49m\u001b[43mconvert_dtype\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mconvert_dtype\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 4921\u001b[0m \u001b[43m \u001b[49m\u001b[43mby_row\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mby_row\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 4922\u001b[0m \u001b[43m \u001b[49m\u001b[43margs\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43margs\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 4923\u001b[0m \u001b[43m \u001b[49m\u001b[43mkwargs\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m-> 4924\u001b[0m \u001b[43m \u001b[49m\u001b[43m)\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mapply\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n",
- "File \u001b[1;32md:\\Users\\Steven Chen\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\pandas\\core\\apply.py:1427\u001b[0m, in \u001b[0;36mSeriesApply.apply\u001b[1;34m(self)\u001b[0m\n\u001b[0;32m 1424\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mapply_compat()\n\u001b[0;32m 1426\u001b[0m \u001b[38;5;66;03m# self.func is Callable\u001b[39;00m\n\u001b[1;32m-> 1427\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mapply_standard\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n",
- "File \u001b[1;32md:\\Users\\Steven Chen\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\pandas\\core\\apply.py:1507\u001b[0m, in \u001b[0;36mSeriesApply.apply_standard\u001b[1;34m(self)\u001b[0m\n\u001b[0;32m 1501\u001b[0m \u001b[38;5;66;03m# row-wise access\u001b[39;00m\n\u001b[0;32m 1502\u001b[0m \u001b[38;5;66;03m# apply doesn't have a `na_action` keyword and for backward compat reasons\u001b[39;00m\n\u001b[0;32m 1503\u001b[0m \u001b[38;5;66;03m# we need to give `na_action=\"ignore\"` for categorical data.\u001b[39;00m\n\u001b[0;32m 1504\u001b[0m \u001b[38;5;66;03m# TODO: remove the `na_action=\"ignore\"` when that default has been changed in\u001b[39;00m\n\u001b[0;32m 1505\u001b[0m \u001b[38;5;66;03m# Categorical (GH51645).\u001b[39;00m\n\u001b[0;32m 1506\u001b[0m action \u001b[38;5;241m=\u001b[39m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mignore\u001b[39m\u001b[38;5;124m\"\u001b[39m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28misinstance\u001b[39m(obj\u001b[38;5;241m.\u001b[39mdtype, CategoricalDtype) \u001b[38;5;28;01melse\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m\n\u001b[1;32m-> 1507\u001b[0m mapped \u001b[38;5;241m=\u001b[39m \u001b[43mobj\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_map_values\u001b[49m\u001b[43m(\u001b[49m\n\u001b[0;32m 1508\u001b[0m \u001b[43m \u001b[49m\u001b[43mmapper\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mcurried\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mna_action\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43maction\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mconvert\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mconvert_dtype\u001b[49m\n\u001b[0;32m 1509\u001b[0m \u001b[43m\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m 1511\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mlen\u001b[39m(mapped) \u001b[38;5;129;01mand\u001b[39;00m \u001b[38;5;28misinstance\u001b[39m(mapped[\u001b[38;5;241m0\u001b[39m], ABCSeries):\n\u001b[0;32m 1512\u001b[0m \u001b[38;5;66;03m# GH#43986 Need to do list(mapped) in order to get treated as nested\u001b[39;00m\n\u001b[0;32m 1513\u001b[0m \u001b[38;5;66;03m# See also GH#25959 regarding EA support\u001b[39;00m\n\u001b[0;32m 1514\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m obj\u001b[38;5;241m.\u001b[39m_constructor_expanddim(\u001b[38;5;28mlist\u001b[39m(mapped), index\u001b[38;5;241m=\u001b[39mobj\u001b[38;5;241m.\u001b[39mindex)\n",
- "File \u001b[1;32md:\\Users\\Steven Chen\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\pandas\\core\\base.py:919\u001b[0m, in \u001b[0;36mIndexOpsMixin._map_values\u001b[1;34m(self, mapper, na_action, convert)\u001b[0m\n\u001b[0;32m 916\u001b[0m arr \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_values\n\u001b[0;32m 918\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28misinstance\u001b[39m(arr, ExtensionArray):\n\u001b[1;32m--> 919\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43marr\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mmap\u001b[49m\u001b[43m(\u001b[49m\u001b[43mmapper\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mna_action\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mna_action\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m 921\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m algorithms\u001b[38;5;241m.\u001b[39mmap_array(arr, mapper, na_action\u001b[38;5;241m=\u001b[39mna_action, convert\u001b[38;5;241m=\u001b[39mconvert)\n",
- "File \u001b[1;32md:\\Users\\Steven Chen\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\pandas\\core\\arrays\\_mixins.py:81\u001b[0m, in \u001b[0;36mravel_compat..method\u001b[1;34m(self, *args, **kwargs)\u001b[0m\n\u001b[0;32m 78\u001b[0m \u001b[38;5;129m@wraps\u001b[39m(meth)\n\u001b[0;32m 79\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mmethod\u001b[39m(\u001b[38;5;28mself\u001b[39m, \u001b[38;5;241m*\u001b[39margs, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs):\n\u001b[0;32m 80\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mndim \u001b[38;5;241m==\u001b[39m \u001b[38;5;241m1\u001b[39m:\n\u001b[1;32m---> 81\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m meth(\u001b[38;5;28mself\u001b[39m, \u001b[38;5;241m*\u001b[39margs, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs)\n\u001b[0;32m 83\u001b[0m flags \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_ndarray\u001b[38;5;241m.\u001b[39mflags\n\u001b[0;32m 84\u001b[0m flat \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mravel(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mK\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n",
- "File \u001b[1;32md:\\Users\\Steven Chen\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\pandas\\core\\arrays\\datetimelike.py:740\u001b[0m, in \u001b[0;36mDatetimeLikeArrayMixin.map\u001b[1;34m(self, mapper, na_action)\u001b[0m\n\u001b[0;32m 736\u001b[0m \u001b[38;5;129m@ravel_compat\u001b[39m\n\u001b[0;32m 737\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mmap\u001b[39m(\u001b[38;5;28mself\u001b[39m, mapper, na_action\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mNone\u001b[39;00m):\n\u001b[0;32m 738\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mpandas\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m Index\n\u001b[1;32m--> 740\u001b[0m result \u001b[38;5;241m=\u001b[39m \u001b[43mmap_array\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mmapper\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mna_action\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mna_action\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m 741\u001b[0m result \u001b[38;5;241m=\u001b[39m Index(result)\n\u001b[0;32m 743\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28misinstance\u001b[39m(result, ABCMultiIndex):\n",
- "File \u001b[1;32md:\\Users\\Steven Chen\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\pandas\\core\\algorithms.py:1743\u001b[0m, in \u001b[0;36mmap_array\u001b[1;34m(arr, mapper, na_action, convert)\u001b[0m\n\u001b[0;32m 1741\u001b[0m values \u001b[38;5;241m=\u001b[39m arr\u001b[38;5;241m.\u001b[39mastype(\u001b[38;5;28mobject\u001b[39m, copy\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mFalse\u001b[39;00m)\n\u001b[0;32m 1742\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m na_action \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m:\n\u001b[1;32m-> 1743\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43mlib\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mmap_infer\u001b[49m\u001b[43m(\u001b[49m\u001b[43mvalues\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mmapper\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mconvert\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mconvert\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m 1744\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[0;32m 1745\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m lib\u001b[38;5;241m.\u001b[39mmap_infer_mask(\n\u001b[0;32m 1746\u001b[0m values, mapper, mask\u001b[38;5;241m=\u001b[39misna(values)\u001b[38;5;241m.\u001b[39mview(np\u001b[38;5;241m.\u001b[39muint8), convert\u001b[38;5;241m=\u001b[39mconvert\n\u001b[0;32m 1747\u001b[0m )\n",
- "File \u001b[1;32mlib.pyx:2981\u001b[0m, in \u001b[0;36mpandas._libs.lib.map_infer\u001b[1;34m()\u001b[0m\n",
- "File \u001b[1;32mlib.pyx:2539\u001b[0m, in \u001b[0;36mpandas._libs.lib.maybe_convert_objects\u001b[1;34m()\u001b[0m\n",
- "\u001b[1;31mMemoryError\u001b[0m: Unable to allocate 49.1 MiB for an array with shape (3219026,) and data type complex128"
+ "Shape of DataFrame: (94301, 8)\n"
]
}
],
"source": [
"df_raw = YahooDownloader(start_date = TRAIN_START_DATE,\n",
" end_date = TRADE_END_DATE,\n",
- " ticker_list = config_tickers.DOW_30_TICKER+config_tickers.NAS_100_TICKER+config_tickers.SP_500_TICKER).fetch_data()"
+ " ticker_list = config_tickers.DOW_30_TICKER).fetch_data()"
]
},
{
@@ -2143,16 +1356,7 @@
"name": "python3"
},
"language_info": {
- "codemirror_mode": {
- "name": "ipython",
- "version": 3
- },
- "file_extension": ".py",
- "mimetype": "text/x-python",
- "name": "python",
- "nbconvert_exporter": "python",
- "pygments_lexer": "ipython3",
- "version": "3.10.8"
+ "name": "python"
}
},
"nbformat": 4,
diff --git a/examples/Stock_NeurIPS2018_1_Data.py b/examples/Stock_NeurIPS2018_1_Data.py
deleted file mode 100644
index a87b26da6..000000000
--- a/examples/Stock_NeurIPS2018_1_Data.py
+++ /dev/null
@@ -1,69 +0,0 @@
-from __future__ import annotations
-
-import datetime
-import itertools
-
-import numpy as np
-import pandas as pd
-import yfinance as yf
-
-from finrl import config_tickers
-from finrl.config import INDICATORS
-from finrl.meta.preprocessor.preprocessors import data_split
-from finrl.meta.preprocessor.preprocessors import FeatureEngineer
-from finrl.meta.preprocessor.yahoodownloader import YahooDownloader
-
-
-TRAIN_START_DATE = "2000-01-01"
-TRAIN_END_DATE = "2024-01-01"
-TRADE_START_DATE = "2023-01-01"
-TRADE_END_DATE = "2024-01-01"
-
-
-df_raw = YahooDownloader(
- start_date=TRAIN_START_DATE,
- end_date=TRADE_END_DATE,
- ticker_list=config_tickers.DOW_30_TICKER
- + config_tickers.NAS_100_TICKER
- + config_tickers.SP_500_TICKER,
-).fetch_data()
-
-
-df_raw.head()
-
-
-fe = FeatureEngineer(
- use_technical_indicator=True,
- tech_indicator_list=INDICATORS,
- use_vix=True,
- use_turbulence=True,
- user_defined_feature=False,
-)
-
-processed = fe.preprocess_data(df_raw)
-
-
-list_ticker = processed["tic"].unique().tolist()
-list_date = list(
- pd.date_range(processed["date"].min(), processed["date"].max()).astype(str)
-)
-combination = list(itertools.product(list_date, list_ticker))
-
-processed_full = pd.DataFrame(combination, columns=["date", "tic"]).merge(
- processed, on=["date", "tic"], how="left"
-)
-processed_full = processed_full[processed_full["date"].isin(processed["date"])]
-processed_full = processed_full.sort_values(["date", "tic"])
-
-processed_full = processed_full.fillna(0)
-
-
-processed_full.head()
-
-train = data_split(processed_full, TRAIN_START_DATE, TRAIN_END_DATE)
-trade = data_split(processed_full, TRADE_START_DATE, TRADE_END_DATE)
-print(len(train))
-print(len(trade))
-
-train.to_csv("train_data.csv")
-trade.to_csv("trade_data.csv")
diff --git a/examples/ensemble_stock_trading_metrics_analysis.py.ipynb b/examples/ensemble_stock_trading_metrics_analysis.py.ipynb
deleted file mode 100644
index 545f5719e..000000000
--- a/examples/ensemble_stock_trading_metrics_analysis.py.ipynb
+++ /dev/null
@@ -1,956 +0,0 @@
-{
- "cells": [
- {
- "cell_type": "code",
- "execution_count": 1,
- "metadata": {},
- "outputs": [],
- "source": [
- "import matplotlib.pyplot as plt\n",
- "import numpy as np\n",
- "import pandas as pd\n",
- "from tqdm import tqdm\n",
- "from stable_baselines3 import A2C, DDPG, PPO, SAC, TD3\n",
- "\n",
- "from finrl.agents.stablebaselines3.models import DRLAgent\n",
- "from finrl.config import INDICATORS, TRAINED_MODEL_DIR\n",
- "from finrl.meta.env_stock_trading.env_stocktrading import StockTradingEnv\n",
- "from finrl.meta.preprocessor.yahoodownloader import YahooDownloader\n",
- "from finrl.meta.preprocessor.preprocessors import FeatureEngineer, data_split\n",
- "\n",
- "%matplotlib inline"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 2,
- "metadata": {},
- "outputs": [],
- "source": [
- "trade = pd.read_csv('trade_data.csv')\n",
- "trade = trade.set_index(trade.columns[0])\n",
- "trade.index.names = ['']"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 3,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/html": [
- "\n",
- "\n",
- "
\n",
- " \n",
- " \n",
- " | \n",
- " date | \n",
- " tic | \n",
- " open | \n",
- " high | \n",
- " low | \n",
- " close | \n",
- " volume | \n",
- " day | \n",
- " macd | \n",
- " boll_ub | \n",
- " boll_lb | \n",
- " rsi_30 | \n",
- " cci_30 | \n",
- " dx_30 | \n",
- " close_30_sma | \n",
- " close_60_sma | \n",
- " vix | \n",
- " turbulence | \n",
- "
\n",
- " \n",
- " \n",
- " \n",
- " 0 | \n",
- " 2023-01-03 | \n",
- " AAPL | \n",
- " 130.279999 | \n",
- " 130.899994 | \n",
- " 124.169998 | \n",
- " 123.904625 | \n",
- " 112117500.0 | \n",
- " 1.0 | \n",
- " -4.664941 | \n",
- " 148.380015 | \n",
- " 121.517494 | \n",
- " 39.011489 | \n",
- " -130.926001 | \n",
- " 35.987249 | \n",
- " 138.780054 | \n",
- " 141.061399 | \n",
- " 22.9 | \n",
- " 58.114417 | \n",
- "
\n",
- " \n",
- " 0 | \n",
- " 2023-01-03 | \n",
- " ADBE | \n",
- " 340.160004 | \n",
- " 345.820007 | \n",
- " 331.920013 | \n",
- " 336.920013 | \n",
- " 2229100.0 | \n",
- " 1.0 | \n",
- " 2.018147 | \n",
- " 344.361914 | \n",
- " 325.710086 | \n",
- " 51.312759 | \n",
- " 55.832999 | \n",
- " 17.420819 | \n",
- " 334.678332 | \n",
- " 321.834165 | \n",
- " 22.9 | \n",
- " 58.114417 | \n",
- "
\n",
- " \n",
- " 0 | \n",
- " 2023-01-03 | \n",
- " ADI | \n",
- " 165.570007 | \n",
- " 166.199997 | \n",
- " 161.440002 | \n",
- " 157.418777 | \n",
- " 4475700.0 | \n",
- " 1.0 | \n",
- " 0.279274 | \n",
- " 168.515870 | \n",
- " 154.019671 | \n",
- " 51.525939 | \n",
- " -68.722035 | \n",
- " 8.072027 | \n",
- " 161.102222 | \n",
- " 151.353293 | \n",
- " 22.9 | \n",
- " 58.114417 | \n",
- "
\n",
- " \n",
- " 0 | \n",
- " 2023-01-03 | \n",
- " ADP | \n",
- " 240.789993 | \n",
- " 241.509995 | \n",
- " 235.270004 | \n",
- " 228.564453 | \n",
- " 1749800.0 | \n",
- " 1.0 | \n",
- " -3.817562 | \n",
- " 258.519213 | \n",
- " 221.412165 | \n",
- " 45.483461 | \n",
- " -115.839651 | \n",
- " 14.036269 | \n",
- " 243.547140 | \n",
- " 235.814659 | \n",
- " 22.9 | \n",
- " 58.114417 | \n",
- "
\n",
- " \n",
- " 0 | \n",
- " 2023-01-03 | \n",
- " ADSK | \n",
- " 190.619995 | \n",
- " 192.960007 | \n",
- " 183.000000 | \n",
- " 185.149994 | \n",
- " 1181600.0 | \n",
- " 1.0 | \n",
- " -4.526453 | \n",
- " 203.341768 | \n",
- " 180.661229 | \n",
- " 44.659114 | \n",
- " -94.290116 | \n",
- " 3.860456 | \n",
- " 195.468332 | \n",
- " 200.417166 | \n",
- " 22.9 | \n",
- " 58.114417 | \n",
- "
\n",
- " \n",
- "
\n",
- "
"
- ],
- "text/plain": [
- " date tic open high low close \\\n",
- "0 2023-01-03 AAPL 130.279999 130.899994 124.169998 123.904625 \n",
- "0 2023-01-03 ADBE 340.160004 345.820007 331.920013 336.920013 \n",
- "0 2023-01-03 ADI 165.570007 166.199997 161.440002 157.418777 \n",
- "0 2023-01-03 ADP 240.789993 241.509995 235.270004 228.564453 \n",
- "0 2023-01-03 ADSK 190.619995 192.960007 183.000000 185.149994 \n",
- "\n",
- " volume day macd boll_ub boll_lb rsi_30 cci_30 \\\n",
- "0 112117500.0 1.0 -4.664941 148.380015 121.517494 39.011489 -130.926001 \n",
- "0 2229100.0 1.0 2.018147 344.361914 325.710086 51.312759 55.832999 \n",
- "0 4475700.0 1.0 0.279274 168.515870 154.019671 51.525939 -68.722035 \n",
- "0 1749800.0 1.0 -3.817562 258.519213 221.412165 45.483461 -115.839651 \n",
- "0 1181600.0 1.0 -4.526453 203.341768 180.661229 44.659114 -94.290116 \n",
- "\n",
- " dx_30 close_30_sma close_60_sma vix turbulence \n",
- "0 35.987249 138.780054 141.061399 22.9 58.114417 \n",
- "0 17.420819 334.678332 321.834165 22.9 58.114417 \n",
- "0 8.072027 161.102222 151.353293 22.9 58.114417 \n",
- "0 14.036269 243.547140 235.814659 22.9 58.114417 \n",
- "0 3.860456 195.468332 200.417166 22.9 58.114417 "
- ]
- },
- "execution_count": 3,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "trade=data_split(trade, '2023-01-01', '2024-01-01')\n",
- "trade.head()"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 4,
- "metadata": {},
- "outputs": [
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "Stock Dimension: 68, State Space: 681\n"
- ]
- }
- ],
- "source": [
- "stock_dimension = len(trade.tic.unique())\n",
- "state_space = 1 + 2 * stock_dimension + len(INDICATORS) * stock_dimension\n",
- "print(f\"Stock Dimension: {stock_dimension}, State Space: {state_space}\")\n",
- "\n",
- "buy_cost_list = sell_cost_list = [0.001] * stock_dimension\n",
- "num_stock_shares = [0] * stock_dimension\n",
- "\n",
- "env_kwargs = {\n",
- " \"hmax\": 100,\n",
- " \"initial_amount\": 1000000,\n",
- " \"num_stock_shares\": num_stock_shares,\n",
- " \"buy_cost_pct\": buy_cost_list,\n",
- " \"sell_cost_pct\": sell_cost_list,\n",
- " \"state_space\": state_space,\n",
- " \"stock_dim\": stock_dimension,\n",
- " \"tech_indicator_list\": INDICATORS,\n",
- " \"action_space\": stock_dimension,\n",
- " \"reward_scaling\": 1e-4\n",
- "}\n",
- "\n",
- "e_trade_gym = StockTradingEnv(df = trade, turbulence_threshold = 70,risk_indicator_col='vix', **env_kwargs)\n",
- "# env_trade, obs_trade = e_trade_gym.get_sb_env()"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 5,
- "metadata": {},
- "outputs": [],
- "source": [
- "trained_a2c = A2C.load(TRAINED_MODEL_DIR + \"/agent_a2c\")\n",
- "trained_ddpg = DDPG.load(TRAINED_MODEL_DIR + \"/agent_ddpg\")\n",
- "trained_ppo = PPO.load(TRAINED_MODEL_DIR + \"/agent_ppo\")\n",
- "trained_td3 = TD3.load(TRAINED_MODEL_DIR + \"/agent_td3\")\n",
- "trained_sac = SAC.load(TRAINED_MODEL_DIR + \"/agent_sac\")"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 6,
- "metadata": {},
- "outputs": [],
- "source": [
- "def DRL_ensemble_prediction(environment, a2c_model=None, ddpg_model=None, ppo_model=None, td3_model=None, sac_model=None, weights=[1,1,1,1,1], deterministic=True):\n",
- " test_env, test_obs = environment.get_sb_env()\n",
- " account_memory = None\n",
- " actions_memory = None\n",
- "\n",
- "\n",
- " test_env.reset()\n",
- " max_steps = len(environment.df.index.unique()) - 1\n",
- "\n",
- " print(max_steps)\n",
- "\n",
- " _weights = []\n",
- " if a2c_model is not None:\n",
- " _weights.append(weights[0])\n",
- " if ddpg_model is not None:\n",
- " _weights.append(weights[1])\n",
- " if ppo_model is not None:\n",
- " _weights.append(weights[2])\n",
- " if td3_model is not None:\n",
- " _weights.append(weights[3])\n",
- " if sac_model is not None:\n",
- " _weights.append(weights[4])\n",
- " \n",
- " weights = np.array(_weights)\n",
- " \n",
- "\n",
- " for i in tqdm(range(len(environment.df.index.unique()))):\n",
- " if a2c_model is not None:\n",
- " a2c_action, _states = a2c_model.predict(test_obs, deterministic=deterministic)\n",
- " if ddpg_model is not None:\n",
- " ddpg_action, _states = ddpg_model.predict(test_obs, deterministic=deterministic)\n",
- " if ppo_model is not None:\n",
- " ppo_action, _states = ppo_model.predict(test_obs, deterministic=deterministic)\n",
- " if td3_model is not None:\n",
- " td3_action, _states = td3_model.predict(test_obs, deterministic=deterministic)\n",
- " if sac_model is not None:\n",
- " sac_action, _states = sac_model.predict(test_obs, deterministic=deterministic)\n",
- " \n",
- "\n",
- " actions = []\n",
- " action_length = 0\n",
- "\n",
- " if a2c_model is not None and len(a2c_action) > 0:\n",
- " action_length = len(a2c_action[0])\n",
- " elif ddpg_model is not None and len(ddpg_action) > 0:\n",
- " action_length = len(ddpg_action[0])\n",
- " elif ppo_model is not None and len(ppo_action) > 0:\n",
- " action_length = len(ppo_action[0])\n",
- " elif td3_model is not None and len(td3_action) > 0:\n",
- " action_length = len(td3_action[0])\n",
- " elif sac_model is not None and len(sac_action) > 0:\n",
- " action_length = len(sac_action[0])\n",
- "\n",
- " for j in range(action_length):\n",
- " _actions = []\n",
- " if a2c_model is not None:\n",
- " # print(a2c_action)\n",
- " _actions.append(a2c_action[0][j])\n",
- " if ddpg_model is not None:\n",
- " _actions.append(ddpg_action[0][j])\n",
- " if ppo_model is not None:\n",
- " _actions.append(ppo_action[0][j])\n",
- " if td3_model is not None:\n",
- " _actions.append(td3_action[0][j])\n",
- " if sac_model is not None:\n",
- " _actions.append(sac_action[0][j])\n",
- " _action = np.sum(_actions * weights) / np.sum(weights)\n",
- " actions.append(_action)\n",
- " actions[0] = np.array(actions)\n",
- "\n",
- " test_obs, rewards, dones, info = test_env.step(actions) \n",
- "\n",
- " if (i == max_steps - 1): \n",
- " account_memory = test_env.env_method(method_name=\"save_asset_memory\")\n",
- " actions_memory = test_env.env_method(method_name=\"save_action_memory\")\n",
- "\n",
- "\n",
- "\n",
- " if dones[0]: \n",
- " print(\"hit end!\")\n",
- " break\n",
- "\n",
- " return account_memory[0], actions_memory[0] "
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 7,
- "metadata": {},
- "outputs": [
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "248\n"
- ]
- },
- {
- "name": "stderr",
- "output_type": "stream",
- "text": [
- "100%|█████████▉| 248/249 [00:01<00:00, 172.23it/s]"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "hit end!\n"
- ]
- },
- {
- "name": "stderr",
- "output_type": "stream",
- "text": [
- "\n"
- ]
- }
- ],
- "source": [
- "df_account_value_merge, df_actions_merge = DRL_ensemble_prediction(\n",
- " a2c_model=trained_a2c, \n",
- " ddpg_model=trained_ddpg,\n",
- " ppo_model=trained_ppo,\n",
- " td3_model=trained_td3,\n",
- " sac_model=trained_sac,\n",
- " weights=[1, 2, 3, 4, 5],\n",
- " environment = e_trade_gym)"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 8,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/html": [
- "\n",
- "\n",
- "
\n",
- " \n",
- " \n",
- " | \n",
- " date | \n",
- " account_value | \n",
- "
\n",
- " \n",
- " \n",
- " \n",
- " 239 | \n",
- " 2023-12-14 | \n",
- " 1.336939e+06 | \n",
- "
\n",
- " \n",
- " 240 | \n",
- " 2023-12-15 | \n",
- " 1.343660e+06 | \n",
- "
\n",
- " \n",
- " 241 | \n",
- " 2023-12-18 | \n",
- " 1.344525e+06 | \n",
- "
\n",
- " \n",
- " 242 | \n",
- " 2023-12-19 | \n",
- " 1.355349e+06 | \n",
- "
\n",
- " \n",
- " 243 | \n",
- " 2023-12-20 | \n",
- " 1.334816e+06 | \n",
- "
\n",
- " \n",
- " 244 | \n",
- " 2023-12-21 | \n",
- " 1.349302e+06 | \n",
- "
\n",
- " \n",
- " 245 | \n",
- " 2023-12-22 | \n",
- " 1.354918e+06 | \n",
- "
\n",
- " \n",
- " 246 | \n",
- " 2023-12-26 | \n",
- " 1.363353e+06 | \n",
- "
\n",
- " \n",
- " 247 | \n",
- " 2023-12-27 | \n",
- " 1.363219e+06 | \n",
- "
\n",
- " \n",
- " 248 | \n",
- " 2023-12-28 | \n",
- " 1.367380e+06 | \n",
- "
\n",
- " \n",
- "
\n",
- "
"
- ],
- "text/plain": [
- " date account_value\n",
- "239 2023-12-14 1.336939e+06\n",
- "240 2023-12-15 1.343660e+06\n",
- "241 2023-12-18 1.344525e+06\n",
- "242 2023-12-19 1.355349e+06\n",
- "243 2023-12-20 1.334816e+06\n",
- "244 2023-12-21 1.349302e+06\n",
- "245 2023-12-22 1.354918e+06\n",
- "246 2023-12-26 1.363353e+06\n",
- "247 2023-12-27 1.363219e+06\n",
- "248 2023-12-28 1.367380e+06"
- ]
- },
- "execution_count": 8,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "df_account_value_merge.tail(10)"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 9,
- "metadata": {},
- "outputs": [],
- "source": [
- "test_env, test_obs = e_trade_gym.get_sb_env()\n",
- "a2c_action, _states = trained_a2c.predict(test_obs, deterministic=True)"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 10,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/plain": [
- "array([[ 1. , 1. , 1. , 1. , -1. ,\n",
- " -1. , 1. , -0.65387243, 1. , -1. ,\n",
- " 1. , 1. , -1. , -1. , -1. ,\n",
- " -1. , -1. , -1. , 1. , 0.569773 ,\n",
- " 0.45166317, 1. , -1. , -0.52100146, -1. ,\n",
- " 1. , -1. , -1. , 0.16547962, -1. ,\n",
- " -1. , 1. , -0.34704542, 0.02504051, -1. ,\n",
- " -0.3966578 , 1. , 0.14025176, 0.02251373, 1. ,\n",
- " 0.49129128, 0.20406397, -1. , -0.596449 , -1. ,\n",
- " 0.24977826, 0.83777153, 1. , -1. , -1. ,\n",
- " -1. , -1. , 1. , 1. , -1. ,\n",
- " -1. , 0.17500924, 1. , -0.01665697, 1. ,\n",
- " -1. , -1. , -0.36138016, 1. , -1. ,\n",
- " -1. , 1. , -1. ]], dtype=float32)"
- ]
- },
- "execution_count": 10,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "a2c_action"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 11,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/plain": [
- "array(['AAPL', 'ADBE', 'ADI', 'ADP', 'ADSK', 'ALGN', 'AMAT', 'AMD',\n",
- " 'AMGN', 'AMZN', 'ASML', 'BIIB', 'BKNG', 'BMRN', 'CDNS', 'CHKP',\n",
- " 'CMCSA', 'COST', 'CSCO', 'CSX', 'CTAS', 'CTSH', 'DLTR', 'EA',\n",
- " 'EBAY', 'FAST', 'GILD', 'HAS', 'HSIC', 'IDXX', 'ILMN', 'INCY',\n",
- " 'INTC', 'INTU', 'ISRG', 'JBHT', 'KLAC', 'LRCX', 'MAR', 'MCHP',\n",
- " 'MDLZ', 'MNST', 'MSFT', 'MU', 'NFLX', 'NTAP', 'NTES', 'NVDA',\n",
- " 'ORLY', 'PAYX', 'PCAR', 'PEP', 'QCOM', 'REGN', 'ROST', 'SBUX',\n",
- " 'SIRI', 'SNPS', 'SWKS', 'TCOM', 'TTWO', 'TXN', 'VRSN', 'VRTX',\n",
- " 'WBA', 'WDC', 'WYNN', 'XEL'], dtype=object)"
- ]
- },
- "execution_count": 11,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "trade['tic'].unique()"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "# DJI index"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 12,
- "metadata": {},
- "outputs": [],
- "source": [
- "TRADE_START_DATE = df_account_value_merge['date'].unique().tolist()[0]\n",
- "TRADE_END_DATE = df_account_value_merge['date'].unique().tolist()[-1]"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 13,
- "metadata": {},
- "outputs": [
- {
- "name": "stderr",
- "output_type": "stream",
- "text": [
- "100%|██████████| 1/1 [00:01<00:00, 1.79s/it]"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "Shape of DataFrame: (248, 8)\n"
- ]
- },
- {
- "name": "stderr",
- "output_type": "stream",
- "text": [
- "\n"
- ]
- }
- ],
- "source": [
- "df_dji = YahooDownloader(\n",
- " start_date=TRADE_START_DATE, end_date=TRADE_END_DATE, ticker_list=[\"^DJI\"]\n",
- ").fetch_data()"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 14,
- "metadata": {},
- "outputs": [],
- "source": [
- "df_dji = df_dji[[\"date\", \"close\"]]\n",
- "fst_day = df_dji[\"close\"][0]\n",
- "dji = pd.merge(\n",
- " df_dji[\"date\"],\n",
- " df_dji[\"close\"].div(fst_day).mul(1000000),\n",
- " how=\"outer\",\n",
- " left_index=True,\n",
- " right_index=True,\n",
- ").set_index(\"date\")"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 15,
- "metadata": {},
- "outputs": [],
- "source": [
- "df_result_merge = (df_account_value_merge.set_index(df_account_value_merge.columns[0]))\n",
- "\n",
- "result = pd.DataFrame(\n",
- " {\n",
- " \"merge strategy\": df_result_merge[\"account_value\"],\n",
- " # \"mvo\": MVO_result[\"Mean Var\"],\n",
- " \"dji\": dji[\"close\"],\n",
- " }\n",
- ")"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 16,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/plain": [
- "