LSTM for Function Maximization

landon: <p>I have got a beast of a post here so feel free to answer some, all, or none of my questions…</p>
<p>For background, I have a dataset that looks like this picture:<br>
<div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/8/a/8aaea46aa39a9d5c826c74ae9d9af978e4f1de45.png" data-download-href="https://discuss.pytorch.org/uploads/default/8aaea46aa39a9d5c826c74ae9d9af978e4f1de45" title="image"><img src="https://discuss.pytorch.org/uploads/default/original/3X/8/a/8aaea46aa39a9d5c826c74ae9d9af978e4f1de45.png" alt="image" data-base62-sha1="jMQ3JuuUECEMPDtQY7qpGsGKeGN" width="690" height="256" data-dominant-color="E8E8E8"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">image</span><span class="informations">1202×446 22.9 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div></p>
<p>I am attempting to use an LSTM Neural Network to optimize Sharpe ratio by messing with portfolio allocations.</p>
<ol>
<li>I am using a batch size of 8, sequence length of 16, and have 16 features as shown above. As of right now I have a tensor of size [8, 16, 16] where it is 16 groups of 8 consecutive time periods. From my understanding it takes 8 months and makes an array out of that then stacks 16 of those on top of each other.</li>
</ol>
<p>I am wondering if this seems logical to everyone as a way to format my data. It seems almost too simple.</p>
<ol start="2">
<li>
<p>I am having difficulty with the forward function. I have tried quite a few things, so I wish I could attach more images. My goal is to have it output 8 values (maybe in a 1x8 tensor), those being the allocations for each asset class, however, I am struggling with making this happen. Wondering if anyone has any input on the appropriate way to make this happen. As of right now I’m getting very weird shape tensors back.</p>
</li>
<li>
<p>Once I get the data and forward working, I can move on to the Loss Function. I am very confused about how to make this happen. Once I have the allocations I need to calculate what Sharpe that would have given over the period, however, it needs to all be done in a tensor form. Any pointers on making custom loss functions in general?</p>
</li>
</ol>

landon: <p>It did not let me attach more than one picture so I will do that here:</p>
<p>For question 2, here is my code:<br>
<div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/d/4/d43005bfcce322584d3f3f8a2fb50a212d1fbf83.png" data-download-href="https://discuss.pytorch.org/uploads/default/d43005bfcce322584d3f3f8a2fb50a212d1fbf83" title="image"><img src="https://discuss.pytorch.org/uploads/default/original/3X/d/4/d43005bfcce322584d3f3f8a2fb50a212d1fbf83.png" alt="image" data-base62-sha1="uh66U8bNVScANpZ3nCm3Z3yqIh5" width="501" height="500" data-dominant-color="222424"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">image</span><span class="informations">763×760 28.7 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div></p>

landon: <p>For question 1, here is my code:<br>
<img src="https://discuss.pytorch.org/uploads/default/original/3X/3/c/3cb934a4db610c47e07a7d00d0def23a32009296.png" alt="image" data-base62-sha1="8FbrRO4YJB2VfYCELW98asKbXSe" width="684" height="382"></p>