FinTech Homework

Roger Jang


Due date: 2024/11/23 23:59:59

Optimum Trading Strategy with Complete Price Info

Suppose we have only a single stock to trade, and all its prices are known in advance. In this case, we can use dynamic programming (DP) to achieve the best return rate, as explained in the class ( ).

In this homework, we will extend this task to include multiple stocks. In other words, you need to determine the best timing for 'what to buy' and 'what to sell' across different stocks to maximize the overall return. The TA will use a dataset to rank your return rate based on your submissions. Your function, submitted to the judging system, should follow the input/output format below:

actionMat = myAction01(priceMat, transFeeRate);
where

For example, we can demonstrate how everything works by using a simple greedy strategy, as shown below:

To estimate the return rate, we will need two files: To run the main program using the simple greedy approach on 4 stocks over 992 days (stored at priceMat0992.txt), you can enter the following command:
python rrEstimateOpen.py priceMat0992.txt 0.01
The result will look like this:
578094.413707%

Now you need to implement three functions in myAction.py to meet the following requirements:

  1. myAction01(): This function should implement any strategy to optimize the return. While you can use any approach (such as the previously mentioned greedy strategy), a dynamic programming (DP) method is expected to yield the best result.
  2. myAction02(): In this function, you need to optimize the overall return while adhering to the constraint that you must hold cash for at least K days throughout the investment process. For example, if K = 30, you must spend at least 30 days holding cash (without holding any stocks) by the end of each of these days. (The last day counts as one of them.)
  3. myAction03(): This function should optimize the overall return under the constraint that you must hold cash for at least K consecutive days during the investment process. For example, if K = 30, you must have at least 30 consecutive days holding cash (without holding any stocks) at the end of each of those days.
Once you have completed these functions, you can use rrEstimateOpen02.py to test them:
python rrEstimateOpen02.py priceMat0992.txt 0.01
The result will appear like this:
Reading priceMat0992.txt...
------------Problem 1-------------
Time: 0.0
rr=0.000000%
Non continueous cash holding=992
Continueous cash holding=992
------------Problem 2-------------
Time: 0.0
rr=0.000000%
Non continueous cash holding=992
Continueous cash holding=992
------------Problem 3-------------
Time: 0.0
rr=0.000000%
Non continueous cash holding=992
Continueous cash holding=992
Keep in mind that rrEstimateOpen02.py is also the main program used by the TA to evaluate your submission. Make sure to run this program to test your three functions in myAction.py before submitting the file.

Note that:

For submission:

Hints by Roger:

Hints by TA: