Answers.Body: <blockquote>
    <p>I want to maximize the profit inside a trading day and avoid to place the pair (limit buy order, limit sell order) if the profit on that transaction is less than 100$. Be aware that I thought using the "Profit &amp; Loss" as the reward.</p>
  </blockquote>
  
  <p>To me this implies that your profit per transaction is not the true reward function that you should be using. You don't say directly in the question, but presumably there is some per-transaction cost, tax or other issue which means that these low gain transactions are not desirable. </p>
  
  <p>The answer is to find a more accurate reward function. You have suggested a quick fix of subtracting a fixed offset from the reward. This should have a desirable effect of limiting borderline buy/sell arrangements and meeting your constraint, so I would suggest trying it. The main issue I see with it is that you may have changed the reward function so that it doesn't truly reflect your goals.</p>
  
  <p>A better approach is to look more carefully at the problem and your goals at a higher level. There must be a reason for wanting to avoid these smaller profit transactions. What is it, and can it be expressed itself as a reward? For instance, if there will be a transaction fee, include that. If the fee structure or reasoning is complicated or appears delayed or aggregated over many actions, then this makes optimisation harder, but RL is actually designed to cope with this. You could for instance only reward the agent with profit/loss after a group of actions covering a whole day's trade. You would then rely on the learning algorithm to figure out which states and actions combined to generate the observed reward.</p>
  
  <p>If there is an unknown or random difference between predicted and actual financial gain then no amount of juggling the reward function gets around that. For RL, learning about and predicting expected gains is "built in", but that does not mean that this task becomes easier - in fact if prediction in the problem is hard, you may be better off focusing on that and forgetting RL at least initially. Your question is not clear on that, but if you want to avoid risk whilst learning, you should bear in mind that a simple hard rule would likely interfere with the ability of RL to work. At its heart RL is a trial-and-error learning system. Errors should be expected, and are required for the system to learn where best the balance point is between risk and reward. Of course that doesn't help you if the learning system would deliberately make you bankrupt exploring what happens when you sell things at a loss - there are likely to be ways to avoid that and still achieve your goals, but you will need to explain more about your system in a different question.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-01-19T20:56:09.187Z
Answers.Text: The purpose of wanting minimum $100 profit per transaction is simply to avoid the small movements profits and it gives me a sort of protection.Yeah, implicitly I want to cover a least the commission.
Answers.UserDisplayName: fgauth
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-01-19T21:06:57.913Z
Answers.Text: @fgauth: What prevents you including the commission in the reward calculation? Just base the reward on the actual money in your pocket after all handling costs . . . add in a cost for wasting your time too if you like
Answers.UserDisplayName: Neil Slater
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-01-19T21:33:24.807Z
Answers.Text: The commission is neglected for the moment as it is a very little amount. The idea here is to avoid the little noisy movements. Instead, I prefer long beautiful profitable movements. That's why I want a $100 minimum profit.
Answers.UserDisplayName: fgauth
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-01-19T22:00:09.643Z
Answers.Text: @fgauth: Then you need to put a price/reward on your preference, and you should note that forcing the agent to follow your preference could lead it to perform less well by other measurements.
Answers.UserDisplayName: Neil Slater
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-01-19T22:04:47.877Z
Answers.Text: You seem to know what you're talking about. Do you have time to discuss in a private room, i.e. Hangouts or whatever?
Answers.UserDisplayName: fgauth
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-01-20T08:51:09.147Z
Answers.Text: @fgauth: No sorry I don't want to schedule a meeting or chat. However, if you can phrase your problem as a question on this site, I might be able to answer. It takes some effort to ask a good question here, but it is good practice if some of your thinking is still unclear - sometimes merely thinking through and phrasing your question properly will help you find your own asnwer.
Answers.UserDisplayName: Neil Slater
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-01-20T08:56:41.797Z
Answers.Text: @fgauth: I have seen your second question, and it seems clearer. Although I won't be able to answer it as you have left the financial side unexplained (you will need a trading expert to understand what it is you actually want), I think it is a good fit for the site and upvoted it.
Answers.UserDisplayName: Neil Slater
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-03-03T07:45:59.127Z
Answers.Text: @fgauth "commission is neglected for the moment as it is a very little amount", I do not agree with you. Studies have shown that when transaction fees are included machine learning fails to out perform a buy and hold strategy. Trading fees eat away profit, especially the compounded negative effect of trading fees.
Answers.UserDisplayName: Jason
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-01-19T14:30:41.393Z
Answers.LastActivityDate: 2019-01-20T15:46:29.887Z
Answers.LastEditDate: 2019-01-20T15:46:29.887Z
Answers.UserDisplayName: Neil Slater
Answers.Body: <p>I would use the proposed fitness function defined in your other <a href="https://ai.stackexchange.com/questions/10082/suitable-reward-function-for-trading-buy-and-sell-orders">StackExchange</a> question. I would then inflate the buying price used in the equation by \$100, and leave the selling price as the price the shares were sold for. This would only reward a trading rule when profit is greater than \$100.</p>
  
  <p>If you want to minimise spike it might be best to normalise the data going into your learning algorithm, for example use an x day moving average instead of the actual share price.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-02-27T12:02:55.730Z
Answers.LastActivityDate: 2019-02-27T12:02:55.730Z
Answers.UserDisplayName: Jason
Body: <p>I am working to build a reinforcement agent with DQN. The agent would be able to place buy and sell orders for a day trading purpose. I am facing a little problem with that project. The question is "how to tell the agent to maximize the profit and avoid the transaction where the profit is less than 100$".</p>
  
  <p>I want to maximize the profit inside a trading day and avoid to place the pair (limit buy order, limit sell order) if the profit on that transaction is less than 100$. The idea here is to avoid the little noisy movements. Instead, I prefer long beautiful profitable movements. Be aware that I thought using the "Profit &amp; Loss" as the reward.</p>
  
  <p>"I want the minimal profit per transaction to be 100$" ==> It seems this is not something that is enforceable. I can train the agent to maximize profit per transaction, but how that profit is cannot be ensured.</p>
  
  <p>At the beginning, I wanted to tell the agent, if the profit of a transaction is 50 dollars, I will remove 100 dollars, then It becomes a penalty of 50 dollars for the agent. I thought it was a great way to tell the agent to not place a limit buy order if you are not sure it will give us a minimal profit of 100$. It seems that all I would be doing there is simply shifting the value of the reward. The agent only cares about maximizing the sum of rewards and not taking care of individual transactions. </p>
  
  <p>How to tell the agent to maximize the profit and avoid the transaction where the profit is less than 100$? With that strategy, what guarantee that the agent will never make a buy/sell decision that results in less than 100 dollars profit? Does the sum of reward - # transaction * 100 can be a solution?</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-01-18T17:55:07.820Z
Comments.Text: Does every transaction correspond to one action, or are multiple actions required for a single transaction, or can a single action lead to multiple transactions? If you have that every action results in exactly one transaction with exactly one reward (that transaction's profit)... then the most straightforward solution would be to simply replace any reward $R_t < 100$ with $R_t = 0$, but keep it unmodified if $R_t \geq 100$
Comments.UserDisplayName: Dennis Soemers
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-01-18T18:18:31.683Z
Comments.Text: or shift all rewards by $-100$ I suppose, such that a hypothetical "do-nothing" action with a default reward of $0$ would be preferred over transactions with rewards $< 100$. It really depends on exactly how your problem is formulated though, what are states, what are actions, etc.
Comments.UserDisplayName: Dennis Soemers
Tags: <reinforcement-learning><dqn><rewards>
Title: For some reasons, a reward becomes a penalty if
UserDisplayName: fgauth
ThreadText: # For some reasons, a reward becomes a penalty if
  
  (Asked by: username_0 on 2019-01-18)
  
  I am working to build a reinforcement agent with DQN. The agent would be able to place buy and sell orders for a day trading purpose. I am facing a little problem with that project. The question is "how to tell the agent to maximize the profit and avoid the transaction where the profit is less than 100$".
  
  I want to maximize the profit inside a trading day and avoid to place the pair (limit buy order, limit sell order) if the profit on that transaction is less than 100$. The idea here is to avoid the little noisy movements. Instead, I prefer long beautiful profitable movements. Be aware that I thought using the "Profit & Loss" as the reward.
  
  "I want the minimal profit per transaction to be 100$" ==> It seems this is not something that is enforceable. I can train the agent to maximize profit per transaction, but how that profit is cannot be ensured.
  
  At the beginning, I wanted to tell the agent, if the profit of a transaction is 50 dollars, I will remove 100 dollars, then It becomes a penalty of 50 dollars for the agent. I thought it was a great way to tell the agent to not place a limit buy order if you are not sure it will give us a minimal profit of 100$. It seems that all I would be doing there is simply shifting the value of the reward. The agent only cares about maximizing the sum of rewards and not taking care of individual transactions.
  
  How to tell the agent to maximize the profit and avoid the transaction where the profit is less than 100$? With that strategy, what guarantee that the agent will never make a buy/sell decision that results in less than 100 dollars profit? Does the sum of reward - # transaction \* 100 can be a solution?
  
  **Tags:** reinforcement-learning, dqn, rewards
  
  > **Comments:**
  > **username_1**: Does every transaction correspond to one action, or are multiple actions required for a single transaction, or can a single action lead to multiple transactions? If you have that every action results in exactly one transaction with exactly one reward (that transaction's profit)... then the most straightforward solution would be to simply replace any reward $R_t < 100$ with $R_t = 0$, but keep it unmodified if $R_t \geq 100$  
  > **username_1**: or shift all rewards by $-100$ I suppose, such that a hypothetical "do-nothing" action with a default reward of $0$ would be preferred over transactions with rewards $< 100$. It really depends on exactly how your problem is formulated though, what are states, what are actions, etc.  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_2 on 2019-01-19. Score: 1
  
  > I want to maximize the profit inside a trading day and avoid to place the pair (limit buy order, limit sell order) if the profit on that transaction is less than 100$. Be aware that I thought using the "Profit & Loss" as the reward.
  
  To me this implies that your profit per transaction is not the true reward function that you should be using. You don't say directly in the question, but presumably there is some per-transaction cost, tax or other issue which means that these low gain transactions are not desirable.
  
  The answer is to find a more accurate reward function. You have suggested a quick fix of subtracting a fixed offset from the reward. This should have a desirable effect of limiting borderline buy/sell arrangements and meeting your constraint, so I would suggest trying it. The main issue I see with it is that you may have changed the reward function so that it doesn't truly reflect your goals.
  
  A better approach is to look more carefully at the problem and your goals at a higher level. There must be a reason for wanting to avoid these smaller profit transactions. What is it, and can it be expressed itself as a reward? For instance, if there will be a transaction fee, include that. If the fee structure or reasoning is complicated or appears delayed or aggregated over many actions, then this makes optimisation harder, but RL is actually designed to cope with this. You could for instance only reward the agent with profit/loss after a group of actions covering a whole day's trade. You would then rely on the learning algorithm to figure out which states and actions combined to generate the observed reward.
  
  If there is an unknown or random difference between predicted and actual financial gain then no amount of juggling the reward function gets around that. For RL, learning about and predicting expected gains is "built in", but that does not mean that this task becomes easier - in fact if prediction in the problem is hard, you may be better off focusing on that and forgetting RL at least initially. Your question is not clear on that, but if you want to avoid risk whilst learning, you should bear in mind that a simple hard rule would likely interfere with the ability of RL to work. At its heart RL is a trial-and-error learning system. Errors should be expected, and are required for the system to learn where best the balance point is between risk and reward. Of course that doesn't help you if the learning system would deliberately make you bankrupt exploring what happens when you sell things at a loss - there are likely to be ways to avoid that and still achieve your goals, but you will need to explain more about your system in a different question.
  
  > **Comments:**
  > **username_0**: The purpose of wanting minimum $100 profit per transaction is simply to avoid the small movements profits and it gives me a sort of protection.Yeah, implicitly I want to cover a least the commission.  
  > **username_2**: @username_0: What prevents you including the commission in the reward calculation? Just base the reward on the actual money in your pocket after all handling costs . . . add in a cost for wasting your time too if you like  
  > **username_0**: The commission is neglected for the moment as it is a very little amount. The idea here is to avoid the little noisy movements. Instead, I prefer long beautiful profitable movements. That's why I want a $100 minimum profit.  
  > **username_2**: @username_0: Then you need to put a price/reward on your preference, and you should note that forcing the agent to follow your preference could lead it to perform less well by other measurements.  
  > **username_0**: You seem to know what you're talking about. Do you have time to discuss in a private room, i.e. Hangouts or whatever?  
  > **username_2**: @username_0: No sorry I don't want to schedule a meeting or chat. However, if you can phrase your problem as a question on this site, I might be able to answer. It takes some effort to ask a good question here, but it is good practice if some of your thinking is still unclear - sometimes merely thinking through and phrasing your question properly will help you find your own asnwer.  
  > **username_2**: @username_0: I have seen your second question, and it seems clearer. Although I won't be able to answer it as you have left the financial side unexplained (you will need a trading expert to understand what it is you actually want), I think it is a good fit for the site and upvoted it.  
  > **username_3**: @username_0 "commission is neglected for the moment as it is a very little amount", I do not agree with you. Studies have shown that when transaction fees are included machine learning fails to out perform a buy and hold strategy. Trading fees eat away profit, especially the compounded negative effect of trading fees.  
  
  ---
  
  ### Answer by username_3 on 2019-02-27. Score: 1
  
  I would use the proposed fitness function defined in your other [StackExchange](https://ai.stackexchange.com/questions/10082/suitable-reward-function-for-trading-buy-and-sell-orders) question. I would then inflate the buying price used in the equation by \$100, and leave the selling price as the price the shares were sold for. This would only reward a trading rule when profit is greater than \$100.
  
  If you want to minimise spike it might be best to normalise the data going into your learning algorithm, for example use an x day moving average instead of the actual share price.
  
  
  ---
  
  