From cda1f1e4b92b1b7bb44b91e1f4c2e75f19064e80 Mon Sep 17 00:00:00 2001 From: "ap550083@gmail.com" Date: Fri, 19 Jul 2024 18:37:07 +0530 Subject: [PATCH] Currency Arbitrage with Reinforcement Learning added --- ...r_currency_arbitrage_using_Rlearning.ipynb | 290 ++++++++++++++ .../currency_data.csv | 366 ++++++++++++++++++ .../readme.md | 30 ++ 3 files changed, 686 insertions(+) create mode 100644 Finacial Domain/Currency Arbitrage with Reinforcement Learning/agent_for_currency_arbitrage_using_Rlearning.ipynb create mode 100644 Finacial Domain/Currency Arbitrage with Reinforcement Learning/currency_data.csv create mode 100644 Finacial Domain/Currency Arbitrage with Reinforcement Learning/readme.md diff --git a/Finacial Domain/Currency Arbitrage with Reinforcement Learning/agent_for_currency_arbitrage_using_Rlearning.ipynb b/Finacial Domain/Currency Arbitrage with Reinforcement Learning/agent_for_currency_arbitrage_using_Rlearning.ipynb new file mode 100644 index 00000000..20d3bb91 --- /dev/null +++ b/Finacial Domain/Currency Arbitrage with Reinforcement Learning/agent_for_currency_arbitrage_using_Rlearning.ipynb @@ -0,0 +1,290 @@ +{ + "nbformat": 4, + "nbformat_minor": 0, + "metadata": { + "colab": { + "provenance": [] + }, + "kernelspec": { + "name": "python3", + "display_name": "Python 3" + }, + "language_info": { + "name": "python" + } + }, + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "id": "ARmpyIVdteu5" + }, + "outputs": [], + "source": [ + "import pandas as pd\n", + "import numpy as np\n", + "import random\n", + "from datetime import datetime, timedelta\n", + "\n", + "# Parameters\n", + "num_entries = 1000\n", + "currency_pairs = ['EUR/USD', 'USD/JPY', 'GBP/USD', 'USD/CHF', 'AUD/USD', 'USD/CAD']\n", + "\n", + "# Generate timestamps\n", + "start_time = datetime.now()\n", + "timestamps = [start_time - timedelta(minutes=5*i) for i in range(num_entries)]\n", + "\n", + "# Generate synthetic data\n", + "data = []\n", + "for i in range(num_entries):\n", + " timestamp = timestamps[i]\n", + " pair = random.choice(currency_pairs)\n", + " bid_price = round(random.uniform(1.0, 1.5), 4)\n", + " ask_price = round(bid_price + random.uniform(0.0001, 0.0005), 4)\n", + " data.append([timestamp, pair, bid_price, ask_price])\n", + "\n", + "# Create DataFrame\n", + "columns = ['Timestamp', 'Currency Pair', 'Bid Price', 'Ask Price']\n", + "df = pd.DataFrame(data, columns=columns)\n", + "\n", + "# Save to CSV\n", + "df.to_csv('currency_arbitrage_data.csv', index=False)\n" + ] + }, + { + "cell_type": "code", + "source": [ + "import pandas as pd\n", + "\n", + "# Load the dataset\n", + "df = pd.read_csv('currency_arbitrage_data.csv')\n", + "\n", + "# Convert the Timestamp column to datetime\n", + "df['Timestamp'] = pd.to_datetime(df['Timestamp'])\n", + "\n", + "# Display the first few rows of the dataset\n", + "print(df.head())\n" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "tUTB5cjltxSh", + "outputId": "fd4c12e8-afb0-423c-a5ad-634b96b2bdcf" + }, + "execution_count": 2, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + " Timestamp Currency Pair Bid Price Ask Price\n", + "0 2024-07-19 11:38:48.716950 USD/CHF 1.2220 1.2224\n", + "1 2024-07-19 11:33:48.716950 USD/JPY 1.4628 1.4631\n", + "2 2024-07-19 11:28:48.716950 USD/JPY 1.3268 1.3271\n", + "3 2024-07-19 11:23:48.716950 USD/CHF 1.1257 1.1262\n", + "4 2024-07-19 11:18:48.716950 USD/CAD 1.3318 1.3319\n" + ] + } + ] + }, + { + "cell_type": "code", + "source": [ + "from sklearn.preprocessing import StandardScaler, LabelEncoder\n", + "\n", + "# Encode the currency pairs\n", + "le = LabelEncoder()\n", + "df['Currency Pair'] = le.fit_transform(df['Currency Pair'])\n", + "\n", + "# Normalize the bid and ask prices\n", + "scaler = StandardScaler()\n", + "df[['Bid Price', 'Ask Price']] = scaler.fit_transform(df[['Bid Price', 'Ask Price']])\n", + "\n", + "print(df.head())\n" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "krofbKLUtxPK", + "outputId": "006a9e1e-d992-4c06-e43e-70763da549c6" + }, + "execution_count": 3, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + " Timestamp Currency Pair Bid Price Ask Price\n", + "0 2024-07-19 11:38:48.716950 4 -0.173319 -0.172652\n", + "1 2024-07-19 11:33:48.716950 5 1.508608 1.508600\n", + "2 2024-07-19 11:28:48.716950 5 0.558683 0.558661\n", + "3 2024-07-19 11:23:48.716950 4 -0.845950 -0.844594\n", + "4 2024-07-19 11:18:48.716950 3 0.593606 0.592188\n" + ] + } + ] + }, + { + "cell_type": "code", + "source": [ + "import numpy as np\n", + "import gym\n", + "from gym import spaces\n", + "\n", + "class CurrencyArbitrageEnv(gym.Env):\n", + " def __init__(self, df):\n", + " super(CurrencyArbitrageEnv, self).__init__()\n", + " self.df = df\n", + " self.current_step = 0\n", + "\n", + " # Actions: 0 = hold, 1 = buy, 2 = sell\n", + " self.action_space = spaces.Discrete(3)\n", + "\n", + " # Observation space: bid price, ask price, and currency pair\n", + " self.observation_space = spaces.Box(low=-np.inf, high=np.inf, shape=(3,), dtype=np.float32)\n", + "\n", + " # Initial account balance\n", + " self.balance = 10000\n", + "\n", + " def reset(self):\n", + " self.current_step = 0\n", + " self.balance = 10000\n", + " return self._next_observation()\n", + "\n", + " def _next_observation(self):\n", + " obs = self.df.iloc[self.current_step][['Bid Price', 'Ask Price', 'Currency Pair']].values\n", + " return obs\n", + "\n", + " def step(self, action):\n", + " obs = self._next_observation()\n", + " self.current_step += 1\n", + "\n", + " if action == 1: # Buy\n", + " self.balance -= obs[1] # Subtract ask price\n", + " elif action == 2: # Sell\n", + " self.balance += obs[0] # Add bid price\n", + "\n", + " reward = self.balance\n", + "\n", + " done = self.current_step >= len(self.df) - 1\n", + "\n", + " return obs, reward, done, {}\n", + "\n", + " def render(self, mode='human'):\n", + " print(f'Step: {self.current_step}, Balance: {self.balance}')\n", + "\n", + "# Create the environment\n", + "env = CurrencyArbitrageEnv(df)\n" + ], + "metadata": { + "id": "pzTAsCD3txKv" + }, + "execution_count": 4, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "import random\n", + "from collections import deque\n", + "\n", + "class QLearningAgent:\n", + " def __init__(self, state_size, action_size):\n", + " self.state_size = state_size\n", + " self.action_size = action_size\n", + " self.memory = deque(maxlen=2000)\n", + " self.gamma = 0.95 # discount rate\n", + " self.epsilon = 1.0 # exploration rate\n", + " self.epsilon_min = 0.01\n", + " self.epsilon_decay = 0.995\n", + " self.learning_rate = 0.001\n", + " self.q_table = {}\n", + "\n", + " def get_qs(self, state):\n", + " return self.q_table.get(tuple(state.flatten()), np.zeros(self.action_size))\n", + "\n", + " def remember(self, state, action, reward, next_state, done):\n", + " self.memory.append((state, action, reward, next_state, done))\n", + "\n", + " def act(self, state):\n", + " if np.random.rand() <= self.epsilon:\n", + " return random.randrange(self.action_size)\n", + " qs = self.get_qs(state)\n", + " return np.argmax(qs)\n", + "\n", + " def replay(self, batch_size):\n", + " minibatch = random.sample(self.memory, batch_size)\n", + " for state, action, reward, next_state, done in minibatch:\n", + " target = reward\n", + " if not done:\n", + " target = reward + self.gamma * np.amax(self.get_qs(next_state))\n", + " qs = self.get_qs(state)\n", + " qs[action] = target\n", + " self.q_table[tuple(state.flatten())] = qs\n", + " if self.epsilon > self.epsilon_min:\n", + " self.epsilon *= self.epsilon_decay\n", + "\n", + "# Initialize the agent\n", + "state_size = env.observation_space.shape[0]\n", + "action_size = env.action_space.n\n", + "agent = QLearningAgent(state_size, action_size)\n", + "\n", + "# Train the agent\n", + "episodes = 300\n", + "batch_size = 32\n", + "\n", + "for e in range(episodes):\n", + " state = env.reset()\n", + " state = np.reshape(state, [1, state_size])\n", + "\n", + " for time in range(50):\n", + " action = agent.act(state)\n", + " next_state, reward, done, _ = env.step(action)\n", + " next_state = np.reshape(next_state, [1, state_size])\n", + "\n", + " agent.remember(state, action, reward, next_state, done)\n", + " state = next_state\n", + "\n", + " if done:\n", + " print(f\"Episode: {e+1}/{episodes}, Score: {reward}, Epsilon: {agent.epsilon:.2}\")\n", + " break\n", + "\n", + " if len(agent.memory) > batch_size:\n", + " agent.replay(batch_size)\n" + ], + "metadata": { + "id": "l7MHaOXjtxGQ" + }, + "execution_count": 6, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "# Evaluate the agent\n", + "state = env.reset()\n", + "state = np.reshape(state, [1, state_size])\n", + "total_reward = 0\n", + "\n", + "for time in range(500):\n", + " action = agent.act(state)\n", + " next_state, reward, done, _ = env.step(action)\n", + " next_state = np.reshape(next_state, [1, state_size])\n", + " total_reward += reward\n", + " state = next_state\n", + "\n", + " if done:\n", + " print(f\"Final Balance: {total_reward}\")\n", + " break\n" + ], + "metadata": { + "id": "t_-a_DbRuDay" + }, + "execution_count": 7, + "outputs": [] + } + ] +} \ No newline at end of file diff --git a/Finacial Domain/Currency Arbitrage with Reinforcement Learning/currency_data.csv b/Finacial Domain/Currency Arbitrage with Reinforcement Learning/currency_data.csv new file mode 100644 index 00000000..42ca2211 --- /dev/null +++ b/Finacial Domain/Currency Arbitrage with Reinforcement Learning/currency_data.csv @@ -0,0 +1,366 @@ +Date,USD_EUR,USD_GBP,EUR_GBP +2022-01-01,0.6017123780011525,0.20018437580692697,0.42236794691170176 +2022-01-02,0.9595978571430184,0.2517745626934617,0.05572750367476557 +2022-01-03,0.00766319274477758,0.11586967559375393,0.8065257757726989 +2022-01-04,0.6376245398002052,0.34135332290713666,0.7156006121632796 +2022-01-05,0.9362294768129734,0.7247675198938326,0.21506917059823563 +2022-01-06,0.1421954217657975,0.7883045358944142,0.10761757662368848 +2022-01-07,0.8915255149162732,0.2510634184186417,0.2588813273322242 +2022-01-08,0.48879490172281836,0.1379684708984102,0.7571036891248911 +2022-01-09,0.5885389293874674,0.23629158190575839,0.30370949157851773 +2022-01-10,0.8131245105683149,0.03606004746469562,0.6815605182227692 +2022-01-11,0.6437711578298444,0.33990915943341576,0.3496600885162857 +2022-01-12,1.1412857329077584,0.3267359380295658,0.4384408545364722 +2022-01-13,0.08047157226435164,0.15428742883633184,0.7364431432054086 +2022-01-14,0.01215292265305643,0.5586618821947503,0.6096416242157008 +2022-01-15,0.222476827791128,0.03952928988624205,0.5436871239052085 +2022-01-16,0.4940219064929536,0.07933536054267076,0.7676651173645567 +2022-01-17,0.7522903660350435,0.45091929356953275,0.034121254856611626 +2022-01-18,0.2384415481316001,0.7743126737083572,0.6985482120106247 +2022-01-19,1.1206289655076018,0.14770968549921326,0.5421517361933803 +2022-01-20,0.18338301711447724,0.12780983385678174,0.008572614105904331 +2022-01-21,0.18985617269137797,0.6134690454273692,0.705886949458068 +2022-01-22,1.0748196772489047,0.5724084582206909,0.3455665260400289 +2022-01-23,0.07928286512965185,0.08684931138684969,0.17790290826281047 +2022-01-24,0.44554316959474477,0.5675227481130286,0.8926818754163788 +2022-01-25,0.7847839561857213,0.7989830431373025,0.1103581925285014 +2022-01-26,0.8203664445433568,0.6446398653424105,0.7939598682976965 +2022-01-27,0.5677697313102176,0.6044168968231466,0.07459127313655094 +2022-01-28,0.9813301729555923,0.243611003165978,0.35411700583796557 +2022-01-29,0.8913886242158686,0.11073435610495252,0.5002007933044545 +2022-01-30,0.2671729448940133,0.7088894009002114,0.04718640277442339 +2022-01-31,0.6295850448772765,0.16134462154928172,0.26256373841846214 +2022-02-01,1.010122471384412,0.5141341922451677,0.7969843287953697 +2022-02-02,0.08247060584889843,0.7104748704703029,0.8646224013837103 +2022-02-03,0.1300884830595859,0.329386683453252,0.44200006428843563 +2022-02-04,0.7594180457068473,0.03851070476046781,0.21964877843352457 +2022-02-05,0.551618916341521,0.7883556317724097,0.25428257168120566 +2022-02-06,1.0302989193226981,0.07152941758708097,0.8203771645426267 +2022-02-07,0.8114514024082377,0.04532692928050661,0.14779719248461257 +2022-02-08,0.16865172779814044,0.05239979787887457,0.3090000670543888 +2022-02-09,1.1198147395789746,0.45241797333226075,0.40944703124095055 +2022-02-10,0.04979185414575884,0.5405959445284065,0.7622792828591101 +2022-02-11,0.601285401277547,0.665005060870525,0.736827220054977 +2022-02-12,0.7933018197849103,0.15429920069442976,0.2190780176978188 +2022-02-13,1.0776317129434132,0.4431847151468061,0.5467456366380568 +2022-02-14,0.6329344642202314,0.45161426064067456,0.09657272675545579 +2022-02-15,0.7577263198297576,0.4626113249441617,0.7910924820787355 +2022-02-16,0.3194678642793533,0.3377624503545164,0.7013805883311245 +2022-02-17,0.2275129190937557,0.23032620631306377,0.6318753097628375 +2022-02-18,0.7085819319547073,0.45427721910085694,0.6818755225597374 +2022-02-19,0.43604865804166126,0.6172639818960785,0.017504532497889646 +2022-02-20,1.115248934264014,0.35389539391140706,0.5360700773092496 +2022-02-21,0.3035274271766247,0.30321755714364174,0.7747605357303863 +2022-02-22,0.45252586564222297,0.6214814115491443,0.7074609860792546 +2022-02-23,0.05252384913221664,0.10345567729042182,0.6782638861187995 +2022-02-24,0.7359906307342977,0.6407509496987063,0.6872163097270106 +2022-02-25,0.7411086379021282,0.3301712163351108,0.6585832328066764 +2022-02-26,0.9577971395565633,0.22655823601803107,0.17402270934358136 +2022-02-27,1.0251040850293325,0.21476481851826998,0.6865079447173749 +2022-02-28,0.1143386862100848,0.6568540450564393,0.5592285831201318 +2022-03-01,0.615495313489734,0.5415718692320912,0.3725819110049636 +2022-03-02,0.5372515850431473,0.22449287354436784,0.794931283283225 +2022-03-03,0.9424970899860636,0.7982670100494218,0.0011501539370525448 +2022-03-04,0.050500219647721376,0.5573790694160744,0.7899644271170522 +2022-03-05,1.1269727399780103,0.556022971754087,0.14054735334858767 +2022-03-06,0.9010100335605409,0.6388141084069202,0.7996262781134987 +2022-03-07,1.1174503682594141,0.49423984407479304,0.5534638282304877 +2022-03-08,0.09456743173615445,0.21731309445892422,0.02890115484227539 +2022-03-09,0.30069571001366213,0.6985309952893191,0.13090149206629287 +2022-03-10,0.370991366526147,0.5985784948232812,0.054081812328040615 +2022-03-11,0.954031984202289,0.2338565380034351,0.36174136919282573 +2022-03-12,0.6846553839467201,0.11072964717390912,0.7489341540008964 +2022-03-13,0.24735338391269152,0.1104832461358229,0.5889638142844734 +2022-03-14,0.2746442161200329,0.3398529137905075,0.3656396510327566 +2022-03-15,0.022864336722596912,0.10801192670688559,0.853089322200924 +2022-03-16,0.05473041104921963,0.4653719421909869,0.13818977894294238 +2022-03-17,0.47526838165895263,0.16068704824950064,0.2650844866091198 +2022-03-18,0.8152320904349668,0.5959624854316015,0.5150004146330812 +2022-03-19,0.5873604335827756,0.46485806132211416,0.8762651550472198 +2022-03-20,0.4480566154561895,0.522241428164008,0.29962892748702796 +2022-03-21,0.29633969988419656,0.3994127458135271,0.12547026849578935 +2022-03-22,0.469577364480549,0.017157757939992014,0.22629332811568012 +2022-03-23,0.40252377550004265,0.12326219573668702,0.21597960298282612 +2022-03-24,1.124865290922932,0.6469103718674227,0.8229810128326652 +2022-03-25,0.3302623055151453,0.09903281157394934,0.6652361287172432 +2022-03-26,0.005247461483266269,0.5776096513800123,0.27437696403188844 +2022-03-27,0.8586014624639873,0.16018557671069936,0.006087239474645923 +2022-03-28,0.5266629543540384,0.2664940157498533,0.44346664750108045 +2022-03-29,0.8428795363567614,0.20237236984170864,0.15065453029474077 +2022-03-30,0.9500771285277374,0.5214362408318866,0.21165083940468163 +2022-03-31,1.145863802730043,0.5882522251962884,0.550223105360222 +2022-04-01,0.7394249282844777,0.540282971594544,0.5829095753339112 +2022-04-02,1.1057086282860185,0.43658399702908146,0.36789908077004146 +2022-04-03,0.23376438802256447,0.7721614286248858,0.09870041215645618 +2022-04-04,1.1215063189201675,0.5879373788874313,0.028448301817804767 +2022-04-05,0.4030378210617119,0.5454952327629797,0.7929368353718744 +2022-04-06,1.0319830277200275,0.42018744846644546,0.4812543746214656 +2022-04-07,0.9823324635505869,0.3482512957725238,0.09459980925817062 +2022-04-08,0.3349521500670876,0.5582383737761379,0.6802634928484018 +2022-04-09,0.36519453963297105,0.07559930320318227,0.7505047586988636 +2022-04-10,1.1619788916370821,0.08871589715152908,0.19919895787415393 +2022-04-11,1.1922483417553567,0.6251765288042678,0.0006625574780162902 +2022-04-12,0.5468584223937001,0.6634908265381108,0.8231913337604135 +2022-04-13,1.0658041888683014,0.19653233279493343,0.714090390056182 +2022-04-14,1.183470412849599,0.614496019734126,0.3523935633408984 +2022-04-15,0.6424455335422142,0.4269219496301575,0.4352352484224542 +2022-04-16,0.3085912195961461,0.7440237507186208,0.6890149153528303 +2022-04-17,0.7954050162728951,0.4562954175960008,0.8869735713740908 +2022-04-18,0.13063606132281133,0.19325957858109427,0.6517485007657101 +2022-04-19,0.16851109392724867,0.4528715365006827,0.5516880642159603 +2022-04-20,0.7212688294885062,0.3102528199372633,0.4517939948281926 +2022-04-21,0.5334436933807096,0.42764460612696215,0.810202067797355 +2022-04-22,0.9012508374058641,0.3248619359644875,0.24826114784247977 +2022-04-23,0.8550536749312173,0.3227679363248074,0.1364764534606832 +2022-04-24,0.9916798131183441,0.2302590609440568,0.7676351213612285 +2022-04-25,0.33191080631880415,0.08030522127269216,0.4353626966213088 +2022-04-26,0.3858736349626556,0.09912086481845864,0.762305451527019 +2022-04-27,0.9859698557044377,0.37631095381870827,0.8812597676884347 +2022-04-28,1.073058475807227,0.2939411599731505,0.39349952215430956 +2022-04-29,0.7317244264850317,0.21965552283662879,0.28489434394455126 +2022-04-30,1.0726884452813756,0.6272912774919074,0.26797483758709467 +2022-05-01,0.5335704332231556,0.024482887625150076,0.5160329299827804 +2022-05-02,0.8895043541331734,0.44387185423682496,0.7070561016751855 +2022-05-03,0.0916026186033306,0.29911522924775336,0.792078657912979 +2022-05-04,0.6509652237218434,0.5684567747407661,0.21249740148325266 +2022-05-05,0.09979688455798223,0.49127320505659366,0.2975252393599026 +2022-05-06,0.4818581657993326,0.19662695345427128,0.10943711306259621 +2022-05-07,0.8239373490784115,0.7265422148442668,0.845854443487674 +2022-05-08,0.7845538499447792,0.3389320987697252,0.8360314702069909 +2022-05-09,0.9437996893767938,0.5614261507054848,0.31991291794334864 +2022-05-10,0.6175609707009245,0.6246515315573156,0.8228195035170055 +2022-05-11,0.8194967713851341,0.19258513733332094,0.3600996333982892 +2022-05-12,0.8467529304822591,0.01882752875314946,0.43905595502774675 +2022-05-13,0.21900842677657797,0.6070117833902423,0.32531398872581135 +2022-05-14,0.3955991070176979,0.41791074210929086,0.7662284719961949 +2022-05-15,1.1701335347525283,0.796687081968044,0.8881976949375961 +2022-05-16,1.1944551582454315,0.6935470617690238,0.08208250003753635 +2022-05-17,0.5560957972055366,0.4498601061223646,0.0466463447394709 +2022-05-18,0.37960726513028925,0.4772507282164127,0.7225411999823041 +2022-05-19,0.29553628013436045,0.6941726545545207,0.6550933915430991 +2022-05-20,0.11722540616320844,0.2907818587554713,0.35130636578483776 +2022-05-21,0.7432945640710303,0.40860660694037954,0.4304579708460665 +2022-05-22,0.8445870432273938,0.30235409105905514,0.40467464586686974 +2022-05-23,1.179407675828777,0.32415915033151443,0.8210403052736265 +2022-05-24,0.5595893023687813,0.5472817872782846,0.5025632512895782 +2022-05-25,0.9178237733388251,0.3202253728006989,0.2987138233933814 +2022-05-26,1.1639689524047572,0.3198560254989928,0.8760654416014559 +2022-05-27,0.4040070114352293,0.0669346956787555,0.5821611828771938 +2022-05-28,0.016413900238954858,0.4449460796825446,0.19407753567717767 +2022-05-29,0.9570454114357693,0.31374403660594696,0.26092031043834996 +2022-05-30,1.1541477264540456,0.25320023138859116,0.0562015194491155 +2022-05-31,0.20503872252848068,0.36139560009894,0.25734171265926203 +2022-06-01,1.1314739954382755,0.7874534508005924,0.3898034502606811 +2022-06-02,0.5503235429271153,0.3711255504641988,0.3872936159619827 +2022-06-03,0.661087455728225,0.4122593021762865,0.0138481708032967 +2022-06-04,0.6093722254343593,0.1252682130193099,0.11121051164312551 +2022-06-05,0.21048459568280123,0.22450627717601668,0.015518821081007128 +2022-06-06,0.6353768274308786,0.68845414452196,0.3607426892167969 +2022-06-07,0.45629974781368504,0.4695938850498871,0.41534732703068533 +2022-06-08,0.4907028050060091,0.5345742923387932,0.2313446262351986 +2022-06-09,1.0183130460992704,0.003695403152804566,0.7409202491803026 +2022-06-10,0.9602223281386386,0.029794281091191355,0.7856354477691037 +2022-06-11,0.5190065641758339,0.29793307608527647,0.10867784704975378 +2022-06-12,0.32483806053440767,0.7720292754190736,0.7485401203794008 +2022-06-13,0.15281029986642758,0.6606146555510707,0.3753066485477641 +2022-06-14,0.4417997415123661,0.5257968433450861,0.30237781564716154 +2022-06-15,0.18333460981457897,0.23080639006178139,0.1562202824126999 +2022-06-16,0.1769033538835266,0.5239390147970274,0.007452157643921176 +2022-06-17,1.1888217581854787,0.4483885448958037,0.834923198731446 +2022-06-18,0.39564072874309786,0.7561859425186638,0.11573791885380656 +2022-06-19,0.4116453328079957,0.3909795051978513,0.30142310889716284 +2022-06-20,0.4926611735267853,0.1471048231293227,0.5272237018882836 +2022-06-21,0.9323078733873568,0.5532030913245567,0.6443228638469995 +2022-06-22,0.9505641280183901,0.48249931729992374,0.41112573268366626 +2022-06-23,0.6667452607957425,0.42515166337118554,0.7832416461881582 +2022-06-24,0.8888927815852963,0.3561605366218845,0.06799030170673896 +2022-06-25,0.02569605205797507,0.7496124019226524,0.27941262331661637 +2022-06-26,0.7599377128252005,0.7422459423195442,0.3432113253087586 +2022-06-27,0.7874218180957919,0.2446913803843792,0.6117378976755786 +2022-06-28,0.4047569652113835,0.637725714243571,0.032491009370662974 +2022-06-29,1.14803524842526,0.7849257619759722,0.6809439721112297 +2022-06-30,0.5543092837153597,0.5006104819439231,0.1656001011791679 +2022-07-01,0.8699271497840937,0.7479460389379813,0.7216262648374482 +2022-07-02,0.09819634371975247,0.7646569215664876,0.22039088830296136 +2022-07-03,0.4674245108884631,0.028926467694707993,0.29156166040705706 +2022-07-04,0.6777837415895396,0.5106134120263103,0.5620847105047208 +2022-07-05,1.1852080633325641,0.7604031918150931,0.16011616623263225 +2022-07-06,0.9651142727736096,0.5185114072390025,0.33284103230961765 +2022-07-07,0.1881115034851665,0.4635502165406917,0.4556746660214664 +2022-07-08,0.6101444701178534,0.02132362575194584,0.45924426905582966 +2022-07-09,0.5131869155904552,0.7239104776955101,0.8245097148134656 +2022-07-10,0.5233858653467813,0.579219965519793,0.47303230284746933 +2022-07-11,0.43163864578073635,0.6897128724720862,0.6257502294809766 +2022-07-12,0.6886872099343061,0.3154217431852339,0.6320972310953321 +2022-07-13,0.02277276502102583,0.275200213892291,0.1411174112210827 +2022-07-14,0.6873140760549684,0.011378637620229705,0.45974370059343267 +2022-07-15,0.07534313530707633,0.7028166094688144,0.4648379231093176 +2022-07-16,0.25616463420146923,0.30312255831814927,0.8300920784759557 +2022-07-17,0.39042923476898356,0.17940200575480914,0.36822247497512267 +2022-07-18,1.101712251294755,0.2764644186723496,0.7069552480226137 +2022-07-19,0.2665047600798706,0.0585677945036486,0.33084726283090954 +2022-07-20,1.149278883845257,0.41792222891791914,0.5956316456119415 +2022-07-21,0.7429306478950629,0.2361596390430954,0.552907854857404 +2022-07-22,0.8626331617027151,0.6010691643103292,0.45133136196682994 +2022-07-23,0.6401628939914166,0.6878943248111571,0.12459980651729528 +2022-07-24,0.4174257432174789,0.547895941212128,0.2731581869657834 +2022-07-25,0.15158587860942946,0.32576756897540754,0.8765244257926698 +2022-07-26,0.7673520439880832,0.1808688606697869,0.015944263194607646 +2022-07-27,0.6177652365979475,0.7847717229858028,0.6583847655627048 +2022-07-28,1.193996294145547,0.4073067378283905,0.5495558763160228 +2022-07-29,0.25286928146687665,0.3700835133956013,0.46108772246967566 +2022-07-30,0.18931156967650503,0.7109456928122689,0.5507529983029383 +2022-07-31,0.8023825113648296,0.6961874239524852,0.11543738885071549 +2022-08-01,1.1255613886899165,0.7034361066459455,0.5779039189359444 +2022-08-02,0.02331870412138901,0.35374012519844594,0.019330800300287578 +2022-08-03,0.7836339818721686,0.2944080715402992,0.8428676290180961 +2022-08-04,1.0435955872770168,0.42602183712767494,0.28045848364064874 +2022-08-05,0.5050638124125043,0.11219818959253898,0.3472316143336032 +2022-08-06,1.0539083183058215,0.6868967569104127,0.08063103955484416 +2022-08-07,0.6347267259338876,0.7031376140801928,0.5314116246023783 +2022-08-08,0.4488624643464645,0.37138263795703585,0.7451354325402896 +2022-08-09,0.144394601176531,0.5506080506131984,0.1301195990286874 +2022-08-10,0.48107683425307823,0.06123797078300282,0.6071904086901216 +2022-08-11,0.1899240919066623,0.3592072866669434,0.2627190959600969 +2022-08-12,0.924762246803255,0.6675094215474447,0.41441631067610446 +2022-08-13,0.46739885306857953,0.7864929394750432,0.46125997196849944 +2022-08-14,1.0003016527308883,0.24357516615800617,0.13306868087174234 +2022-08-15,0.47326333815866745,0.7185046683584149,0.5791059630339089 +2022-08-16,0.10449102205808551,0.34242104093063275,0.39968209254361675 +2022-08-17,0.2562918684672371,0.38314984879625147,0.4850482495431066 +2022-08-18,0.4716591285905658,0.6189358521811723,0.7578453281247656 +2022-08-19,0.920243211650783,0.3462781525616856,0.8625846357575558 +2022-08-20,0.5974358526246858,0.18144504532974387,0.2215554677904459 +2022-08-21,0.4516776670803884,0.44995852211743115,0.06309744153989394 +2022-08-22,0.8378346029242159,0.004005898014099874,0.16542866496303196 +2022-08-23,0.049433549163066456,0.1589548901000094,0.11933002411892264 +2022-08-24,0.18194602286993192,0.11820297103706699,0.5197797606252572 +2022-08-25,0.13992687879250137,0.48972733701648763,0.7928734344447356 +2022-08-26,0.6605992869872707,0.44882452951732177,0.18732995003727737 +2022-08-27,0.3855588560837225,0.6521952169347619,0.5224396640594237 +2022-08-28,0.8385696682986762,0.21497320493364427,0.8812693923901623 +2022-08-29,0.34778067591996126,0.5969751150804793,0.2011590769790836 +2022-08-30,0.9117601556845671,0.03537771805674268,0.878622568785097 +2022-08-31,0.3850509689121757,0.7176129715773686,0.8163368164200072 +2022-09-01,0.06558276582671403,0.6035177404555615,0.755284103971016 +2022-09-02,1.196368554005712,0.038075393927057104,0.7059750823509438 +2022-09-03,0.16595943994253956,0.027605056866960177,0.5641331988290298 +2022-09-04,0.08450838388783785,0.2181649596590626,0.8476504227179303 +2022-09-05,0.8044248051619057,0.5754443725346265,0.31591269858632876 +2022-09-06,1.1395856780820846,0.41569274220083186,0.39828316382933165 +2022-09-07,0.025123824818841678,0.7486211491296905,0.6042014855925989 +2022-09-08,0.27498740260697735,0.3023287822190353,0.08766404509363979 +2022-09-09,0.8222895080360113,0.7031568307926594,0.35415656732058903 +2022-09-10,0.23571413078671677,0.7383010112070001,0.38390884103622946 +2022-09-11,0.21377113227160563,0.041186623047152086,0.7717456411459213 +2022-09-12,0.10729896380027774,0.17594931133261796,0.07265586687661356 +2022-09-13,1.0063631900218768,0.43397209471641585,0.17952840409139761 +2022-09-14,0.41354986552692274,0.01339668826865621,0.022324063031726803 +2022-09-15,0.0856269961066591,0.4355791154034889,0.6911541371316975 +2022-09-16,1.0407549539725316,0.2413007466617165,0.5423845721128425 +2022-09-17,0.4876196155884812,0.6915981964509107,0.36087750011854647 +2022-09-18,0.0666749768872954,0.1108092045307581,0.3806452636815391 +2022-09-19,0.5772811353636099,0.6520975878520461,0.5887933722912935 +2022-09-20,0.2204565729303351,0.0868593875813084,0.255026785179709 +2022-09-21,0.34250797793052007,0.6716516236984673,0.22035237888842796 +2022-09-22,0.0047984905508956285,0.7828098374304688,0.03479678757365893 +2022-09-23,0.5888959021975286,0.23767994474507337,0.017425628453780064 +2022-09-24,1.0690100820185495,0.47776005070492994,0.5799500719983176 +2022-09-25,1.1056324713583974,0.45461454483392894,0.6485258198199808 +2022-09-26,1.030605857906371,0.23110067425279768,0.46633991298795385 +2022-09-27,0.6909545298756901,0.5163065622335674,0.8032741039715822 +2022-09-28,0.07074178910953526,0.07532515147316357,0.6604583649150795 +2022-09-29,0.6483520522886205,0.5971355953978942,0.7683693936660305 +2022-09-30,0.08735883554458175,0.1911240686764896,0.2731808149008138 +2022-10-01,0.8104215366339028,0.5581972345563277,0.46382116661600614 +2022-10-02,0.713436107074555,0.261993537279515,0.2708877621799413 +2022-10-03,0.874583429778445,0.4536796629103365,0.06212409764157384 +2022-10-04,0.9219905007164867,0.6411960039449827,0.8353601559059037 +2022-10-05,0.8194944483145886,0.510174287637735,0.5018985494528718 +2022-10-06,1.056444653660813,0.6589364635653527,0.7101739415108004 +2022-10-07,0.14415181196271898,0.40945743640838705,0.702576486711825 +2022-10-08,0.19892951571758635,0.49966188823058755,0.589313775584659 +2022-10-09,0.5938472839028154,0.1171859705062297,0.20780887530513775 +2022-10-10,0.9076200727250243,0.13042085795094485,0.036252076204772575 +2022-10-11,0.2089579420355834,0.5556760199364571,0.13088265910378957 +2022-10-12,1.0149657327468775,0.3277217471480127,0.4706663091326565 +2022-10-13,0.11435134469508154,0.22491383198825599,0.6886882728422001 +2022-10-14,0.11903604271786263,0.3319228483901226,0.33022235153966656 +2022-10-15,0.5339690941123988,0.7845926464370887,0.40660160093388154 +2022-10-16,0.11139231714395782,0.6256251975782124,0.15546508085517735 +2022-10-17,0.7804368827105999,0.343406144362532,0.03029695093663377 +2022-10-18,0.07785104605184369,0.18159638837988334,0.5648266538685139 +2022-10-19,1.047645542826332,0.37820097805517394,0.5801378890715954 +2022-10-20,0.3609951757647852,0.42272614367778527,0.7376788496573262 +2022-10-21,1.126978623125342,0.17632021166429832,0.2952451980246733 +2022-10-22,0.5532318898393382,0.1511447224931926,0.3243442247918642 +2022-10-23,0.7863314861078496,0.351656925928121,0.2739319708766547 +2022-10-24,0.6485217484513227,0.6984500109109038,0.45411266139811163 +2022-10-25,0.4997502032989308,0.10069894962231923,0.7942458939114317 +2022-10-26,0.565492741325527,0.35975719116877464,0.5586364627674238 +2022-10-27,1.139389093430658,0.5562493133901992,0.3156855559599402 +2022-10-28,0.5235679969852086,0.13184400722482678,0.24465848900090836 +2022-10-29,1.0060889186895159,0.7341583527544937,0.05901805256413709 +2022-10-30,0.710977911247091,0.06345657297262185,0.036180268287034405 +2022-10-31,0.5300093900793327,0.1465967908263746,0.03835624794852029 +2022-11-01,0.8364525332251457,0.6449205693733376,0.7231149992172337 +2022-11-02,0.6365742011261156,0.06415914279179971,0.6514821266604426 +2022-11-03,0.47864621526207396,0.23055070211584436,0.15338508162020545 +2022-11-04,1.1666774576099948,0.5797016828983309,0.5289514792967389 +2022-11-05,0.47571541232321,0.45548546194931333,0.5549071432390317 +2022-11-06,1.0099887654598372,0.4763009535244702,0.3837513274697175 +2022-11-07,0.2545283124941296,0.524551863294575,0.347368288070129 +2022-11-08,0.015860987586745166,0.33116485433442605,0.06787287865577295 +2022-11-09,0.9501025014261325,0.7063071532743256,0.19686584239408392 +2022-11-10,0.604050925469999,0.4650155702130014,0.4490829481105272 +2022-11-11,0.010791176206428065,0.30593582311772693,0.2749143474644536 +2022-11-12,0.3340534102448531,0.026640879312587365,0.5146017373804607 +2022-11-13,0.3821024846518198,0.08430695498638441,0.11669825322821673 +2022-11-14,0.11011681516059073,0.5613179346863658,0.07899070096915432 +2022-11-15,0.9380301614368967,0.13205001016724652,0.7071480287296686 +2022-11-16,1.110343103309815,0.1274399164283647,0.21416660454709355 +2022-11-17,0.6671884791494357,0.5054349057863211,0.20132131892766383 +2022-11-18,0.5721085807588856,0.2912988535564147,0.4242548114679946 +2022-11-19,0.4667833970912611,0.2957140199661386,0.11589239953219217 +2022-11-20,0.6207789814219782,0.5663593416471846,0.7194587327970214 +2022-11-21,1.0403505827735902,0.18320214543496177,0.4014499750957553 +2022-11-22,0.6393217257609645,0.33200316070265184,0.06630939288179365 +2022-11-23,0.2753207131601788,0.6111441043627979,0.6634952005311182 +2022-11-24,0.5638700265682818,0.03716005244452969,0.09199427151419998 +2022-11-25,0.6078222138522232,0.5762838478286993,0.763752823183869 +2022-11-26,0.006247529267804408,0.19239278324740772,0.3850258320507619 +2022-11-27,0.5564384417681256,0.36427897278740845,0.42667766452870554 +2022-11-28,0.6784823470345407,0.4908704120702201,0.8191224657393502 +2022-11-29,0.5199018405608127,0.7227414084967092,0.0845082058485264 +2022-11-30,0.7295604116934747,0.6836521953754828,0.7525490940959997 +2022-12-01,0.8531110719084226,0.17704122755624516,0.40750009193362785 +2022-12-02,0.06069932237339861,0.1900048608214358,0.8441641611451823 +2022-12-03,0.47594220022191513,0.5742575002975379,0.3421467098879441 +2022-12-04,0.6644945652865581,0.47376949640411037,0.7192669251428156 +2022-12-05,0.7291439102805841,0.1165830117219036,0.17864435133830692 +2022-12-06,0.8371555428654363,0.48862070927463164,0.6377035104804888 +2022-12-07,0.0954753356242465,0.3276232636951341,0.42221005464921796 +2022-12-08,0.6545260686600118,0.5408211771423631,0.7170760796200382 +2022-12-09,1.0958104684534913,0.08459260744739705,0.21546079670474524 +2022-12-10,0.2462128931950779,0.17037002800986284,0.19936099946558808 +2022-12-11,0.8774270307512129,0.2995798726798826,0.6339618699613232 +2022-12-12,1.0566721581194065,0.012347389365692152,0.5854853511406751 +2022-12-13,4.9931547367432216e-05,0.4765445334954205,0.276890207400272 +2022-12-14,0.15766652019211164,0.4487410471792923,0.061065072422618674 +2022-12-15,0.7236166384542841,0.137530941936632,0.7469364161412436 +2022-12-16,0.34202109526832286,0.0010450493050846888,0.18212781235552974 +2022-12-17,1.1743735009195935,0.18920276349060297,0.5140355326097058 +2022-12-18,0.9650869893324556,0.5037263806811444,0.40364868074654503 +2022-12-19,0.891465698359864,0.465891562247966,0.40263978256879823 +2022-12-20,0.3845441727405781,0.4480102886996755,0.3103380281244382 +2022-12-21,1.1250461959662967,0.716884831002603,0.5691238133853151 +2022-12-22,0.9133782905176442,0.20313166967792579,0.38807014327324263 +2022-12-23,0.5960127400095957,0.6964140695362181,0.2863155391478317 +2022-12-24,0.02466337208997067,0.7370496855949846,0.23877439705114578 +2022-12-25,0.3803929135993322,0.5783022606162617,0.2867981983557938 +2022-12-26,0.8414929927517252,0.175240750660089,0.34882521056640825 +2022-12-27,0.35824208049810496,0.6727097694321345,0.2045592950078828 +2022-12-28,0.506335908273395,0.678643865844982,0.09449392059575956 +2022-12-29,0.3386819434659408,0.22449702353772577,0.35097673609030655 +2022-12-30,0.10630071676454213,0.09056994006932087,0.11246447683751674 +2022-12-31,0.3625262673723699,0.16195624533456776,0.038367687651444736 diff --git a/Finacial Domain/Currency Arbitrage with Reinforcement Learning/readme.md b/Finacial Domain/Currency Arbitrage with Reinforcement Learning/readme.md new file mode 100644 index 00000000..d1814ddd --- /dev/null +++ b/Finacial Domain/Currency Arbitrage with Reinforcement Learning/readme.md @@ -0,0 +1,30 @@ +# Financial Projects with Reinforcement Learning + +1.Currency Arbitrage with Reinforcement Learning + +##Currency Arbitrage with Reinforcement Learning + +### Overview +This project involves developing a Reinforcement Learning (RL) model to perform currency arbitrage. The agent learns to make profitable trades between different currency pairs by observing historical exchange rate data. + +### Dataset +The dataset contains historical exchange rates with the following columns: +- `Date`: The date of the observation. +- `USD_EUR`: Exchange rate from USD to EUR. +- `USD_GBP`: Exchange rate from USD to GBP. +- `EUR_GBP`: Exchange rate from EUR to GBP. + +##Custom Environment +The custom environment is defined in currency_arbitrage_env.py. It handles the interactions between the agent and the market, including actions (Buy, Sell, Hold) and rewards. + +## Training the Agent +The agent is trained using the DQN algorithm from stable-baselines3. The training process involves learning from the historical data to make profitable trades. + +## requirements +Python 3.7+ +pandas +numpy +gym +stable-baselines3 + +