Spaces:
Runtime error
Runtime error
Commit
·
c3e8fb1
1
Parent(s):
84ad1cc
Visualize total profits
Browse files- app.py +10 -4
- rl_agent/env.py +0 -4
app.py
CHANGED
|
@@ -18,6 +18,11 @@ def get_time():
|
|
| 18 |
return datetime.datetime.now().time()
|
| 19 |
|
| 20 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
def pretrain_rl_agent():
|
| 22 |
global equity
|
| 23 |
observations = env_train.reset()
|
|
@@ -26,6 +31,7 @@ def pretrain_rl_agent():
|
|
| 26 |
observations = torch.as_tensor(observations).float()
|
| 27 |
action = agent(observations)
|
| 28 |
observations, reward, _ = env_train.step(action.data.to("cpu").numpy())
|
|
|
|
| 29 |
|
| 30 |
action.backward()
|
| 31 |
|
|
@@ -92,7 +98,7 @@ data = data.tail(50000)
|
|
| 92 |
data = data.set_index('Local time')
|
| 93 |
date_split = '01.01.2023 16:04:00.000 GMT-0600'
|
| 94 |
|
| 95 |
-
learning_rate = 0.
|
| 96 |
first_momentum = 0.0
|
| 97 |
second_momentum = 0.0001
|
| 98 |
transaction_cost = 0.0001
|
|
@@ -183,10 +189,10 @@ def trading_plot():
|
|
| 183 |
# The UI of the demo defines here.
|
| 184 |
with gr.Blocks() as demo:
|
| 185 |
gr.Markdown("Auto trade bot.")
|
| 186 |
-
gr.Markdown(f"Profit: {profit}")
|
| 187 |
|
| 188 |
-
|
| 189 |
-
|
| 190 |
|
| 191 |
# for plotly it should follow this: https://gradio.app/plot-component-for-maps/
|
| 192 |
candlestick_plot = gr.Plot().style()
|
|
|
|
| 18 |
return datetime.datetime.now().time()
|
| 19 |
|
| 20 |
|
| 21 |
+
def get_profit():
|
| 22 |
+
global profit
|
| 23 |
+
return profit
|
| 24 |
+
|
| 25 |
+
|
| 26 |
def pretrain_rl_agent():
|
| 27 |
global equity
|
| 28 |
observations = env_train.reset()
|
|
|
|
| 31 |
observations = torch.as_tensor(observations).float()
|
| 32 |
action = agent(observations)
|
| 33 |
observations, reward, _ = env_train.step(action.data.to("cpu").numpy())
|
| 34 |
+
reward *= 1e3
|
| 35 |
|
| 36 |
action.backward()
|
| 37 |
|
|
|
|
| 98 |
data = data.set_index('Local time')
|
| 99 |
date_split = '01.01.2023 16:04:00.000 GMT-0600'
|
| 100 |
|
| 101 |
+
learning_rate = 0.01
|
| 102 |
first_momentum = 0.0
|
| 103 |
second_momentum = 0.0001
|
| 104 |
transaction_cost = 0.0001
|
|
|
|
| 189 |
# The UI of the demo defines here.
|
| 190 |
with gr.Blocks() as demo:
|
| 191 |
gr.Markdown("Auto trade bot.")
|
| 192 |
+
# gr.Markdown(f"Profit: {profit}")
|
| 193 |
|
| 194 |
+
dt = gr.Textbox(label="Total profit")
|
| 195 |
+
demo.queue().load(get_profit, inputs=None, outputs=dt, every=1)
|
| 196 |
|
| 197 |
# for plotly it should follow this: https://gradio.app/plot-component-for-maps/
|
| 198 |
candlestick_plot = gr.Plot().style()
|
rl_agent/env.py
CHANGED
|
@@ -37,16 +37,12 @@ class Environment:
|
|
| 37 |
self.position_value = act
|
| 38 |
|
| 39 |
self.history.pop(0)
|
| 40 |
-
|
| 41 |
self.history.append(self.data.iloc[self.t, :]['Close'] - self.data.iloc[(self.t-1), :]['Close']) # the price being traded
|
| 42 |
-
|
| 43 |
self.position_value = self.position_value.item()
|
| 44 |
|
| 45 |
return [self.position_value] + self.history, reward, self.done # obs, reward, done
|
| 46 |
|
| 47 |
|
| 48 |
-
|
| 49 |
-
|
| 50 |
if __name__ == "__main__":
|
| 51 |
data = pd.read_csv('./data/EURUSD_Candlestick_1_M_BID_01.01.2021-04.02.2023.csv')
|
| 52 |
# data['Local time'] = pd.to_datetime(data['Local time'])
|
|
|
|
| 37 |
self.position_value = act
|
| 38 |
|
| 39 |
self.history.pop(0)
|
|
|
|
| 40 |
self.history.append(self.data.iloc[self.t, :]['Close'] - self.data.iloc[(self.t-1), :]['Close']) # the price being traded
|
|
|
|
| 41 |
self.position_value = self.position_value.item()
|
| 42 |
|
| 43 |
return [self.position_value] + self.history, reward, self.done # obs, reward, done
|
| 44 |
|
| 45 |
|
|
|
|
|
|
|
| 46 |
if __name__ == "__main__":
|
| 47 |
data = pd.read_csv('./data/EURUSD_Candlestick_1_M_BID_01.01.2021-04.02.2023.csv')
|
| 48 |
# data['Local time'] = pd.to_datetime(data['Local time'])
|