rasbt /
LLMs-from-scratch
Implement a ChatGPT-like LLM in PyTorch from scratch, step by step
90/100 healthLoading repository data…
TonyMa1 / repository
A Python implementation of Walk Forward Optimization (WFO) for trading strategy backtesting with Bayesian Optimization
A transparent discovery signal based on current public GitHub metadata.
This score does not audit code, security, maintainers, documentation quality, or suitability. Verify the repository and its current documentation before adoption.
A Python implementation of Walk Forward Optimization (WFO) for trading strategy backtesting with robust position management and dynamic parameter optimization.
This project implements Walk Forward Optimization (WFO) for backtesting and optimizing trading strategies. WFO is a technique that uses rolling windows of data to optimize strategy parameters on in-sample data and validate them on out-of-sample data, reducing the risk of overfitting.
walk_forward_opt/
├── src/
│ └── walk_forward_opt/
│ ├── strategies/ # Trading strategy implementations
│ ├── backtesting/ # WFO and backtesting logic
│ ├── optimization/ # Parameter optimization algorithms
│ └── utils/ # Utility functions and metrics
└── tests/
└── walk_forward_opt/
├── test_strategies/
├── test_backtesting/
├── test_optimization/
└── test_utils/
git clone https://github.com/TonyMa1/walk-forward-backtester.git
cd walk-forward-backtester
python -m venv .venv
# On Windows:
.venv\Scripts\activate
# On macOS/Linux:
source .venv/bin/activate
pip install -r requirements.txt
Run the sample demonstration:
python -m walk_forward_opt
This will run the Walk Forward Optimization process with sample data and display performance metrics for both the MA Crossover and ATR Stop Loss strategies.
import pandas as pd
from walk_forward_opt.backtesting.wfo import WalkForwardOptimization
from walk_forward_opt.strategies.ma_crossover import MACrossoverStrategy
from walk_forward_opt.strategies.atr_stop_loss import ATRStopLossStrategy
# Load your price data (or use the sample data generator)
from walk_forward_opt.__main__ import generate_sample_data
data = generate_sample_data(n_days=1000, volatility=0.02)
# Or load your own data:
# data = pd.read_csv('your_data.csv', index_col='date', parse_dates=True)['close']
# Initialize a strategy
ma_strategy = MACrossoverStrategy()
# Initialize the WFO backtester
wfo = WalkForwardOptimization(
data=data,
train_size=252, # 1 year of trading days
test_size=126, # 6 months of trading days
step_size=126 # Move forward 6 months at a time
)
# Run optimization with the MA Crossover strategy
results = wfo.run_optimization(
strategy=ma_strategy.generate_signals,
optimize_params=ma_strategy.optimize_parameters,
short_ma_range=(5, 50),
long_ma_range=(20, 200),
step=5
)
# Analyze results
analysis = wfo.analyze_results(results)
print(f"Mean Training Sharpe Ratio: {analysis['mean_train_metric']:.2f}")
print(f"Mean Testing Sharpe Ratio: {analysis['mean_test_metric']:.2f}")
print(f"Total Test Returns: {analysis['total_test_returns']:.2%}")
You can modify existing strategies or create your own by implementing:
See the existing implementations in src/walk_forward_opt/strategies/ for examples.
pytest tests/
This project uses Ruff for linting and formatting:
ruff check .
ruff format .
mypy src/
When you run the backtester, it outputs:
MIT License
Selected from shared topics, language and repository description—not editorial ratings.
rasbt /
Implement a ChatGPT-like LLM in PyTorch from scratch, step by step
90/100 healthNirDiamant /
50+ tutorials and implementations for Generative AI Agent techniques, from basic conversational bots to complex multi-agent systems.
84/100 healthmicropython /
MicroPython - a lean and efficient Python implementation for microcontrollers and constrained systems
bharathgs /
A comprehensive list of pytorch related content on github,such as different models,implementations,helper libraries,tutorials etc.
84/100 healthShangtongZhang /
Python Implementation of Reinforcement Learning: An Introduction
92/100 healthaimacode /
Python implementation of algorithms from Russell And Norvig's "Artificial Intelligence - A Modern Approach"
89/100 health