# HW02: Trading strategies using technical indicators ## Instructional Video https://www.youtube.com/watch?v=i1DisY9ARzA ## Goal In this assignment, you are required to design a stock trading strategy using the technical indicators (TIs) covered in class. You will then upload your strategy to Gradescope to compete with your classmates. We will provide a public dataset for your testing. The final score will be calculated as the average of your performance on both the public dataset and a private dataset (i.e., (public_score + private_score) / 2). ## File List - [bestParamByExhaustiveSearch.py](https://drive.google.com/file/d/1cZtPDp2PqikOufNOiSdkt27waiQOXgaQ/view?usp=sharing) - [myStrategy.py](https://drive.google.com/file/d/1IgAzWFLXEkAlFhsO96vW8rVn9W2w3ptk/view?usp=sharing) - [readme.txt](https://drive.google.com/file/d/1ZcOidMT7GPntVo5fxv9kGC7SK72Kj-sz/view?usp=sharing) - [rrEstimate.py](https://drive.google.com/file/d/1gXsH3Dkxwq6yxVE5Iy0cT-BiIJt71WG4/view?usp=sharing) - [public.csv](https://drive.google.com/file/d/1McOubLdeKfRIQoDoUEDzOa5qAFGC5C6a/view?usp=sharing) ## Design Flow Example 1. Choose the technical indicator(s) you want to use (or design your own). 2. Define the trading strategy based on these indicators, including modifiable parameters for optimization. 3. Optimize the parameters using historical price data. 4. Apply the optimized parameters to evaluate performance over a longer period. **Example:** In the sample code `bestParamByExhaustiveSearch.py`, we maximize the return rate on *public.csv* via exhaustive search: ```bash python bestParamByExhaustiveSearch.py public.csv ``` After a while, the best settings with maximum return rate will be found: ``` Best settings: fast_period=8, slow_period=24, signal_period=9 ==> returnRate=0.007356 ``` Then you can put these best parameters into the program myStrategy.py , and try the trading strategy on the same dataset by typing ``` python rrEstimate.py public.csv ``` You should see: ``` rr=0.735616% ``` ## Notes - Your trading strategy can only use historical prices available up to the current day to make buy/sell decisions. - You only need to submit the function myStrategy.py - Only technical indicators are allowed. Machine learning, DP, or other methods are not permitted. (Gradescope does not provide GPU resources.) - Each call to myStrategy() must finish within 0.01 sec, otherwise it will be terminated and the default output will be 0. - Scoring is based on the average of your return rates on both public and private datasets (each approximately 2,400 days). - The results for the public dataset will be displayed immediately, while the results for the private dataset will be announced after the assignment deadline. - The last submission on Gradescope before the deadline will be used for grading. - On Gradescope, the only available packages are: - pandas==2.2.2 - numpy==2.1.1 - scipy==1.14.1 - statsmodels==0.14.2 ## FAQ