"If the option is in the money, exercise it; otherwise let it expire" is a conditional, and every payoff function this vault ever writes — a call's , a knock-out barrier's zero-if-touched rule — is, at the code level, exactly this construct. This note introduces Python's conditional statement, the mechanics of nested and chained conditionals, and the semantic role of indentation, which is the single biggest surprise for anyone coming from a brace-delimited language. It closes on why conditionals alone are still not enough to write interesting programs — the missing piece, iteration, is the subject of the next lesson but one.
- write a correct
if/elseandif/elif/elseconditional, including nesting; - explain why Python uses indentation to delimit blocks and what changes if a statement is indented one level differently;
- build and read a compound Boolean test using
and,or, and comparison operators; - explain what "runs in constant time" means for a branching program and why that is a genuine limitation.
In this lesson
- The conditional statement
- Chained and nested conditionals
- Compound Boolean tests
- Why conditionals alone are still not enough
Before you start
The full lesson, with worked examples and exercise solutions, is for members.
Read the full lessonNew to SelfMadeQuant.com? See membership options or browse the Python for Quantitative Finance syllabus.