TAYU Academy course material · Python Quant Trading Lab
Course Notes
1. Understand the core idea of “Data cleaning exercise” 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
Data cleaning is not about making every row pass; it is about explicitly isolating inputs that cannot be explained. Repetitive time, bad OHLC, missing or non-finite numerical values should be separately counted and not silently deleted, claiming no anomalies.
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.
Download dirty CSV → retain original backup → run cleaning → validate valid/repeat/isolated → examine anomaly causes → save cleaned hash and feature table.
Reproduce the rows marked as "240 effective", "1 repeat", and "3 isolate". Explain why it is not permissible to retain the last row if there are differences between two rows of content at the same time.
Conflict resolution should be based on the source and version, and should isolate rather than arbitrarily override. Counting should cover each input. Filling in future prices with zeros or backfilling creates a market and should not be used as a fix.
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.
Data cleaning is not about making every row pass; it is about explicitly isolating inputs that cannot be explained. Repetitive time, bad OHLC, missing or non-finite numerical values should be separately counted and not silently deleted, claiming no anomalies.
Record your work and compare the reference result. Self-checks are not verified competence.
Completion records your own study, not verified competence. Exercises use fictional data; no real account or deposit is required.