Module 3 · Data, Variables, Samples, and Measurement Lesson 29 of 120
Revisions, Vintages, and Point-in-Time Availability
Backtesting with the version that actually existed.
Transcript
20 sentences · select one to jump thereCheck your understanding
Which value belongs in the time-three replay?
Code lab
Run it yourself
The lesson source in 7 languages. Edit it, run TypeScript and Python right here, and compare with the expected output.
/**
* Fintech Math Bootcamp · Lesson 029 of 120
* Revisions, Vintages, and Point-in-Time Availability
* Module 03: Data, Variables, Samples, and Measurement
*
* Scenario: Backtesting with the version that actually existed
* Rule: availableAt ≤ decisionTime
*
* Try it: Which value belongs in the time-three replay?
*
* Lesson article: https://thefintechbuilder.com/financial-mathematics-statistics-and-data-foundations/data-variables-samples-and-measurement/revisions-vintages-and-point-in-time-availability/
* Free course: https://courses.thefintechbuilder.com
* Synthetic teaching example, not financial advice or a production library.
*/
export function lesson029() {
const versions = [
{value: 110, availableAt: 5},
{value: 100, availableAt: 1}
];
const decisionTime = 3;
const eligible = versions.filter(v => v.availableAt <= decisionTime);
const latest = eligible.reduce<typeof versions[number] | null>(
(best, v) => best === null || v.availableAt > best.availableAt ? v : best, null);
const result = latest?.value ?? null;
return result;
}
export const checkedResult = 100;
// Run this file directly: npx tsx lessons/03-data-variables-samples-and-measurement/029-revisions-vintages-and-point-in-time-availability.ts
if (process.argv[1] && import.meta.url.endsWith(process.argv[1].replace(/\\/g, "/").split("/").pop()!)) {
console.log(JSON.stringify(lesson029(), null, 2));
}
Your output
Press Run to execute the code in your browser.
Expected output
100"""
Fintech Math Bootcamp · Lesson 029 of 120
Revisions, Vintages, and Point-in-Time Availability
Module 03: Data, Variables, Samples, and Measurement
Scenario: Backtesting with the version that actually existed
Rule: availableAt ≤ decisionTime
Try it: Which value belongs in the time-three replay?
Lesson article: https://thefintechbuilder.com/financial-mathematics-statistics-and-data-foundations/data-variables-samples-and-measurement/revisions-vintages-and-point-in-time-availability/
Free course: https://courses.thefintechbuilder.com
Synthetic teaching example, not financial advice or a production library.
Run it: python main.py
"""
import json
def lesson029() -> float | None:
versions = [
{"value": 110, "available_at": 5},
{"value": 100, "available_at": 1},
]
decision_time = 3
eligible = [v for v in versions if v["available_at"] <= decision_time]
latest = None
for v in eligible:
if latest is None or v["available_at"] > latest["available_at"]:
latest = v
result = latest["value"] if latest is not None else None
return result
if __name__ == "__main__":
print(json.dumps(lesson029(), indent=2))
Your output
Press Run to execute the code in your browser.
Expected output
100/**
* Fintech Math Bootcamp · Lesson 029 of 120
* Revisions, Vintages, and Point-in-Time Availability
* Module 03: Data, Variables, Samples, and Measurement
*
* Scenario: Backtesting with the version that actually existed
* Rule: availableAt ≤ decisionTime
*
* Try it: Which value belongs in the time-three replay?
*
* Lesson article: https://thefintechbuilder.com/financial-mathematics-statistics-and-data-foundations/data-variables-samples-and-measurement/revisions-vintages-and-point-in-time-availability/
* Free course: https://courses.thefintechbuilder.com
* Synthetic teaching example, not financial advice or a production library.
*
* Run it: javac Main.java && java Main
*/
import java.util.ArrayList;
import java.util.List;
public class Main {
static final class Version {
final double value;
final double availableAt;
Version(double value, double availableAt) {
this.value = value;
this.availableAt = availableAt;
}
}
// Returns null when no version was available at the decision time.
static Double lesson029() {
Version[] versions = {
new Version(110, 5),
new Version(100, 1)
};
double decisionTime = 3;
List<Version> eligible = new ArrayList<Version>();
for (Version v : versions) {
if (v.availableAt <= decisionTime) eligible.add(v);
}
Version latest = null;
for (Version v : eligible) {
if (latest == null || v.availableAt > latest.availableAt) latest = v;
}
Double result = latest == null ? null : Double.valueOf(latest.value);
return result;
}
public static void main(String[] args) {
Double result = lesson029();
System.out.println(result == null ? "null" : num(result));
}
// Formats a double the way JSON.stringify does: whole numbers without ".0", null for NaN or infinity.
static String num(double x) {
if (Double.isNaN(x) || Double.isInfinite(x)) return "null";
if (x == Math.rint(x) && Math.abs(x) < 1e15) return String.valueOf((long) x);
return String.valueOf(x);
}
}
No browser runner for Java yet
Read the code here, then run it in your own toolchain or a ready-made cloud workspace.
Expected output
100// Fintech Math Bootcamp · Lesson 029 of 120
// Revisions, Vintages, and Point-in-Time Availability
// Module 03: Data, Variables, Samples, and Measurement
//
// Scenario: Backtesting with the version that actually existed
// Rule: availableAt ≤ decisionTime
//
// Try it: Which value belongs in the time-three replay?
//
// Lesson article: https://thefintechbuilder.com/financial-mathematics-statistics-and-data-foundations/data-variables-samples-and-measurement/revisions-vintages-and-point-in-time-availability/
// Free course: https://courses.thefintechbuilder.com
// Synthetic teaching example, not financial advice or a production library.
//
// Run it: go run main.go
package main
import (
"encoding/json"
"fmt"
)
type Version struct {
Value float64
AvailableAt float64
}
// lesson029 returns nil when no version was available at the decision time.
func lesson029() *float64 {
versions := []Version{
{Value: 110, AvailableAt: 5},
{Value: 100, AvailableAt: 1},
}
decisionTime := 3.0
var eligible []Version
for _, v := range versions {
if v.AvailableAt <= decisionTime {
eligible = append(eligible, v)
}
}
var latest *Version
for i := range eligible {
if latest == nil || eligible[i].AvailableAt > latest.AvailableAt {
latest = &eligible[i]
}
}
if latest == nil {
return nil
}
result := latest.Value
return &result
}
func main() {
printJSON(lesson029())
}
// printJSON prints a value as JSON indented with two spaces, like JSON.stringify(value, null, 2).
func printJSON(value any) {
out, err := json.MarshalIndent(value, "", " ")
if err != nil {
panic(err)
}
fmt.Println(string(out))
}
No browser runner for Go yet
Read the code here, then run it in your own toolchain or a ready-made cloud workspace.
Expected output
100/**
* Fintech Math Bootcamp · Lesson 029 of 120
* Revisions, Vintages, and Point-in-Time Availability
* Module 03: Data, Variables, Samples, and Measurement
*
* Scenario: Backtesting with the version that actually existed
* Rule: availableAt ≤ decisionTime
*
* Try it: Which value belongs in the time-three replay?
*
* Lesson article: https://thefintechbuilder.com/financial-mathematics-statistics-and-data-foundations/data-variables-samples-and-measurement/revisions-vintages-and-point-in-time-availability/
* Free course: https://courses.thefintechbuilder.com
* Synthetic teaching example, not financial advice or a production library.
*
* Run it: g++ -std=c++17 -o main main.cpp && ./main
*/
#include <charconv>
#include <cmath>
#include <iostream>
#include <optional>
#include <string>
#include <vector>
// Formats a double the way JSON.stringify does: shortest round-trip form, null for NaN or infinity.
std::string num(double x) {
if (!std::isfinite(x)) return "null";
char buffer[32];
auto [end, error] = std::to_chars(buffer, buffer + sizeof buffer, x);
(void)error;
return std::string(buffer, end);
}
struct Version {
double value;
double availableAt;
};
// Returns an empty optional when no version was available at the decision time.
std::optional<double> lesson029() {
const std::vector<Version> versions{
{110, 5},
{100, 1}
};
const double decisionTime = 3;
std::vector<Version> eligible;
for (const Version& v : versions) {
if (v.availableAt <= decisionTime) eligible.push_back(v);
}
const Version* latest = nullptr;
for (const Version& v : eligible) {
if (latest == nullptr || v.availableAt > latest->availableAt) latest = &v;
}
const std::optional<double> result =
latest == nullptr ? std::nullopt : std::optional<double>(latest->value);
return result;
}
int main() {
const std::optional<double> result = lesson029();
std::cout << (result ? num(*result) : "null") << "\n";
}
No browser runner for C++ yet
Read the code here, then run it in your own toolchain or a ready-made cloud workspace.
Expected output
100//! Fintech Math Bootcamp · Lesson 029 of 120
//! Revisions, Vintages, and Point-in-Time Availability
//! Module 03: Data, Variables, Samples, and Measurement
//!
//! Scenario: Backtesting with the version that actually existed
//! Rule: availableAt ≤ decisionTime
//!
//! Try it: Which value belongs in the time-three replay?
//!
//! Lesson article: https://thefintechbuilder.com/financial-mathematics-statistics-and-data-foundations/data-variables-samples-and-measurement/revisions-vintages-and-point-in-time-availability/
//! Free course: https://courses.thefintechbuilder.com
//! Synthetic teaching example, not financial advice or a production library.
//!
//! Run it: rustc main.rs && ./main
struct Version {
value: f64,
available_at: f64,
}
/// Returns None when no version was available at the decision time.
fn lesson029() -> Option<f64> {
let versions = [
Version { value: 110.0, available_at: 5.0 },
Version { value: 100.0, available_at: 1.0 },
];
let decision_time = 3.0;
let eligible: Vec<&Version> = versions.iter().filter(|v| v.available_at <= decision_time).collect();
let latest = eligible.iter().fold(None::<&Version>, |best, &v| match best {
Some(b) if v.available_at <= b.available_at => Some(b),
_ => Some(v),
});
let result = latest.map(|v| v.value);
result
}
fn main() {
match lesson029() {
Some(value) => println!("{}", num(value)),
None => println!("null"),
}
}
/// Formats a number the way JSON.stringify does: shortest round-trip form, null for NaN or infinity.
fn num(x: f64) -> String {
if x.is_finite() {
format!("{}", x)
} else {
"null".to_string()
}
}
No browser runner for Rust yet
Read the code here, then run it in your own toolchain or a ready-made cloud workspace.
Expected output
100/**
* Fintech Math Bootcamp · Lesson 029 of 120
* Revisions, Vintages, and Point-in-Time Availability
* Module 03: Data, Variables, Samples, and Measurement
*
* Scenario: Backtesting with the version that actually existed
* Rule: availableAt ≤ decisionTime
*
* Try it: Which value belongs in the time-three replay?
*
* Lesson article: https://thefintechbuilder.com/financial-mathematics-statistics-and-data-foundations/data-variables-samples-and-measurement/revisions-vintages-and-point-in-time-availability/
* Free course: https://courses.thefintechbuilder.com
* Synthetic teaching example, not financial advice or a production library.
*
* Run it: dotnet run (inside a console project that holds this Program.cs)
*/
using System.Text.Json;
Console.WriteLine(JsonSerializer.Serialize(Lesson029()));
// Returns null when no version was available at the decision time.
static double? Lesson029()
{
var versions = new[]
{
new Version(110, 5),
new Version(100, 1),
};
const double decisionTime = 3;
var eligible = versions.Where(v => v.AvailableAt <= decisionTime);
var latest = eligible.Aggregate((Version?)null,
(best, v) => best is null || v.AvailableAt > best.AvailableAt ? v : best);
double? result = latest?.Value;
return result;
}
record Version(double Value, double AvailableAt);
No browser runner for C# yet
Read the code here, then run it in your own toolchain or a ready-made cloud workspace.
Expected output
100Prefer your own machine? Every file is in the course repository · open it in Codespaces.
Lesson notes
The rule
availableAt ≤ decisionTime