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.248139. 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 trinomial tree program to price a up-and-out barrier put. The trinomial tree must match the barrier. 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 there are 365 days in a year;
    • H: up-and-out barrier;
    • n: number of time steps in T, which is an integer.
    Output: The price of the up-and-out barrier put option. For example, if S = 100, X = 110, r = 0.03, s = 0.3, T = 60, H = 120, and n = 100, the output is 11.089643. Input Format (for Python codes, replace your student ID with uppercase): "python3 F08922011_HW_3.py 100 110 0.03 0.3 60 120 100". Output Format: "11.089643". 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 2024 May 10. 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_3.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.
  4. Write a least-squares Monte Carlo program to price an American-style Asian put, and use 1, x, x2 as the basis functions. Note that the put's payoff, when exercised early, uses the running average. Output its price and delta. Inputs:
    • S: stock price, which is a float;
    • X: strike price, which is a float;
    • T: time to maturity in days, which is an integer, and there are 365 days in a year;
    • r: continuously compounded annual interest rate, which is a float;
    • s: annual volatility, which is a float;
    • n: number of time steps in T, which is an integer;
    • N: number of simulation paths, which is an integer.
    Output: (1) Price of the put; (2) Delta of the put (caluclated by S × 1.01 and S × 0.99). For example, if S = 100, X = 100, T = 365, r = 0.05, s = 0.3, n = 100, and N = 10000, the example outputs are 5.483093 and -0.407075. Note that Input Format (for Python codes, replace your student ID with uppercase): "python3 F08922011_HW_4.py 100 100 365 0.05 0.3 100 10000". Output Format: "5.483093, -0.407075". 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 2024 June 7. 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_4.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.

Enrollments