vermouth1992 / drl-portfolio-management Goto Github PK
View Code? Open in Web Editor NEWCSCI 599 deep learning and its applications final project
License: MIT License
CSCI 599 deep learning and its applications final project
License: MIT License
Hi,
I like to know if we change our data, I am downloading for yf and I am getting exactly same as market portfolio. I have transferred the data into required shape, of around 4000 data points (Open,Close,low, high, Adj Close) and have tried config changes, window length, Epochs and batch size. @vermouth1992, I will be very thankful if you could inform if the data need to be changed before application of DDPG (both LSTM and CNN is giving exactly equity weighted porfolio)
P.S : with 28 stocks with 15 year of data and model is taking approximately 5 minutes to build the graphs.
Thank you,
Best regards
Hi. Very nice work and worth a look. Actually, i think would like to play with the environment. I found that your data_visualization does not work very well. It has error saying that DataGenerator object has no attribute 'step'. it also has no attribute 'data'.
Hello, thanks for sharing your work.
When I try the ddpg_experiments.ipynb, I find that the model didn't recognize weekend and still buy at
the open price and sell at close price, hence it keep accumulate rewards at weekend using the open/close price ratio at Friday.
You can find the error by checking env.infos
env = PortfolioEnv(target_history, target_stocks, window_length=3, steps=1000, sample_start_date='2012-08-17')
test_model(env, ddpg_model)
for i in range(500):
print(env.infos[i]['date'], env.infos[i]['portfolio_value'], env.infos[i]['return'])
the partial results shows:
2012-09-02 1.058014239550557 0.0013116319398563077
2012-09-03 1.059402875785309 0.0013116323757466268
2012-09-04 1.0607933903235898 0.0013116849102682993
2012-09-05 1.0675025217029879 0.006304718720860286
2012-09-06 1.0637071820637054 -0.003561680119160464
2012-09-07 1.090686865405708 0.025047501078305816
2012-09-08 1.0773419908170259 -0.012310761424490245
2012-09-09 1.0641603946671545 -0.012310761448217923
2012-09-10 1.0511400792449224 -0.012310761426362674
2012-09-11 1.0297269828798703 -0.020581662744926732
2012-09-12 1.0308227588613141 0.0010635764348758947
2012-09-13 1.016849685771081 -0.013647973711283193
2012-09-14 1.0218781309497884 0.004932934435793886
2012-09-15 0.9946166375396496 -0.027040143728223203
2012-09-16 0.9986255719667779 0.004022531505118037
2012-09-17 1.0026506649364386 0.004022531505279921
The almost identical rewards we got at 9/2, 9/3, 9/4 and every weekend messed up our portfolio value.
Any ideas?
Hey there,
Nice work :)
I am facing an issue when I run cnn_experiments python notebook with tensorflow backend,it throws up the following error:
I formed the window length to be 15,test stocks to be 3,I defined the window of dimension 3,15,1.
but when the text_x and test _y are sent to the model, the model throws and error stating that the expected input is 3,15,1 while the value send is 4320,3,15,4.
Will you be able to point me in the right direction to get this issue sorted
How should I be conditioning my window length, any advice will be helpful
Could you please tell me how can I train the model? For example, how can I get the same parameters of DDPG models used in ddpg_experiments?
Thanks!
Hi,thank you for sharing the code.
could you upload all_stock_5yr.csv file in you code ,or give a link to get NASDAQ100 history data,thanks
When I run the ddpg_experiments python notebook it turns the following error:
TypeError : cannot interpret feed_dict key as Tensor: Tensor Tensor("CONV2D_3_INPUT:0", SHAPE=(?,17,3,1),dtype=float32) is not an element of this graph.
In the file ddpg_experiments.ipynb you have shown 2 plots of the results in testing_history
, one for imitation, one for ddpg, which is very attractive. For example, ddpg with window 3, cnn, and batch norm achieves 3 fold return.
However, after training it myself using the same code, same model, same config and same data, I fail to replicate the results. The return is always below the market.
TypeError Traceback (most recent call last)
in
1 from model.supervised.cnn import StockCNN
2 # instantiate CNN model
----> 3 cnn_model = StockCNN(env=env)
4 cnn_model.build_model(load_weights=False)
TypeError: init() got an unexpected keyword argument 'env'
I read through your PortfolioEnv code and your DDPG code. It seems to me that the state of your model only incorporates the window of price returns for each asset, and does not incorporate the previous portfolio allocation. This is reflected in how the commission is computed in PortfolioEnv: where you say that dw1 = (y1 * w1) / (np.dot(y1, w1) + eps). Comparing this to the PortfolioEnv implemented by wassname: dw1 = (y1 * w0) / (np.dot(y1, w0) + eps). Can you explain why you calculate the commission in this manner? Much appreciated, thanks.
Why there is no script provided to train the dppg model just like you have provided imitation_learning.py for training imitation learning algorithm?
It would be helpful to replicate the results and experimentations.
Hello, this seems like a nice work.
I have some questions though.
When you're comparing on the test data what does refer the market value?
In your perspective do you think this is a good approach?
I have reviewed the commits in the portfolio.py, why the code of the cost function is altered?
After the change, the function is not correct.
https://github.com/vermouth1992/drl-portfolio-management/commit/1dd6db0ce5cc277e38475beea54eca537a4cf925#
- w0 = self.w0
p0 = self.p0
- dw1 = (y1 * w0) / (np.dot(y1, w0) + eps) # (eq7) weights evolve into
+ dw1 = (y1 * w1) / (np.dot(y1, w1) + eps) # (eq7) weights evolve into
mu1 = self.cost * (np.abs(dw1 - w1)).sum() # (eq16) cost to change portfolio
+ p1 = p0 * (1 - mu1) * np.dot(y1, w0) # (eq11) final portfolio value
- p1 = p0 * (1 - mu1) * np.dot(y1, w1) # (eq11) final portfolio value
p1 = p1 * (1 - self.time_cost) # we can add a cost to holding```
env = PortfolioEnv(history, abbreviation, sample_start_date='2013-08-20')
done = False
while not done:
action = np.array([1.0] + history.shape[0] * [0.0])
observation, reward, done, info = env.step(action)
env.render()
AttributeError: 'DataGenerator' object has no attribute 'step'
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.