siddheshtv commited on
Commit
1d88157
·
verified ·
1 Parent(s): 24efe27

create readme.md

Browse files
Files changed (1) hide show
  1. README.md +86 -0
README.md ADDED
@@ -0,0 +1,86 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: mit
3
+ language:
4
+ - en
5
+ tags:
6
+ - td3
7
+ - stock prediction
8
+ - reinforcement learning
9
+ ---
10
+
11
+ # TD3 Model for AAPL Stock Prediction
12
+ ## Model Description
13
+
14
+ This model is a TD3 (Twin Delayed Deep Deterministic Policy Gradient) algorithm applied for stock price prediction, specifically trained on AAPL (Apple Inc.) stock data. The TD3 model is a reinforcement learning agent that interacts with a stock market environment and is trained to predict and maximize the return from trading AAPL stock.
15
+
16
+ ### Key Features
17
+ - Asset: AAPL (Apple Inc.) Stock
18
+ - Model Type: TD3 (Twin Delayed DDPG)
19
+ - Action Space: Continuous (Buy, Sell, Hold decisions)
20
+ - Reward: Modeled on cumulative returns
21
+ - Training Data: Historical stock prices and related financial indicators for AAPL stock
22
+ - Environment: Custom stock trading environment simulating price movement and portfolio management
23
+ - Framework: PyTorch
24
+
25
+ ## Quick Run
26
+ To use this model for stock prediction and trading, install the required dependencies and load the model via Hugging Face. Here is an example code snippet:
27
+
28
+ ```python
29
+ import torch
30
+ from huggingface_hub import hf_hub_download
31
+ import torch.nn as nn
32
+ import numpy as np
33
+
34
+ # Download the model
35
+ model_path = hf_hub_download(repo_id="siddheshtv/td3-stock-aapl", filename="td3_stock_prediction_model_AAPL_full.pth")
36
+
37
+ # Load the model
38
+ checkpoint = torch.load(model_path)
39
+
40
+ # Recreate the Actor class
41
+ class Actor(nn.Module):
42
+ def __init__(self, state_dim, action_dim, max_action):
43
+ super(Actor, self).__init__()
44
+ self.net = nn.Sequential(
45
+ nn.Linear(state_dim, 400),
46
+ nn.ReLU(),
47
+ nn.Dropout(0.2),
48
+ nn.Linear(400, 300),
49
+ nn.ReLU(),
50
+ nn.Dropout(0.2),
51
+ nn.Linear(300, action_dim),
52
+ nn.Tanh()
53
+ )
54
+ self.max_action = max_action
55
+
56
+ def forward(self, state):
57
+ return self.max_action * self.net(state)
58
+
59
+ # Instantiate the model
60
+ model = Actor(checkpoint['state_dim'], checkpoint['action_dim'], checkpoint['max_action'])
61
+ model.load_state_dict(checkpoint['model_state_dict'])
62
+ model.eval() # Set the model to evaluation mode
63
+
64
+ # Function to select action
65
+ def select_action(state):
66
+ with torch.no_grad():
67
+ state = torch.FloatTensor(state.reshape(1, -1))
68
+ return model(state).cpu().data.numpy().flatten()
69
+
70
+ # Example usage
71
+ state = np.random.rand(checkpoint['state_dim']) # Replace with actual state data
72
+ action = select_action(state)
73
+ print(f"Predicted action: {action}")
74
+ ```
75
+
76
+ ## Citation
77
+
78
+ ```
79
+ @misc{siddheshtv-td3,
80
+ title={TD3 Model for AAPL Stock Prediction},
81
+ author={Siddhesh Kulthe},
82
+ year={2024},
83
+ howpublished={\url{https://huggingface.co/siddheshtv/td3-stock-aapl}},
84
+ note={TD3 model for predicting stock price movements of AAPL using reinforcement learning},
85
+ }
86
+ ```