TAYU Academy course material · Python Quant Trading Lab
Course Notes
1. Understand the core idea of “OHLCV feature engineering” and explain it in your own words
2. Master this module's focus: Processing financial data with Pandas
3. Complete the assignment on your own and check it against the reference answer
OHLCV features should correspond to decision points. Yield, rolling mean, and volatility should use data up to the current time. Future returns can be used as labels, but they should not be conflated with features.
Core Steps: Read CSV, parse time to UTC, unify, remove duplicates, check for missing and anomalous values, calculate returns, then resample to a higher frequency. Time series calculations should avoid using future data; for example, use rolling with past data only.
Example: df['ret'] = df['close'].pct_change() to calculate returns; df.resample('1h').agg({'open': 'first', 'high': 'max', 'low': 'min', 'close': 'last'}) to resample minute data into hourly data.
First clean the data → calculate `close.pct_change` → use rolling window → set available time window → split features from labels → detect future dependence using prefix invariance.
Close values are 100, 102, and 101. Calculate the effective gains for both. Explain why shifting (-1) the observation feature is dangerous.
2% and approximately -0.980392%; `shift(-1)` moves the future row to the current, which can be used for post-event labeling but cannot be used as a known feature at the time. Decimal gains and percentages should be distinguished.
Closing synthetic prices of 100, 102, and 101 correspond to missing gains of -0.00980392 and 0.02, respectively. If you copy the row of 101 and then calculate, you must first remove duplicates. SMA2 is in the second row of 101 and the third row of 101.5. Extra lagging is only required when the signal point is earlier than the calculation data; not all rolling calculations require a mechanical shift.
`df.shift(-1)` can be used for post-event labeling but cannot be used as a feature; do not fill in the first missing profit with a valid training sample.
Download the companion files into one folder, install the dependencies listed in the README, then run. The full script also prints a cleaning report and OHLC resampling; the snippet below uses real pandas APIs.
import pandas as pd
df = pd.read_csv('ohlcv-synthetic.csv')
df['timestamp'] = pd.to_datetime(df['timestamp'], utc=True)
df = df.sort_values('timestamp').drop_duplicates('timestamp')
df = df.set_index('timestamp')
df['return'] = df['close'].pct_change(fill_method=None)
df['sma_3'] = df['close'].rolling(3, min_periods=3).mean()
print(df[['close', 'return', 'sma_3']].head(8))1. Unify time zones and remove duplicates
2. Check data quality first
3. Avoid look-ahead bias
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.