This page describes the typical Python workflow for regimeflow users from first
import to analysis and export.
import regimeflow as rfcfg = rf.BacktestConfig.from_yaml("examples/backtest_basic/config.yaml")Built-in or registered strategy:
engine = rf.BacktestEngine(cfg)
results = engine.run("moving_average_cross")Custom Python strategy:
class MyStrategy(rf.Strategy):
def initialize(self, ctx):
self.ctx = ctx
def on_bar(self, bar):
pass
engine = rf.BacktestEngine(cfg)
results = engine.run(MyStrategy())summary = rf.analysis.performance_summary(results)
stats = rf.analysis.performance_stats(results)
equity = results.equity_curve()
trades = results.trades()rf.analysis.write_report_json(results, "report.json")
rf.analysis.write_report_csv(results, "report.csv")
rf.analysis.write_report_html(results, "report.html")This is the common loop when the strategy itself lives in Python.
- subclass
rf.Strategy - use
initialize()to keep state/context references - act on
on_bar,on_tick, oron_order_book - use
StrategyContextto submit/cancel orders and query state - run, inspect, and iterate
Useful StrategyContext methods:
submit_ordercancel_orderportfolioget_positioncurrent_regimecurrent_timeget_latest_barget_latest_quoteget_latest_bookget_barsschedule_timercancel_timer
If your workflow starts in Pandas, use regimeflow.data to bridge Python dataframes and native types.
Typical helpers:
bars_to_dataframedataframe_to_barsticks_to_dataframedataframe_to_ticksload_csv_barsload_csv_ticksload_csv_dataframenormalize_timezonefill_missing_time_bars
Example:
from regimeflow.data import load_csv_dataframe, normalize_timezone
df = load_csv_dataframe("bars.csv")
df = normalize_timezone(df)The Python package is also the reporting layer.
Use:
rf.analysiswhen you need structured metrics and report exportrf.visualizationwhen you need charts, dashboards, and HTML deliverables
Examples:
dashboard = rf.visualization.create_strategy_tester_dashboard(results)
html_path = rf.visualization.export_dashboard_html(results, "report.html")Use rf.research.ResearchSession when you want a higher-level Python object
that owns a backtest config and can run parity checks.
session = rf.research.ResearchSession(config_path="examples/backtest_basic/config.yaml")
results = session.run_backtest("moving_average_cross")
parity = session.parity_check(live_config_path="examples/live_paper_alpaca/config.yaml")This workflow is useful in notebooks and research tooling where you want a single object for config, runs, and parity checks.
Use the walk-forward exports when parameter stability matters more than a single in-sample run.
Relevant types:
ParameterDefWalkForwardConfigWalkForwardOptimizerWalkForwardResultsWindowResult
- use
BacktestConfig.from_yaml(...)when your workflow already has a checked-in config - use
BacktestConfig.from_dict(...)when your workflow is generated programmatically - use
rf.analysishelpers instead of hand-parsingreport_json()everywhere - use
rf.datahelpers when Pandas is your entry point - use
rf.visualizationonly when you need dashboards or plots; keep core research loops data-oriented - use
rf.researchwhen you need parity-oriented or notebook-oriented session management
python/overview.mdpython/cli.mdtutorials/python-usage.mdapi/python.md