Comments (1)
self.cost is a is a variable to track the cost of the agents strategy and updated after each sell/buy action
+=
it will change the account balance because the cost for trading a stock is directly substracted from the money the agent has.
It will not update the new amount of shares:
What this function does:
- check if the stock is currently held if yes the sell the amount the agent decided as an action
- update the balance by incresasing the balance money you get from the selling of that stock (minus transaction costs so (1-TRANSACTION_FFE_PERCENT)) (not min(abs(action,self.state[index+STOCK_DIM+1]) ensures that you can just sell maximum the amount of shares currently held of that stock because if the rescaled action says "sell 10 stocks but you just hold 5 stocks" you can just sell 5 stocks because no short selling is allowed.
- update the number of that particular stock currently held if you hold 10 stocks and sell 5 then you just hold 5 stocks
- update the cost variable to track the money spend by follwing the agents strategy
- update te count of trades so after each sell/buy action it is increased by 1 to see in the end how much trades the agent made
so yes you are right every sell action deductes the transaction cost directly from the balance
i created a similar environment but seperated the balance, stock_prices, num_stocks in the portfolio to increase readability
just think about it as this
def _sell_stock(self, index, action):
self.holdings[index] > 0: (step 1)
#update balance, holding, cost, trade_count
amount = round(min(abs(action),self.holdings[index])) #amount to trade (step 2)
stock_sell_activity = [self.day,index,amount] (aditionally Track sell activity)
self.balance += self.stock_price[index]amount(1-TRANSACTION_FEE_PERCENT-BPS) (step 2) update balance note BPS is a spread considere because bid and aski prices differ
self.holdings[index] -= amount (step 3) update the hodling of the particular stock by substracting the amount sold
self.cost += self.stock_price[index]amount(TRANSACTION_FEE_PERCENT+BPS) (step 4)
self.daily_cost += self.stock_price[index]amount(TRANSACTION_FEE_PERCENT+BPS) (aditionally track daily cost of the strategy)
self.daily_sell_amount += round(self.stock_price[index]amount(1-TRANSACTION_FEE_PERCENT-BPS)) (additonally to tracl daily amount sold )
self.trades+=1 (step 5)
else:
pass
from finrl-trading.
Related Issues (20)
- The output actions or the portfolio weights look like this: HOT 1
- SyntaxError HOT 2
- Rebalance window
- Question regarding the observation space in the Env
- Format of original data
- Cannot copy sequence with size... even with correct observation space dim. HOT 1
- python 3.6.0 is not supported
- Backtesting results
- Please ask why bring my stock data into the training, the action produces nan HOT 2
- I am trying to run this code but NameError: name 'DRLEnsembleAgent' is not defined
- Including more variables into the algorithm
- Problem with stockenvtrain, stockenvvalidation and stockenvtrade HOT 3
- I have add other 2 algorithms to this ensemble stragegy but i am gettting error
- No module named 'env' HOT 3
- Trying to integrate model with SPY stocks
- deployment page down
- What can I do for Crypto trading?
- A Synergistic Exploration of RL-Based Stock trading & Quantitative finance Strategies for an Enhanced understanding of the trading.
- Repository not found for Phase II: Portfolio Allocation
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from finrl-trading.