Use when implementing models that learn from minimal data or need to adapt to new market regimes rapidly. Covers episodic learning, context sets, support and query sequences, zero-shot vs few-shot learning, meta-learning for finance, transfer learning across assets and regimes, and quick adaptation to market changes.
Guide for implementing few-shot learning techniques in financial trading strategies, enabling models to quickly adapt to new market regimes or trade previously unseen assets with minimal data.
Activate this skill when:
Few-Shot Learning:
I_train ∩ I_test = IZero-Shot Learning:
I_train ∩ I_test = ∅# Few-shot setting
train_assets = ['SPY', 'GLD', 'TLT'] # 30 assets
test_assets = ['SPY', 'GLD', 'TLT'] # Same 30 assets, different time period
# Zero-shot setting
train_assets = ['SPY', 'GLD', 'TLT'] # 30 assets for training
test_assets = ['BTC', 'ETH', 'SOL'] # 20 different assets for testing
Train models the same way they'll be used at test time:
Traditional Training:
# Standard mini-batch training - all assets mixed together
for epoch in epochs:
for batch in shuffle(all_data):
loss = model(batch)
optimizer.step()
Episodic Training:
# Episode-based training - mimics test-time usage
for episode in episodes:
# Sample target sequence (what we want to predict)
target_asset, target_time = sample_target()
# Sample context set C (what we condition on)
context_set = sample_contexts(
assets=train_assets,
exclude=(target_asset, target_time), # Ensure causality
size=C # Number of context sequences
)
# Make prediction using context
prediction = model(target=target, context=context_set)
loss = criterion(prediction, true_value)
optimizer.step()
Key Principles:
Context set C contains sequences from other assets/regimes that inform the prediction.
Properties:
Construction Methods:
See IMPLEMENTATION.md for code examples.
How It Works:
Key Insight: Cross-attention automatically identifies which context sequences are most similar to the target, weighting them higher in the final prediction.
See IMPLEMENTATION.md for implementation.
1. Same Asset, Different Regime (Few-Shot)
2. Different Assets, Similar Dynamics (Zero-Shot)
3. Cross-Asset Momentum Spillover
Joint Loss Function:
L_joint = α * L_MLE + L_Sharpe