# The Martingale Index: A Measure of Self-Deception in Betting and Finance

This repository contains the code to replicate the results presented in the paper **"The Martingale Index: A Measure of Self-Deception in Betting and Finance"**, which is being published by *Judgement and Decision Making*. 
The code is implemented in Python using Jupyter Notebooks.

## Repository Structure

- **Section3.ipynb** 	– Contains the code for Section 3 	- **Does not require input data**
- **Section4.1.ipynb** 	– Contains the code for Section 4.1 	- **Data from SPFuturesReady.xlsx**
- **Section4.2.ipynb** 	– Contains the code for Section 4.2 	- **Data from SP500DataReady.csv**
- **Section4.3.ipynb** 	– Contains the code for Section 4.3	- **VIX data refinitiv_sas.xlsx**

## Prerequisites

- **Python 3.x** (tested with Python 3.8+)
- **Jupyter Notebook** or **JupyterLab**
- Required libraries (install via `pip`):
  - `numpy`
  - `pandas`
  - 'random'
  - 'seaborn'
  - `matplotlib`

## Variable definitions for SPFuturesReady.xlsx

- Date: calendar date of the observation
- RET: return on the S&P 500 E-mini futures from open to settlement. Defined in the paper as ret = 100(S−O)/O; S: settlement price of the S&P 500 E-mini futures; O: opening price of the S&P 500 E-mini futures
- Drawshort: maximum percentage rise in the S&P 500 E-mini futures from the opening futures price. Defined in the paper as rise = 100(H−O)/O; O: opening price of the S&P 500 E-mini futures; H: the highest price of the S&P 500 E-mini futures for the day.  
- Drawlong: maximum percentage drop in the S&P 500 E-mini futures from the opening futures price. Defined in the paper as drop = 100(O−L)/O; O: opening price of the S&P 500 E-mini futures; L: the lowest price of the S&P 500 E-mini futures for the day. 

## Variable definitions for SP500DataReady.csv

- PERMNO: company identified (stock i)
- DATE: calendar date of the observation (day n)
- RET: daily return (i,n
- Mvend: market value of equity at the end of day n for stock i.
- Mvbeg: market value of equity at the start of day n for stock i.
- Spnobs: number of firms with data on day n.
- Spmvbeg: the total market value of equity for all stocks at the start of day n.
- Spmvend: the total market value of equity for all stocks at the end of day n.
- Spvwret: value-weighted average return on all stocks on day n.
- rbeg: corresponds to p(i,n)
- rend: corresponds to p’(i,n)
- rret: rend/rbeg - 1; daily return (i,n) based on SP500 units.

## Variable definitions for VIX data refinitiv_sas.xlsx

- Date: calendar date of the observation
- Open: opening value of the VIX index
- High: the highest value of the VIX index
- Low: the lowest value of the VIX index
- Close: the closing value of the VIX index
- PRCC:  100(Close-Open)/Open
- %RISE: 100(High-Open)/Open 
- %DROP: 100(Low-Open)/Open