Exercise · m14_prospect.py
Prospect theory value and weighting functions; the disposition effect
not run yet
Not saved: sign up to keep your code"""M14 · Prospect theory value and weighting functions; the disposition effect.
Exercise stubs. See notes.md §14.9.1–§14.9.2. Defaults are Tversky-Kahneman (1992) medians.
"""
from __future__ import annotations
def pt_value(x, alpha: float = 0.88, beta: float = 0.88, lam: float = 2.25):
"""v(x) = x^alpha for x >= 0 and -lam (-x)^beta for x < 0. Accept scalars or arrays
(return a numpy array / numpy scalar)."""
raise NotImplementedError
def tk_weight(p, gamma: float = 0.61):
"""Probability weighting w(p) = p^gamma / (p^gamma + (1-p)^gamma)^(1/gamma)."""
raise NotImplementedError
def hold_minus_sell(paper_pnl: float, h: float, p_up: float = 0.5, **kw) -> float:
"""PT value of holding minus PT value of selling now.
hold = p_up v(paper_pnl + h) + (1 - p_up) v(paper_pnl - h); sell = v(paper_pnl).
Extra keyword arguments (alpha, beta, lam) pass through to pt_value. Return a float.
"""
raise NotImplementedError
No runs yet
The stub's functions raise
NotImplementedError until you write them. Fill in one, press
Run tests, and watch its tests turn green.Reference solution
Available after your first run, with an account approved for code runs.