
Python for Finance

It could be viewed as a great achievement when a new Python learner could write his/her own financial calculator. The basic knowledge to do so includes the following:
For the latter, we have learnt from the preceding sections, such as the formula to calculate the present value of one future cash flow. Let's write the simplest Python function to double an input value:
def dd(x): return 2*x
Here, def
is the keyword for writing a function, dd
is the function name, and x
in the parentheses is an input variable. For Python, the indentation is critical. The preceding indentation indicates that the second line is the part of the dd
function. Calling this function is the same as calling other built-in Python functions:
>>>dd(5) 10 >>>dd(3.42) 6.84
Now, let's write our simplest financial calculator. First, launch Python and use its editor to enter...
Change the font size
Change margin width
Change background colour