# Looping over Sarsa algorithm for better Q values

Let's say an RL trading system places trades based on pricing data.

Each episode represents 1 hour of trading, and there are 24 hours of data available. The Q table represents for a given state, what is the most action with the highest utility.

The state is a sequence of prices, and the action is either buy, hold, sell.

Instead of "Loop for each episode" as per the Sarsa algorithm :

for 1 to N:
"Loop for each episode"


Manually set N or exit out of the loop on convergence.

Is this the correct approach? Iterating multiple times over the episodes will produce more valuable state-action pairs in the Q table, because e greedy is not deterministic and for each iteration may exploit an action to greater reward than other episode epochs.

• do you have a fixed data set or are you able to generate data from the environment? if it is the latter, then yes your approach is correct Commented Jun 18, 2020 at 15:14
• @David Ireland the dataset is fixed as for a given time interval the price values do not change. I'm confused by your comment 'generate data' as the model utilises data from the environment, the source of the environment pricing data is a trading exchange. So I can generate data by reading the pricing data but I'm not sure if I'm interpreting correctly 'generate data from the environment' . Commented Jun 18, 2020 at 15:29
• The way I understood your post was that you have an episode that is 24 steps long. Each step you get a series of prices and you have to decide whether to hold/sell/buy. If so, then are you able to interact with an environment arbitrarily, e.g. can you run simulations of this? or is your data set fixed? Commented Jun 18, 2020 at 16:58
• @DavidIreland yes can run simulations where the reward of choosing buy/hold/sell for each step is observed. The dataset is fixed in that the number of prices for the environment is immutable. The episode length is mutable, for example If I set the episode length from 1 to two hours then there are 12 episodes available and the number of price attributes for each state will double. Commented Jun 18, 2020 at 17:45
• Okay, then it seems like it should work by following the table. However, is your state space continuous? If so, then you may want to use Deep Q-Learning. Commented Jun 18, 2020 at 18:32