TAYU Academy course material · Machine Learning for Trading
Text walkthrough
LSTM basics
A self-paced text walkthrough, without video or audio. See the article below for worked examples and materials.
Course Notes
1. Understand the core idea of “LSTM basics” and explain it in your own words
2. Master this module's focus: LSTM experiment
3. Complete the assignment on your own and check it against the reference answer
LSTM takes sequential inputs and hidden states to represent historical data. Tensors are typically of the form sample × time × features, but the framework specifies this clearly; shuffling training samples does not equal allowing random mixing of time tests.
LSTM is suitable for handling sequential data, with an input shape generally of (number of samples, time steps, feature number). Financial data is noisy and has a small number of samples, making deep models prone to overfitting. It should be compared with simple baseline models (such as logistic regression or random guessing).
For example, if the out-of-sample performance of a 30-step LSTM trained with 5 features does not outperform logistic regression, there is no reason to adopt a more complex model.
Check batch_first → build 20-step windows within each segment → fit the scaling on the training segment → input 3 features / hidden 8 → run 8 epochs and record shapes and losses.
What do the dimensions of the accompanying training input 139×20×3 represent? Can the test window include future labels that have not been confirmed after training?
139 samples, 20 time steps, 3 features; future labels not to be mixed. Training and testing should use independent windows, and purging should not be bypassed to increase sample boundaries.
Assuming 32 samples, each with 20 steps, and 3 features per step, the shape is (32, 20, 3); hidden dimension is 8, and a single-layer output is (32, 20, 8), resulting in (32, 8) for the final moment, followed by a classification head outputting 32 logits. Labels cannot mimic future directions within a window by pretending to be the last known direction.
A good fit on a synthetic series is not price-forecasting ability; never use final test results to choose network size.
Install the dependencies listed for this lab in the README first. If a dependency or platform is unavailable, mark the lab as not run; downloading the source is not evidence of running it.
python lstm_lab.py1. Mind the input shape
2. Compare against a simple baseline model
3. More complex is not better
Risk warning: leveraged trading in forex, precious metals and similar products carries a high level of risk and you may lose all of your capital, or more. This course is for education only. It is not investment advice and does not promise any return. Example prices and contract specifications are teaching assumptions; always use what your own platform discloses. Past performance and backtests do not indicate future results.
All values, prices, accounts and cases in this course are teaching assumptions; the fixed materials can be reproduced offline. Marking a lesson complete only records your study. It is not a certification, a service approval or a promise of returns. Workbooks and answer files are currently provided in Chinese.
Key Takeaways
Completion records your own study, not verified competence. Exercises use fictional data; no real account or deposit is required.