# 003. Product credit exposure

**Question:** Which product codes have the largest credited value relative to invoiced sales?

## Result

The largest computed metric is 17.1 for AMAZONFEE; the smallest is 0 for B. Metric: credit_to_gross (Ratio).

Ratios compare period credits to period gross value; credits may relate to earlier sales.

![Product credit exposure](outputs/chart.png)

| stockcode | gross_gbp | credit_gbp | lines | credit_to_gross |
| --- | --- | --- | --- | --- |
| AMAZONFEE | 1.376e+04 | 2.353e+05 | 34 | 17.1 |
| M | 7.811e+04 | 1.468e+05 | 571 | 1.879 |
| 23843 | 1.685e+05 | 1.685e+05 | 2 | 1 |
| 23166 | 8.17e+04 | 7.748e+04 | 260 | 0.9483 |
| 21108 | 1.807e+04 | 6,591 | 270 | 0.3648 |
| 47566B | 1.129e+04 | 3,693 | 379 | 0.3271 |
| 22273 | 1.202e+04 | 3,513 | 344 | 0.2923 |
| 22191 | 1.197e+04 | 2,654 | 441 | 0.2217 |
| 20971 | 1.384e+04 | 2,779 | 538 | 0.2008 |
| 48185 | 2.389e+04 | 4,555 | 372 | 0.1907 |
| 71477 | 2.066e+04 | 3,444 | 356 | 0.1667 |
| POST | 7.81e+04 | 1.187e+04 | 1256 | 0.152 |
| 21175 | 2.707e+04 | 3,775 | 826 | 0.1394 |
| 21843 | 2.137e+04 | 2,480 | 585 | 0.1161 |

The chart shows 14 of 233 result rows; the table previews the first 14 in the analysis-defined order. [Download the full result table](outputs/results.csv). Numerical values are computed from the source; missing results stay unavailable.

## Method

SQL conditional aggregation with a minimum sales exposure.

The study uses shared source preparation and reusable statistical routines. Its specific transformations are in [analysis.py](analysis.py), and common model/evaluation code is in [portfolio/methods.py](../../portfolio/methods.py). The [notebook](analysis.ipynb) executes the study and displays the saved results.

## Decision and limitations

Investigate the product and invoice context before attributing credits to quality problems.

Historical invoice lines; credits are not reliably matched to original sales. Gross purchases are not profit. Unidentified customers cannot support customer-level conclusions. Exact repeated lines remain unless the study explicitly compares removal. 

Related studies may share observations or holdouts. These are focused analytical studies, not independent replications or deployed business systems. Any model refinements informed by these results need new untouched evaluation data. No commercial impact is inferred from an association or backtest.

## Reproduce

From the repository root, after installing `requirements.txt`:

```powershell
python projects/003-product-credit-exposure/analysis.py
```

Source data are downloaded automatically if absent. Original archives are retained unchanged and checked by SHA-256. The cleaned cache normalizes column names; field-specific changes are visible in [data preparation](../../portfolio/data.py). Runtime evidence is in [receipt.json](outputs/receipt.json).

## Source

[Online Retail](https://archive.ics.uci.edu/dataset/352/online+retail), Chen (2015). [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/). Source data are transformed and aggregated in this study. [Source provenance](../../data/provenance/retail.json) and [prepared-data audit](../../data/provenance/retail_prepared.json) record the downloaded files, field coverage and hashes.
