What you will learn
- Types and units
- Functions and modules
- Errors and missing values
- Deterministic transformations
Types and units
Represent prices, quantities, timestamps and identifiers with explicit types and units. A string that looks numeric should not be accepted silently in arithmetic. Financial calculations also need a deliberate decimal or integer-unit policy where rounding affects results.
Functions and modules
Functions should perform bounded transformations with named inputs and outputs. Separate data loading, feature calculation and reporting so each can be inspected independently. A function that both fetches changing data and calculates a result is harder to reproduce.
Errors and missing values
Errors and missing values should have explicit behavior. A failed data request is not an empty but valid market, and a missing multiplier is not zero. Return a clear unavailable state or raise an error before dependent calculations proceed.
Deterministic transformations
Deterministic transformations produce the same output from the same inputs and configuration. Remove hidden dependence on current time, random seeds or mutable global state unless it is explicitly part of the experiment and recorded.
Worked example
A function computes P&L from entry, exit, quantity and multiplier but reads direction from a global variable. Running it after another task changes the global direction and flips the result. Direction belongs in the explicit input contract.
Try it yourself
Write pseudocode for a pure linear-P&L function with validation. Include long/short direction and nonnegative quantity.
Show the worked solution
Validate finite numeric prices and multiplier, positive multiplier, nonnegative quantity and an allowed direction. Return direction-sign × (exit−entry) × quantity × multiplier. Keep fees as an explicit additional input or separate named calculation.
Apply this to your course project
Deliver a small tested pipeline from raw observations to a research report.
Keep the calculation inputs, assumptions and decisions with your work. Practical exercises are self-reviewed; the scored knowledge checks assess the questions shown, not an independent certification of practical competence.