-
-
Notifications
You must be signed in to change notification settings - Fork 542
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement BaseRewardStrategy interface more clearly.
- Loading branch information
1 parent
36d3717
commit 80a55cf
Showing
6 changed files
with
67 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,4 @@ | ||
from lib.env.TradingEnv import TradingEnv | ||
from lib.env.render.TradingChart import TradingChart | ||
|
||
import lib.env.reward as reward |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import pandas as pd | ||
|
||
from abc import ABCMeta, abstractmethod | ||
from typing import List | ||
|
||
|
||
class BaseRewardStrategy(object, metaclass=ABCMeta): | ||
@abstractmethod | ||
@staticmethod | ||
def get_reward(observations: pd.DataFrame, | ||
account_history: pd.DataFrame, | ||
net_worths: List[float], | ||
last_bought: int, | ||
last_sold: int, | ||
current_price: float) -> float: | ||
raise NotImplementedError() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import pandas as pd | ||
|
||
from typing import List | ||
|
||
from lib.env.reward import BaseRewardStrategy | ||
|
||
|
||
class IncrementalProfit(BaseRewardStrategy): | ||
@staticmethod | ||
def get_reward(observations: pd.DataFrame, | ||
account_history: pd.DataFrame, | ||
net_worths: List[float], | ||
last_bought: int, | ||
last_sold: int, | ||
current_price: float): | ||
prev_balance = account_history['balance'].values[-2] | ||
curr_balance = account_history['balance'].values[-1] | ||
reward = 0 | ||
|
||
if curr_balance > prev_balance: | ||
reward = net_worths[-1] - net_worths[last_bought] | ||
elif curr_balance < prev_balance: | ||
reward = observations['Close'].values[last_sold] - current_price | ||
|
||
return reward |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
from lib.env.reward.IncrementalProfit import IncrementalProfit | ||
from lib.env.reward.BaseRewardStrategy import BaseRewardStrategy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters