renaissance-statistical-arbitrage by copyleftdev/sk1llz
npx skills add https://github.com/copyleftdev/sk1llz --skill renaissance-statistical-arbitrageRenaissance Technologies 由数学家吉姆·西蒙斯创立,运营着 Medallion 基金——这是历史上最成功的对冲基金,在超过 30 年的时间里,扣除费用前的年化回报率约为 66%。该公司雇佣数学家、物理学家和计算机科学家(而非金融人士),并将严谨的科学方法应用于市场数据。
"我们不从商学院招聘人才。我们从硬科学领域招聘人才。"
"数据中的模式是短暂的。如果某个方法有效,它很可能很快就会失效。"
"我们从事的不是预测业务。我们从事的是寻找那些重复频率略高于随机概率的模式。"
Renaissance 认为市场并非完全有效,但近乎有效。利润来自于发现微小的、具有统计显著性的优势,并通过严谨的风险管理大规模地利用这些优势。
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
class RenaissanceBacktester:
"""
Renaissance 风格的回测:对偏差保持高度警惕。
"""
def __init__(self, strategy, universe):
self.strategy = strategy
self.universe = universe
self.results = []
def run(self, start_date, end_date,
train_window_days=252,
test_window_days=63,
embargo_days=5):
"""
带有禁运期的前向滚动验证。
绝不允许训练数据泄露到测试期。
"""
current = start_date
while current + timedelta(days=train_window_days + test_window_days) <= end_date:
train_end = current + timedelta(days=train_window_days)
# 禁运期:训练和测试之间的间隔,防止数据泄露
test_start = train_end + timedelta(days=embargo_days)
test_end = test_start + timedelta(days=test_window_days)
# 在历史数据上训练
train_data = self.get_point_in_time_data(current, train_end)
self.strategy.fit(train_data)
# 在未来数据上测试(策略在训练期间无法看到这些数据)
test_data = self.get_point_in_time_data(test_start, test_end)
returns = self.strategy.execute(test_data)
self.results.append({
'train_period': (current, train_end),
'test_period': (test_start, test_end),
'returns': returns,
'sharpe': self.calculate_sharpe(returns)
})
current = test_end
return self.analyze_results()
def get_point_in_time_data(self, start, end):
"""
关键:返回每个时间点实际存在的数据。
没有未来信息,没有重述的财务报表,没有幸存者偏差。
"""
return self.universe.get_pit_snapshot(start, end)
def analyze_results(self):
"""对前向滚动结果进行统计分析。"""
returns = [r['returns'] for r in self.results]
# t 检验:平均回报是否显著不同于零?
t_stat, p_value = stats.ttest_1samp(returns, 0)
return {
'mean_return': np.mean(returns),
'sharpe_ratio': np.mean(returns) / np.std(returns) * np.sqrt(252),
't_statistic': t_stat,
'p_value': p_value,
'significant': p_value < 0.01,
'n_periods': len(self.results)
}
class SignalEnsemble:
"""
Renaissance 的洞见:组合多个弱信号。
跟踪衰减并淘汰失效的信号。
"""
def __init__(self, decay_halflife_days=30):
self.signals = {} # signal_id -> SignalModel
self.performance = {} # signal_id -> 滚动性能
self.decay_halflife = decay_halflife_days
def add_signal(self, signal_id, model, weight=1.0):
self.signals[signal_id] = {
'model': model,
'weight': weight,
'created_at': datetime.now(),
'alive': True
}
self.performance[signal_id] = RollingStats(window=252)
def generate_combined_signal(self, features):
"""
正交信号的加权组合。
性能衰减的信号权重降低。
"""
predictions = {}
weights = {}
for signal_id, signal in self.signals.items():
if not signal['alive']:
continue
pred = signal['model'].predict(features)
# 权重 = 原始权重 × 近期表现
perf = self.performance[signal_id]
decay_weight = self.calculate_decay_weight(perf)
predictions[signal_id] = pred
weights[signal_id] = signal['weight'] * decay_weight
# 归一化权重
total_weight = sum(weights.values())
if total_weight == 0:
return 0.0
combined = sum(
predictions[sid] * weights[sid] / total_weight
for sid in predictions
)
return combined
def update_performance(self, signal_id, realized_return, predicted_direction):
"""跟踪信号是否正确预测了方向。"""
correct = (realized_return > 0) == (predicted_direction > 0)
self.performance[signal_id].add(1.0 if correct else 0.0)
# 淘汰衰减到阈值以下的信号
if self.performance[signal_id].mean() < 0.51: # 仅略好于随机
self.signals[signal_id]['alive'] = False
def calculate_decay_weight(self, perf):
"""基于近期命中率的指数衰减。"""
hit_rate = perf.mean()
# 缩放:50% 命中率 = 0 权重,55% = 0.5,60% = 1.0
return max(0, (hit_rate - 0.50) * 10)
class MarketRegimeHMM:
"""
使用隐马尔可夫模型的 Renaissance 风格状态检测。
市场在不同状态下表现出不同的统计特性。
"""
def __init__(self, n_regimes=3):
self.n_regimes = n_regimes
self.model = None
self.regime_stats = {}
def fit(self, returns, volume, volatility):
"""
将 HMM 拟合到市场观测变量。
从价格/成交量/波动率模式中发现潜在状态。
"""
# 将观测变量堆叠成特征矩阵
observations = np.column_stack([
returns,
np.log(volume + 1),
volatility
])
self.model = hmm.GaussianHMM(
n_components=self.n_regimes,
covariance_type='full',
n_iter=1000
)
self.model.fit(observations)
# 解码以获得最可能的状态序列
regimes = self.model.predict(observations)
# 描述每个状态的特征
for regime in range(self.n_regimes):
mask = regimes == regime
self.regime_stats[regime] = {
'mean_return': returns[mask].mean(),
'volatility': returns[mask].std(),
'frequency': mask.mean(),
'mean_duration': self.calculate_duration(regimes, regime)
}
return self
def current_regime(self, recent_observations):
"""根据近期数据推断当前状态。"""
probs = self.model.predict_proba(recent_observations)
return np.argmax(probs[-1])
def regime_adjusted_signal(self, base_signal, current_regime):
"""根据状态调整信号强度。"""
regime = self.regime_stats[current_regime]
# 根据波动率反向调整信号
# (在高波动率状态下,相同的信号应持有较小的头寸)
vol_adjustment = 0.15 / regime['volatility'] # 目标 15% 波动率
return base_signal * vol_adjustment
class AlphaResearch:
"""
Renaissance 方法:测试成千上万个假设,
但进行多重检验校正以避免错误发现。
"""
def __init__(self, significance_level=0.01):
self.alpha = significance_level
self.tested_hypotheses = []
def test_signal(self, signal_name, returns, predictions):
"""测试信号是否具有预测能力。"""
# 信息系数:预测与结果的相关性
ic = stats.spearmanr(predictions, returns)
# 显著性 t 检验
n = len(returns)
t_stat = ic.correlation * np.sqrt(n - 2) / np.sqrt(1 - ic.correlation**2)
p_value = 2 * (1 - stats.t.cdf(abs(t_stat), n - 2))
self.tested_hypotheses.append({
'signal': signal_name,
'ic': ic.correlation,
't_stat': t_stat,
'p_value': p_value
})
return p_value
def get_significant_signals(self, method='fdr'):
"""
在测试了许多信号之后,应用多重检验校正。
"""
p_values = [h['p_value'] for h in self.tested_hypotheses]
if method == 'bonferroni':
# 最保守:将 alpha 除以检验次数
adjusted_alpha = self.alpha / len(p_values)
significant = [
h for h in self.tested_hypotheses
if h['p_value'] < adjusted_alpha
]
elif method == 'fdr':
# Benjamini-Hochberg:控制错误发现率
sorted_hypotheses = sorted(self.tested_hypotheses, key=lambda x: x['p_value'])
significant = []
for i, h in enumerate(sorted_hypotheses):
# BH 阈值:(排名 / 检验次数) * alpha
threshold = ((i + 1) / len(p_values)) * self.alpha
if h['p_value'] <= threshold:
significant.append(h)
else:
break # 所有剩余的也将失败
return significant
Renaissance 通过以下问题来对待交易:
每周安装量
82
代码仓库
GitHub 星标数
5
首次出现
2026年2月1日
安全审计
安装于
opencode74
gemini-cli70
github-copilot67
cursor67
codex66
kimi-cli60
Renaissance Technologies, founded by mathematician Jim Simons, operates the Medallion Fund—the most successful hedge fund in history with ~66% annual returns before fees over 30+ years. The firm hires mathematicians, physicists, and computer scientists (not finance people) and applies rigorous scientific methods to market data.
"We don't hire people from business schools. We hire people from the hard sciences."
"Patterns in data are ephemeral. If something works, it's probably going to stop working."
"We're not in the business of predicting. We're in the business of finding patterns that repeat slightly more often than they should."
Renaissance believes markets are not perfectly efficient but nearly so. Profits come from finding tiny, statistically significant edges and exploiting them at massive scale with rigorous risk management.
Scientific Method : Form hypotheses, test rigorously, reject most ideas.
Signal, Not Prediction : Find patterns that repeat more often than chance; don't predict the future.
Decay Awareness : Every signal degrades over time. Continuous research is survival.
Statistical Significance : If it's not statistically significant, it doesn't exist.
Ensemble Everything : Combine thousands of weak signals into robust strategies.
class RenaissanceBacktester:
"""
Renaissance-style backtesting: paranoid about biases.
"""
def __init__(self, strategy, universe):
self.strategy = strategy
self.universe = universe
self.results = []
def run(self, start_date, end_date,
train_window_days=252,
test_window_days=63,
embargo_days=5):
"""
Walk-forward validation with embargo period.
Never let training data leak into test period.
"""
current = start_date
while current + timedelta(days=train_window_days + test_window_days) <= end_date:
train_end = current + timedelta(days=train_window_days)
# EMBARGO: gap between train and test to prevent leakage
test_start = train_end + timedelta(days=embargo_days)
test_end = test_start + timedelta(days=test_window_days)
# Train on historical data
train_data = self.get_point_in_time_data(current, train_end)
self.strategy.fit(train_data)
# Test on future data (strategy cannot see this during training)
test_data = self.get_point_in_time_data(test_start, test_end)
returns = self.strategy.execute(test_data)
self.results.append({
'train_period': (current, train_end),
'test_period': (test_start, test_end),
'returns': returns,
'sharpe': self.calculate_sharpe(returns)
})
current = test_end
return self.analyze_results()
def get_point_in_time_data(self, start, end):
"""
CRITICAL: Return data as it existed at each point in time.
No future information, no restated financials, no survivorship bias.
"""
return self.universe.get_pit_snapshot(start, end)
def analyze_results(self):
"""Statistical analysis of walk-forward results."""
returns = [r['returns'] for r in self.results]
# t-test: is mean return significantly different from zero?
t_stat, p_value = stats.ttest_1samp(returns, 0)
return {
'mean_return': np.mean(returns),
'sharpe_ratio': np.mean(returns) / np.std(returns) * np.sqrt(252),
't_statistic': t_stat,
'p_value': p_value,
'significant': p_value < 0.01,
'n_periods': len(self.results)
}
class SignalEnsemble:
"""
Renaissance insight: combine many weak signals.
Track decay and retire dying signals.
"""
def __init__(self, decay_halflife_days=30):
self.signals = {} # signal_id -> SignalModel
self.performance = {} # signal_id -> rolling performance
self.decay_halflife = decay_halflife_days
def add_signal(self, signal_id, model, weight=1.0):
self.signals[signal_id] = {
'model': model,
'weight': weight,
'created_at': datetime.now(),
'alive': True
}
self.performance[signal_id] = RollingStats(window=252)
def generate_combined_signal(self, features):
"""
Weighted combination of orthogonal signals.
Signals with decayed performance get lower weights.
"""
predictions = {}
weights = {}
for signal_id, signal in self.signals.items():
if not signal['alive']:
continue
pred = signal['model'].predict(features)
# Weight by original weight × recent performance
perf = self.performance[signal_id]
decay_weight = self.calculate_decay_weight(perf)
predictions[signal_id] = pred
weights[signal_id] = signal['weight'] * decay_weight
# Normalize weights
total_weight = sum(weights.values())
if total_weight == 0:
return 0.0
combined = sum(
predictions[sid] * weights[sid] / total_weight
for sid in predictions
)
return combined
def update_performance(self, signal_id, realized_return, predicted_direction):
"""Track whether signal correctly predicted direction."""
correct = (realized_return > 0) == (predicted_direction > 0)
self.performance[signal_id].add(1.0 if correct else 0.0)
# Kill signals that have decayed below threshold
if self.performance[signal_id].mean() < 0.51: # Barely better than random
self.signals[signal_id]['alive'] = False
def calculate_decay_weight(self, perf):
"""Exponential decay based on recent hit rate."""
hit_rate = perf.mean()
# Scale: 50% hit rate = 0 weight, 55% = 0.5, 60% = 1.0
return max(0, (hit_rate - 0.50) * 10)
class MarketRegimeHMM:
"""
Renaissance-style regime detection using Hidden Markov Models.
Markets exhibit different statistical properties in different regimes.
"""
def __init__(self, n_regimes=3):
self.n_regimes = n_regimes
self.model = None
self.regime_stats = {}
def fit(self, returns, volume, volatility):
"""
Fit HMM to market observables.
Discover latent regimes from price/volume/volatility patterns.
"""
# Stack observables into feature matrix
observations = np.column_stack([
returns,
np.log(volume + 1),
volatility
])
self.model = hmm.GaussianHMM(
n_components=self.n_regimes,
covariance_type='full',
n_iter=1000
)
self.model.fit(observations)
# Decode to get most likely regime sequence
regimes = self.model.predict(observations)
# Characterize each regime
for regime in range(self.n_regimes):
mask = regimes == regime
self.regime_stats[regime] = {
'mean_return': returns[mask].mean(),
'volatility': returns[mask].std(),
'frequency': mask.mean(),
'mean_duration': self.calculate_duration(regimes, regime)
}
return self
def current_regime(self, recent_observations):
"""Infer current regime from recent data."""
probs = self.model.predict_proba(recent_observations)
return np.argmax(probs[-1])
def regime_adjusted_signal(self, base_signal, current_regime):
"""Adjust signal strength based on regime."""
regime = self.regime_stats[current_regime]
# Scale signal inversely with volatility
# (same signal in high-vol regime should have smaller position)
vol_adjustment = 0.15 / regime['volatility'] # Target 15% vol
return base_signal * vol_adjustment
class AlphaResearch:
"""
Renaissance approach: test thousands of hypotheses,
but correct for multiple testing to avoid false discoveries.
"""
def __init__(self, significance_level=0.01):
self.alpha = significance_level
self.tested_hypotheses = []
def test_signal(self, signal_name, returns, predictions):
"""Test if a signal has predictive power."""
# Information Coefficient: correlation of prediction with outcome
ic = stats.spearmanr(predictions, returns)
# t-test for significance
n = len(returns)
t_stat = ic.correlation * np.sqrt(n - 2) / np.sqrt(1 - ic.correlation**2)
p_value = 2 * (1 - stats.t.cdf(abs(t_stat), n - 2))
self.tested_hypotheses.append({
'signal': signal_name,
'ic': ic.correlation,
't_stat': t_stat,
'p_value': p_value
})
return p_value
def get_significant_signals(self, method='fdr'):
"""
After testing many signals, apply multiple testing correction.
"""
p_values = [h['p_value'] for h in self.tested_hypotheses]
if method == 'bonferroni':
# Most conservative: divide alpha by number of tests
adjusted_alpha = self.alpha / len(p_values)
significant = [
h for h in self.tested_hypotheses
if h['p_value'] < adjusted_alpha
]
elif method == 'fdr':
# Benjamini-Hochberg: control false discovery rate
sorted_hypotheses = sorted(self.tested_hypotheses, key=lambda x: x['p_value'])
significant = []
for i, h in enumerate(sorted_hypotheses):
# BH threshold: (rank / n_tests) * alpha
threshold = ((i + 1) / len(p_values)) * self.alpha
if h['p_value'] <= threshold:
significant.append(h)
else:
break # All remaining will also fail
return significant
Renaissance approaches trading by asking:
Weekly Installs
82
Repository
GitHub Stars
5
First Seen
Feb 1, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykPass
Installed on
opencode74
gemini-cli70
github-copilot67
cursor67
codex66
kimi-cli60
AI Elements:基于shadcn/ui的AI原生应用组件库,快速构建对话界面
67,500 周安装