File size: 2,177 Bytes
a445ccd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6b11f75
a445ccd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
---
license: mit
tags:
  - finance
  - retrieval
  - candlestick
  - k-line
  - vicreg
  - contrastive-learning
  - RAG
---

# FinAlogy — VICReg Morphology-Aware Encoder

This repository contains the pretrained visual encoder and demo data for **FinAlogy**, a visual analogy retrieval system for financial K-line analysis.

- 💻 Code: [https://github.com/nice-zzy/FinAlogy](https://github.com/nice-zzy/FinAlogy)
- ▶️ Demo Video: https://youtu.be/SIreBcl__WU

---

## Files

| File | Description |
|---|---|
| `checkpoint_best.pth` | Pretrained VICReg encoder checkpoint (CLIP-ViT-B/32 backbone, 675 MB) |
| `finalogy_demo_instances.zip` | Demo K-line instances for quick inference testing |

---

## Model Description

The encoder is a **CLIP-ViT-B/32** backbone fine-tuned with **VICReg** self-supervised learning on DOW30 historical K-line data (2010–2021). It maps candlestick chart images into a 512-dimensional morphology-aware embedding space, capturing shape-level properties (body size, shadow structure, local trend direction) while remaining invariant to absolute price scales.

**Training details:**
- Backbone: CLIP-ViT-B/32
- Loss: VICReg (λ = µ = 5)
- Data: DOW30 components, 2010–2020 (train), 2021 (test)
- Window size: W = 5 trading days
- Silver-pair threshold: τ = 0.98

**Evaluation (test set, 2,075 unique anchors):**

| Method | 52D Alignment |
|---|---|
| Barlow Twins | 0.785 |
| SimSiam | 0.814 |
| **VICReg (ours)** | **0.910** |

> 52D Alignment measures cosine similarity between retrieved results and the query in the 52-dimensional morphological feature space — higher is better. VICReg achieves the best morphological alignment among all compared methods.

---

## Usage

```python
import torch
from huggingface_hub import hf_hub_download

# Download checkpoint
ckpt_path = hf_hub_download(
    repo_id="ZiyaZhao/FinAlogy",
    filename="checkpoint_best.pth"
)

# Load encoder
checkpoint = torch.load(ckpt_path, map_location="cpu")
# See https://github.com/nice-zzy/FinAlogy for full inference pipeline
```

For the full retrieval and report generation pipeline, see the [GitHub repository](https://github.com/nice-zzy/FinAlogy).