Principles of Financial Computing Course

Principles of Financial Computing

Time: 9:10 ~ 12:10 Friday (Spring Semester)
Location: Room 111 of the CSIE Building


On Wall Street, being right on the fundamentals and
wrong on the timing is the same as just being wrong.
---Jonathan Cohen

Where is the risk management at J.P. Morgan Chase?
--- Bloomberg News, January 16, 2002

10. Of course, I make a lot investing.
I only teach so I can help young people.
--- Top Ten Lies Finance Professors Tell Their Students



To Students,

You will learn a perhaps different perspective on finance, especially as it pertains to pricing and software engineering. Our emphasis on computation should add a new dimension and toolbox to your existing knowledge and financial sense. (But see Enrollments below.)
It is your responsibility to learn to write in high-level programming languages. We cannot impart that skill in the class. If the mathematics proves hard going, you are expected to fill in the gap by self-reading. The technicalities are not beyond a motivated graduate student's reach.


The major topics covered in the course, time permitting, are listed below for your reference.


Notes [ 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022, 2023, 2024 ]

  1. 2024.02.23
  2. 2024.03.01
  3. 2024.03.08
  4. 2024.03.15
  5. 2024.03.22 & 1st assignment due
  6. 2024.03.29
  7. 2025.04.05 holiday
  8. 2024.04.12
  9. 2024.04.19 & 2nd assignment due
  10. 2024.04.26
  11. 2024.05.03
  12. 2024.05.10 & 3rd assignment due
  13. 2024.05.17
  14. 2024.05.24
  15. 2024.05.31
  16. 2024.06.07 & 4th assignment due

Programming Exercises

Homework should be turned in on time. No late homework will be accepted without legitimate reasons. There will be four to six programming assignments.
Treat each homework as an examination.
  1. Write a program for loan amortization swapping. Consider an n1-year, V-dollar loan at an r1 interest rate. At the end of year n2 (n2 < n1), however, there is an opportunity to swap the loan (i.e., the remaining principal) into a new loan with an r2 interest rate for the remaining n1-n2 years, of course under a new amortization. An F-dollar fee is charged at the end of year n2 if the loan is swapped. Both loans have the same number of payments per annum, m. Inputs:
    • V: original loan amount in dollars;
    • m: number of payments per annum, an integer;
    • n1: duration of the original loan in years, an integer;
    • r1: annual interest rate of the original loan, compounded m times per annum;
    • n2: the year that loan swapping is possible;
    • r2: annual interest rate of the new loan, also compounded m times per annum;
    • F: swapping fee.
    Outputs:
    • total principal paid in the first n2 years;
    • total interest paid in the first n2 years;
    • total interest paid from the end of year n2 (excluded) to the end of year n1 if the loan is not swapped (so the r1 interest rate is maintained);
    • total interest paid from the end of year n2 (excluded) to the end of year n1 if the loan is swapped to the new r2 interest rate;
    • the IRR for the whole n1 years (the fee F considered) if the loan is swapped;
    • does swapping the loan lower the IRR? Answer 1 for yes, 0 for no difference, and -1 for no.
    For example, if V = 1000000, m = 12, n1 = 2, r1 = 0.060, n2 = 1, r2 = 0.025, F = 888, the outputs are 485041.840313, 46805.482720, 16889.163346, 6999.998244, 0.051895, 1. Input format (for Python codes): "python3 F08922011_HW_1.py 1000000 12 2 0.060 1 0.025 888". Output format: "485041.840313, 46805.482720, 16889.163346, 6999.998244, 0.051895, 1". Please send your source (and executable) code and a brief explanation txt file (if the code is not written in Python, describe how to run it) using NTU COOL before 08:00 AM of March 22, 2024. No late submissions will be accepted. Compress all files into a single zip file, and name it ID_HW_i.zip, where ID is your student ID in uppercase and i is the number of the homework (example: F08922011_HW_1.zip). If the code is not written in Python, you may be asked to demonstrate your code to TA 許家豪 and you still have to submit the files before the deadline.
  2. Write a binomial tree program to price Bermudan put options, where early exercise is only allowed on specific dates. Inputs:
    • S: stock price;
    • X: strike price;
    • r: continuously compounded annual interest rate;
    • s: annual volatility;
    • T: time to maturity in days, which is an integer and also an exercise date;
    • m: number of periods per day for the tree, an integer;
    • E: early exercise dates from now, a list of integers.
    Output: The price of the Bermudan put option. For example, if S = 100, X = 110, r = 0.03, s = 0.3, T = 60, m = 5, and E = [10, 20, 30, 40, 50], the output is 11.248657. Input format (for Python codes, replace your student ID with uppercase): "python3 F08922011_HW_2.py 100 110 0.03 0.3 60 5 10 20 30 40 50". Output format: "11.248657". Please send your source (and executable) code and a brief explanation txt file (if the code is not written in Python, describe how to run it) using NTU COOL before 08:00 AM (GMT+8) 2024 April 19. No late submissions will be accepted. Compress all files into a single zip file, and name it ID_HW_i.zip, where ID is your student ID in uppercase and i is the number of the homework (example: F08922011_HW_2.zip). If the code is not written in Python, you may be asked to demonstrate your code to TA 許家豪 and you still have to submit the files before the deadline.
  3. Write a program to generate an amortization schedule for repaying a loan. There are two interest rates. Inputs: (1) L (loan amount in dollars), (2) r1 (annual interest rate in percent for the first n1 periods, so 12 instead of 0.12), (3) r2 (annual interest rate in percent for the remaining periods), (4) n1 (number of periods when the interest rate is r1), (5) n (duration of the loan in years), and (6) m (the number of payments per annum). Output: A csv file for the amortization schedule and the total interest paid. The schedule shall have five columns: (1) Time (0, 1, 2, ...), (2) The level payment amount, (3) Interest (the interest part of each payment), (4) Principal (the principal part of each payment), and (5) Remaining principal. For example, if L = 10,000,000, r1 = 8%, r2 = 3%, n1 = 120, n = 20, and m = 12, the example output file is here and the total interest is 8593339.37. IMPORTANT notes: (1) The Time column must be integers (no floating-point numbers). (2) The Payment, Interest, Principal, and Remaining principal columns must be floating-point numbers up to 2 decimal points. (3) The order of the columns must be respected. (4) The headers of the columns must be as in the sample file. (5) Start from Time 0 instead of Time 1. This means the value of the first row will be 0, 0, 0, 0, L. Please send your source code, executable code, and a brief explanation file if necessary (e.g., how to run it?) using NTU COOL before 08:00 AM of March 17, 2023. No late submissions will be accepted. Compress your files into a single file and name it StudentID_HW_1 for easy reference. Example: R91922054_HW_1. If Python is not your programming language please demonstrate your code to 盧與明 during the office hour or make an appointment with him to do so. (You still have to submit the files before the deadline.)
  4. Write a binomial tree program to price a Bermudan option. The early exercise time points are T/4 and 3T/4 from now, where T is the time to maturity. The payoff function is max(K - S + 1,0). Inputs: (1) S (stock price), (2) K (strike price), (3) r (annual interest rate continuously compounded), (4) s (annual volatility), (5) T (time to maturity in years), (6) n (number of time steps). Output: Option price. For example, suppose that S = 100, K = 100, r = 5 (%), s = 30 (%), and T = 0.5 (years). The option price is about 7.8052 at n = 100 and 7.8015 at n = 200. IMPORTANT NOTES: (1) The interest rate and volatility should be in percent. For example, if the interest rate is 5% and volatility 30%, the inputs are 5 and 30, respectively. (2) No need to make sure the early exercise dates are aligned with time steps of the tree. Please send your source code, executable code, and a brief explanation file if necessary (e.g., how to run it?) using NTU COOL before 08:00 AM of April 14, 2022. No late submissions will be accepted. Compress your files into a single file and name it StudentID_HW_2 for easy reference. Example: R91922054_HW_2. If Python is not your programming language, please demonstrate your code to 盧與明 during the office hour or make an appointment with him to do so. (You still have to submit the files before the deadline.)
  5. Write a trinomial tree program to price a down-and-out barrier call. Inputs: (1) S (stock price), (2) K (strike price), (3) r (interest rate), (4) s (annual volatility), (5) T (time to maturity in years), (6) H (barrier), and (7) n (number of time steps). Output: Option price. For example, suppose that S = 95, K = 100, r = 10 (%), s = 25 (%), H = 90, and T = 1. The option price is about 5.9899 at n = 75 and 5.9977 at n = 400. IMPORTANT notes: (1) The interest rate and volatility should be in percent. For example, if the interest rate is 5% and volatility 30%, the inputs are 5 and 30, respectively. (2) The trinomial tree must matches the barrier. Please send your source code, executable code, and a brief explanation file if necessary (e.g., how to run it?) using NTU COOL before 08:00 AM of May 12, 2022. No late submissions will be accepted. Compress your files into a single file and name it StudentID_HW_3 for easy reference. Example: R91922054_HW_3. If Python is not your programming language, please demonstrate your code to 盧與明 during the office hour or make an appointment with him to do so. (You still have to submit the files before the deadline.)
  6. Implement the Least Square Monte Carlo method to price an American option. Use 1, x, x2, x3 as the basis functions. (1) S (stock price), (2) K (strike price), (3) r (interest rate), (4) s (volatility), (5) T (time to maturity in years), (6) n (number of time steps), (7) N (number of simulation paths). Output: Option price and the standand error. IMPORTANT notes: (1) The interest rate and volatility should be in percent. For example, if the interest rate is 1% and volatility 10%, the inputs are 1 and 10, respectively. Please send your source code, executable code, and a brief explanation file if necessary (e.g., how to run it?) using NTU COOL before 08:00 AM of June 9, 2022. No late submissions will be accepted. Compress your files into a single file and name it StudentID_HW_4 for easy reference. Example: R91922054_HW_4. If Python is not your programming language, please demonstrate your code to 盧與明 during the office hour or make an appointment with him to do so. (You still have to submit the files before the deadline.)

Enrollments