investing-algorithm-framework 7.7.0__tar.gz → 7.8.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/PKG-INFO +1 -1
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/__init__.py +5 -2
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/app/app.py +2 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/domain/backtesting/backtest_metrics.py +22 -1
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/domain/backtesting/backtest_run.py +4 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/services/__init__.py +4 -2
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/services/metrics/__init__.py +6 -4
- investing_algorithm_framework-7.8.0/investing_algorithm_framework/services/metrics/generate.py +395 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/services/metrics/returns.py +53 -3
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/pyproject.toml +1 -1
- investing_algorithm_framework-7.7.0/investing_algorithm_framework/services/metrics/generate.py +0 -210
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/LICENSE +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/README.md +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/app/__init__.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/app/algorithm/__init__.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/app/algorithm/algorithm.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/app/algorithm/algorithm_factory.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/app/analysis/__init__.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/app/analysis/backtest_data_ranges.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/app/analysis/permutation.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/app/analysis/ranking.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/app/app_hook.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/app/context.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/app/eventloop.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/app/reporting/__init__.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/app/reporting/ascii.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/app/reporting/backtest_report.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/app/reporting/charts/__init__.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/app/reporting/charts/entry_exist_signals.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/app/reporting/charts/equity_curve_drawdown.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/app/reporting/charts/line_chart.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/app/reporting/charts/monthly_returns_heatmap.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/app/reporting/charts/ohlcv_data_completeness.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/app/reporting/charts/rolling_sharp_ratio.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/app/reporting/charts/yearly_returns_barchart.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/app/reporting/generate.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/app/reporting/tables/__init__.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/app/reporting/tables/key_metrics_table.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/app/reporting/tables/stop_loss_table.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/app/reporting/tables/time_metrics_table.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/app/reporting/tables/trade_metrics_table.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/app/reporting/tables/trades_table.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/app/reporting/tables/utils.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/app/reporting/templates/report_template.html.j2 +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/app/stateless/__init__.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/app/stateless/action_handlers/__init__.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/app/stateless/action_handlers/action_handler_strategy.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/app/stateless/action_handlers/check_online_handler.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/app/stateless/action_handlers/run_strategy_handler.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/app/stateless/exception_handler.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/app/strategy.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/app/task.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/app/web/__init__.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/app/web/controllers/__init__.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/app/web/controllers/orders.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/app/web/controllers/portfolio.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/app/web/controllers/positions.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/app/web/create_app.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/app/web/error_handler.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/app/web/responses.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/app/web/run_strategies.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/app/web/schemas/__init__.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/app/web/schemas/order.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/app/web/schemas/portfolio.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/app/web/schemas/position.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/app/web/setup_cors.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/cli/__init__.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/cli/cli.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/cli/deploy_to_aws_lambda.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/cli/deploy_to_azure_function.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/cli/initialize_app.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/cli/templates/.gitignore.template +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/cli/templates/app.py.template +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/cli/templates/app_aws_lambda_function.py.template +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/cli/templates/app_azure_function.py.template +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/cli/templates/app_web.py.template +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/cli/templates/aws_lambda_dockerfile.template +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/cli/templates/aws_lambda_dockerignore.template +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/cli/templates/aws_lambda_readme.md.template +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/cli/templates/aws_lambda_requirements.txt.template +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/cli/templates/azure_function_function_app.py.template +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/cli/templates/azure_function_host.json.template +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/cli/templates/azure_function_local.settings.json.template +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/cli/templates/azure_function_requirements.txt.template +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/cli/templates/data_providers.py.template +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/cli/templates/env.example.template +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/cli/templates/env_azure_function.example.template +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/cli/templates/market_data_providers.py.template +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/cli/templates/readme.md.template +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/cli/templates/requirements.txt.template +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/cli/templates/run_backtest.py.template +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/cli/templates/strategy.py.template +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/create_app.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/dependency_container.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/domain/__init__.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/domain/backtesting/BacktestInitializer.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/domain/backtesting/__init__.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/domain/backtesting/backtest.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/domain/backtesting/backtest_date_range.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/domain/backtesting/backtest_evaluation_focuss.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/domain/backtesting/backtest_permutation_test.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/domain/backtesting/backtest_summary_metrics.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/domain/backtesting/combine_backtests.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/domain/config.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/domain/constants.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/domain/data_provider.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/domain/data_structures.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/domain/decimal_parsing.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/domain/exceptions.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/domain/models/__init__.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/domain/models/app_mode.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/domain/models/base_model.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/domain/models/data/__init__.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/domain/models/data/data_source.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/domain/models/data/data_type.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/domain/models/event.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/domain/models/market/__init__.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/domain/models/market/market_credential.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/domain/models/order/__init__.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/domain/models/order/order.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/domain/models/order/order_side.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/domain/models/order/order_status.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/domain/models/order/order_type.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/domain/models/portfolio/__init__.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/domain/models/portfolio/portfolio.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/domain/models/portfolio/portfolio_configuration.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/domain/models/portfolio/portfolio_snapshot.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/domain/models/position/__init__.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/domain/models/position/position.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/domain/models/position/position_snapshot.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/domain/models/snapshot_interval.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/domain/models/strategy_profile.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/domain/models/time_frame.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/domain/models/time_interval.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/domain/models/time_unit.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/domain/models/tracing/__init__.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/domain/models/tracing/trace.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/domain/models/trade/__init__.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/domain/models/trade/trade.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/domain/models/trade/trade_risk_type.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/domain/models/trade/trade_status.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/domain/models/trade/trade_stop_loss.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/domain/models/trade/trade_take_profit.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/domain/order_executor.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/domain/portfolio_provider.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/domain/positions/__init__.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/domain/positions/position_size.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/domain/services/__init__.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/domain/services/market_credential_service.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/domain/services/portfolios/__init__.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/domain/services/portfolios/portfolio_sync_service.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/domain/services/rounding_service.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/domain/services/state_handler.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/domain/stateless_actions.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/domain/strategy.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/domain/utils/__init__.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/domain/utils/csv.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/domain/utils/custom_tqdm.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/domain/utils/dates.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/domain/utils/jupyter_notebook_detection.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/domain/utils/polars.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/domain/utils/random.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/domain/utils/signatures.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/domain/utils/stoppable_thread.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/domain/utils/synchronized.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/download_data.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/infrastructure/__init__.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/infrastructure/data_providers/__init__.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/infrastructure/data_providers/ccxt.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/infrastructure/data_providers/csv.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/infrastructure/data_providers/pandas.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/infrastructure/database/__init__.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/infrastructure/database/sql_alchemy.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/infrastructure/models/__init__.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/infrastructure/models/decimal_parser.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/infrastructure/models/model_extension.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/infrastructure/models/order/__init__.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/infrastructure/models/order/order.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/infrastructure/models/order/order_metadata.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/infrastructure/models/order_trade_association.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/infrastructure/models/portfolio/__init__.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/infrastructure/models/portfolio/portfolio_snapshot.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/infrastructure/models/portfolio/sql_portfolio.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/infrastructure/models/position/__init__.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/infrastructure/models/position/position.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/infrastructure/models/position/position_snapshot.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/infrastructure/models/trades/__init__.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/infrastructure/models/trades/trade.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/infrastructure/models/trades/trade_stop_loss.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/infrastructure/models/trades/trade_take_profit.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/infrastructure/order_executors/__init__.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/infrastructure/order_executors/backtest_oder_executor.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/infrastructure/order_executors/ccxt_order_executor.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/infrastructure/portfolio_providers/__init__.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/infrastructure/portfolio_providers/ccxt_portfolio_provider.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/infrastructure/repositories/__init__.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/infrastructure/repositories/order_metadata_repository.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/infrastructure/repositories/order_repository.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/infrastructure/repositories/portfolio_repository.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/infrastructure/repositories/portfolio_snapshot_repository.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/infrastructure/repositories/position_repository.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/infrastructure/repositories/position_snapshot_repository.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/infrastructure/repositories/repository.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/infrastructure/repositories/trade_repository.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/infrastructure/repositories/trade_stop_loss_repository.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/infrastructure/repositories/trade_take_profit_repository.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/infrastructure/services/__init__.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/infrastructure/services/aws/__init__.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/infrastructure/services/aws/state_handler.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/infrastructure/services/azure/__init__.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/infrastructure/services/azure/state_handler.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/services/backtesting/__init__.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/services/backtesting/backtest_service.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/services/configuration_service.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/services/data_providers/__init__.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/services/data_providers/data_provider_service.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/services/market_credential_service.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/services/metrics/alpha.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/services/metrics/beta.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/services/metrics/cagr.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/services/metrics/calmar_ratio.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/services/metrics/drawdown.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/services/metrics/equity_curve.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/services/metrics/exposure.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/services/metrics/mean_daily_return.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/services/metrics/price_efficiency.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/services/metrics/profit_factor.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/services/metrics/recovery.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/services/metrics/risk_free_rate.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/services/metrics/sharpe_ratio.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/services/metrics/sortino_ratio.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/services/metrics/standard_deviation.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/services/metrics/treynor_ratio.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/services/metrics/ulcer.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/services/metrics/value_at_risk.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/services/metrics/volatility.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/services/metrics/win_rate.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/services/order_service/__init__.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/services/order_service/order_backtest_service.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/services/order_service/order_executor_lookup.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/services/order_service/order_service.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/services/portfolios/__init__.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/services/portfolios/backtest_portfolio_service.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/services/portfolios/portfolio_configuration_service.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/services/portfolios/portfolio_provider_lookup.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/services/portfolios/portfolio_service.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/services/portfolios/portfolio_snapshot_service.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/services/portfolios/portfolio_sync_service.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/services/positions/__init__.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/services/positions/position_service.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/services/positions/position_snapshot_service.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/services/repository_service.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/services/trade_order_evaluator/__init__.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/services/trade_order_evaluator/backtest_trade_oder_evaluator.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/services/trade_order_evaluator/default_trade_order_evaluator.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/services/trade_order_evaluator/trade_order_evaluator.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/services/trade_service/__init__.py +0 -0
- {investing_algorithm_framework-7.7.0 → investing_algorithm_framework-7.8.0}/investing_algorithm_framework/services/trade_service/trade_service.py +0 -0
|
@@ -42,7 +42,8 @@ from .services import get_annual_volatility, get_sortino_ratio, \
|
|
|
42
42
|
get_average_monthly_return_winning_months, get_percentage_winning_years, \
|
|
43
43
|
get_rolling_sharpe_ratio, create_backtest_metrics, get_growth, \
|
|
44
44
|
get_growth_percentage, get_cumulative_exposure, get_median_return, \
|
|
45
|
-
get_average_return, get_risk_free_rate_us
|
|
45
|
+
get_average_return, get_risk_free_rate_us, get_cumulative_return, \
|
|
46
|
+
get_cumulative_return_series
|
|
46
47
|
|
|
47
48
|
|
|
48
49
|
__all__ = [
|
|
@@ -169,5 +170,7 @@ __all__ = [
|
|
|
169
170
|
"PositionSize",
|
|
170
171
|
"get_median_return",
|
|
171
172
|
"get_average_return",
|
|
172
|
-
"get_risk_free_rate_us"
|
|
173
|
+
"get_risk_free_rate_us",
|
|
174
|
+
"get_cumulative_return",
|
|
175
|
+
"get_cumulative_return_series",
|
|
173
176
|
]
|
|
@@ -1323,7 +1323,9 @@ class App:
|
|
|
1323
1323
|
original_datasets_ordered_by_symbol = {}
|
|
1324
1324
|
|
|
1325
1325
|
for data_source in data_sources:
|
|
1326
|
+
print(data_source)
|
|
1326
1327
|
if DataType.OHLCV.equals(data_source.data_type):
|
|
1328
|
+
print(data_source.symbol)
|
|
1327
1329
|
data_provider = data_provider_service.get(data_source)
|
|
1328
1330
|
data = data_provider_service.get_data(
|
|
1329
1331
|
data_source=data_source,
|
|
@@ -2,7 +2,7 @@ import os
|
|
|
2
2
|
from pathlib import Path
|
|
3
3
|
from dataclasses import dataclass, field
|
|
4
4
|
from logging import getLogger
|
|
5
|
-
from typing import Tuple, List
|
|
5
|
+
from typing import Tuple, List, Dict
|
|
6
6
|
from datetime import datetime, date
|
|
7
7
|
import json
|
|
8
8
|
import pandas as pd
|
|
@@ -85,6 +85,12 @@ class BacktestMetrics:
|
|
|
85
85
|
trades in hours.
|
|
86
86
|
number_of_trades (int): The total number of trades executed
|
|
87
87
|
during the backtest.
|
|
88
|
+
number_of_trades_closed (int): The total number of trades close
|
|
89
|
+
during the backtest.
|
|
90
|
+
number_of_trades_opened (int): The total number of trades opened
|
|
91
|
+
during the backtest.
|
|
92
|
+
number_of_trades_open_at_end (int): The number of trades
|
|
93
|
+
still open at the end of the backtest.
|
|
88
94
|
win_rate (float): The win rate of the trades, expressed
|
|
89
95
|
as a percentage.
|
|
90
96
|
win_loss_ratio (float): The ratio of winning trades
|
|
@@ -111,6 +117,8 @@ class BacktestMetrics:
|
|
|
111
117
|
including return and date.
|
|
112
118
|
worst_year (datetime): A string representation of the worst year,
|
|
113
119
|
including return and date.
|
|
120
|
+
metadata (Dict[str, str]): A dictionary to store any additional
|
|
121
|
+
metadata related to the backtest.
|
|
114
122
|
"""
|
|
115
123
|
backtest_start_date: datetime
|
|
116
124
|
backtest_end_date: datetime
|
|
@@ -120,6 +128,9 @@ class BacktestMetrics:
|
|
|
120
128
|
total_net_gain: float = 0.0
|
|
121
129
|
total_net_gain_percentage: float = 0.0
|
|
122
130
|
final_value: float = 0.0
|
|
131
|
+
cumulative_return: float = 0.0
|
|
132
|
+
cumulative_return_series: List[Tuple[float, datetime]] = \
|
|
133
|
+
field(default_factory=list)
|
|
123
134
|
cagr: float = 0.0
|
|
124
135
|
sharpe_ratio: float = 0.0
|
|
125
136
|
rolling_sharpe_ratio: List[Tuple[float, datetime]] = \
|
|
@@ -152,6 +163,9 @@ class BacktestMetrics:
|
|
|
152
163
|
average_trade_duration: float = 0.0
|
|
153
164
|
average_trade_size: float = 0.0
|
|
154
165
|
number_of_trades: int = 0
|
|
166
|
+
number_of_trades_closed: int = 0
|
|
167
|
+
number_of_trades_opened: int = 0
|
|
168
|
+
number_of_trades_open_at_end: int = 0
|
|
155
169
|
win_rate: float = 0.0
|
|
156
170
|
win_loss_ratio: float = 0.0
|
|
157
171
|
percentage_positive_trades: float = 0.0
|
|
@@ -166,6 +180,7 @@ class BacktestMetrics:
|
|
|
166
180
|
worst_month: Tuple[float, datetime] = None
|
|
167
181
|
worst_year: Tuple[float, date] = None
|
|
168
182
|
total_number_of_days: int = None
|
|
183
|
+
metadata: Dict[str, str] = field(default_factory=dict)
|
|
169
184
|
|
|
170
185
|
def __post_init__(self):
|
|
171
186
|
self.total_number_of_days = (self.backtest_end_date -
|
|
@@ -186,6 +201,12 @@ class BacktestMetrics:
|
|
|
186
201
|
"total_net_gain": self.total_net_gain,
|
|
187
202
|
"total_net_gain_percentage": self.total_net_gain_percentage,
|
|
188
203
|
"final_value": self.final_value,
|
|
204
|
+
"growth": self.growth,
|
|
205
|
+
"growth_percentage": self.growth_percentage,
|
|
206
|
+
"cumulative_return": self.cumulative_return,
|
|
207
|
+
"cumulative_return_series": [(value, date.isoformat())
|
|
208
|
+
for value, date in
|
|
209
|
+
self.cumulative_return_series],
|
|
189
210
|
"cagr": self.cagr,
|
|
190
211
|
"sharpe_ratio": self.sharpe_ratio,
|
|
191
212
|
"rolling_sharpe_ratio": [
|
|
@@ -151,6 +151,10 @@ class BacktestRun:
|
|
|
151
151
|
|
|
152
152
|
if os.path.isfile(run_file):
|
|
153
153
|
data = json.load(open(run_file, 'r'))
|
|
154
|
+
else:
|
|
155
|
+
raise OperationalException(
|
|
156
|
+
f"The run file {run_file} does not exist."
|
|
157
|
+
)
|
|
154
158
|
|
|
155
159
|
# Parse datetime fields
|
|
156
160
|
data["backtest_start_date"] = datetime.strptime(
|
|
@@ -32,7 +32,7 @@ from .metrics import get_annual_volatility, \
|
|
|
32
32
|
get_average_monthly_return_winning_months, get_percentage_winning_years, \
|
|
33
33
|
get_rolling_sharpe_ratio, create_backtest_metrics, get_growth, \
|
|
34
34
|
get_growth_percentage, get_risk_free_rate_us, get_median_return, \
|
|
35
|
-
get_average_return
|
|
35
|
+
get_average_return, get_cumulative_return, get_cumulative_return_series
|
|
36
36
|
|
|
37
37
|
__all__ = [
|
|
38
38
|
"OrderService",
|
|
@@ -109,5 +109,7 @@ __all__ = [
|
|
|
109
109
|
"create_backtest_metrics",
|
|
110
110
|
"get_growth",
|
|
111
111
|
"get_median_return",
|
|
112
|
-
"get_average_return"
|
|
112
|
+
"get_average_return",
|
|
113
|
+
"get_cumulative_return",
|
|
114
|
+
"get_cumulative_return_series",
|
|
113
115
|
]
|
|
@@ -20,8 +20,9 @@ from .returns import get_yearly_returns, get_monthly_returns, \
|
|
|
20
20
|
get_average_gain, get_average_loss, get_average_monthly_return, \
|
|
21
21
|
get_percentage_winning_months, get_average_monthly_return_losing_months, \
|
|
22
22
|
get_average_monthly_return_winning_months, get_growth, \
|
|
23
|
-
get_percentage_winning_years, get_worst_year, \
|
|
24
|
-
get_growth_percentage, get_median_return, get_average_return
|
|
23
|
+
get_percentage_winning_years, get_worst_year, get_cumulative_return, \
|
|
24
|
+
get_growth_percentage, get_median_return, get_average_return, \
|
|
25
|
+
get_cumulative_return_series
|
|
25
26
|
from .exposure import get_average_trade_duration, \
|
|
26
27
|
get_trade_frequency, get_trades_per_day, get_trades_per_year, \
|
|
27
28
|
get_cumulative_exposure, get_exposure_ratio
|
|
@@ -49,7 +50,6 @@ __all__ = [
|
|
|
49
50
|
"get_total_return",
|
|
50
51
|
"get_cumulative_exposure",
|
|
51
52
|
"get_exposure_ratio",
|
|
52
|
-
"get_average_trade_duration",
|
|
53
53
|
"get_win_rate",
|
|
54
54
|
"get_win_loss_ratio",
|
|
55
55
|
"get_calmar_ratio",
|
|
@@ -86,5 +86,7 @@ __all__ = [
|
|
|
86
86
|
"get_growth_percentage",
|
|
87
87
|
"get_risk_free_rate_us",
|
|
88
88
|
"get_median_return",
|
|
89
|
-
"get_average_return"
|
|
89
|
+
"get_average_return",
|
|
90
|
+
"get_cumulative_return",
|
|
91
|
+
"get_cumulative_return_series",
|
|
90
92
|
]
|
investing_algorithm_framework-7.8.0/investing_algorithm_framework/services/metrics/generate.py
ADDED
|
@@ -0,0 +1,395 @@
|
|
|
1
|
+
from typing import List
|
|
2
|
+
|
|
3
|
+
from investing_algorithm_framework.domain import BacktestMetrics, \
|
|
4
|
+
TradeStatus, BacktestRun
|
|
5
|
+
from .cagr import get_cagr
|
|
6
|
+
from .calmar_ratio import get_calmar_ratio
|
|
7
|
+
from .drawdown import get_drawdown_series, get_max_drawdown, \
|
|
8
|
+
get_max_daily_drawdown, get_max_drawdown_absolute, \
|
|
9
|
+
get_max_drawdown_duration
|
|
10
|
+
from .equity_curve import get_equity_curve
|
|
11
|
+
from .exposure import get_exposure_ratio, get_cumulative_exposure, \
|
|
12
|
+
get_trades_per_year, get_trades_per_day
|
|
13
|
+
from .profit_factor import get_profit_factor, get_gross_loss, get_gross_profit
|
|
14
|
+
from .returns import get_monthly_returns, get_yearly_returns, \
|
|
15
|
+
get_worst_trade, get_best_trade, get_worst_year, \
|
|
16
|
+
get_best_year, get_best_month, get_worst_month, get_average_gain, \
|
|
17
|
+
get_percentage_winning_months, get_percentage_winning_years, \
|
|
18
|
+
get_average_loss, get_average_monthly_return, \
|
|
19
|
+
get_average_monthly_return_winning_months, get_average_return, \
|
|
20
|
+
get_average_monthly_return_losing_months, get_cumulative_return, \
|
|
21
|
+
get_cumulative_return_series
|
|
22
|
+
from .returns import get_total_return, get_final_value, get_growth, \
|
|
23
|
+
get_growth_percentage
|
|
24
|
+
from .sharpe_ratio import get_sharpe_ratio, get_rolling_sharpe_ratio
|
|
25
|
+
from .sortino_ratio import get_sortino_ratio
|
|
26
|
+
from .volatility import get_annual_volatility
|
|
27
|
+
from .win_rate import get_win_rate, get_win_loss_ratio
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def create_backtest_metrics(
|
|
31
|
+
backtest_run: BacktestRun, risk_free_rate: float, metrics: List[str] = None
|
|
32
|
+
) -> BacktestMetrics:
|
|
33
|
+
"""
|
|
34
|
+
Create a BacktestMetrics instance and optionally save it to a file.
|
|
35
|
+
"""
|
|
36
|
+
|
|
37
|
+
if metrics is None:
|
|
38
|
+
metrics = [
|
|
39
|
+
"equity_curve",
|
|
40
|
+
"final_value",
|
|
41
|
+
"total_net_gain",
|
|
42
|
+
"total_net_gain_percentage",
|
|
43
|
+
"cumulative_return",
|
|
44
|
+
"cumulative_return_series",
|
|
45
|
+
"cagr",
|
|
46
|
+
"sharpe_ratio",
|
|
47
|
+
"rolling_sharpe_ratio",
|
|
48
|
+
"sortino_ratio",
|
|
49
|
+
"profit_factor",
|
|
50
|
+
"calmar_ratio",
|
|
51
|
+
"annual_volatility",
|
|
52
|
+
"monthly_returns",
|
|
53
|
+
"yearly_returns",
|
|
54
|
+
"drawdown_series",
|
|
55
|
+
"max_drawdown",
|
|
56
|
+
"max_drawdown_absolute",
|
|
57
|
+
"max_daily_drawdown",
|
|
58
|
+
"max_drawdown_duration",
|
|
59
|
+
"trades_per_year",
|
|
60
|
+
"trades_per_day",
|
|
61
|
+
"exposure_ratio",
|
|
62
|
+
"cumulative_exposure",
|
|
63
|
+
"trades_average_gain",
|
|
64
|
+
"trades_average_gain_percentage",
|
|
65
|
+
"trades_average_loss",
|
|
66
|
+
"trades_average_loss_percentage",
|
|
67
|
+
"trades_average_return",
|
|
68
|
+
"trades_average_return_percentage",
|
|
69
|
+
"best_trade",
|
|
70
|
+
"worst_trade",
|
|
71
|
+
"average_trade_duration",
|
|
72
|
+
"average_trade_size",
|
|
73
|
+
"number_of_trades",
|
|
74
|
+
"win_rate",
|
|
75
|
+
"win_loss_ratio",
|
|
76
|
+
"percentage_winning_months",
|
|
77
|
+
"percentage_winning_years",
|
|
78
|
+
"percentage_negative_trades",
|
|
79
|
+
"percentage_positive_trades",
|
|
80
|
+
"average_monthly_return",
|
|
81
|
+
"average_monthly_return_winning_months",
|
|
82
|
+
"average_monthly_return_losing_months",
|
|
83
|
+
"best_month",
|
|
84
|
+
"best_year",
|
|
85
|
+
"worst_month",
|
|
86
|
+
"worst_year",
|
|
87
|
+
"gross_loss",
|
|
88
|
+
"gross_profit",
|
|
89
|
+
"growth",
|
|
90
|
+
"growth_percentage"
|
|
91
|
+
]
|
|
92
|
+
|
|
93
|
+
backtest_metrics = BacktestMetrics(
|
|
94
|
+
backtest_start_date=backtest_run.backtest_start_date,
|
|
95
|
+
backtest_end_date=backtest_run.backtest_end_date,
|
|
96
|
+
)
|
|
97
|
+
|
|
98
|
+
if "total_net_gain" in metrics or "total_net_gain_percentage" in metrics:
|
|
99
|
+
total_return = get_total_return(backtest_run.portfolio_snapshots)
|
|
100
|
+
|
|
101
|
+
if "total_net_gain" in metrics:
|
|
102
|
+
backtest_metrics.total_net_gain = total_return[0]
|
|
103
|
+
|
|
104
|
+
if "total_net_gain_percentage" in metrics:
|
|
105
|
+
backtest_metrics.total_net_gain_percentage = total_return[1]
|
|
106
|
+
|
|
107
|
+
if "trades_average_gain" in metrics \
|
|
108
|
+
or "trades_average_gain_percentage" in metrics:
|
|
109
|
+
trades_average_gain = get_average_gain(backtest_run.trades)
|
|
110
|
+
|
|
111
|
+
if "trades_average_gain" in metrics:
|
|
112
|
+
backtest_metrics.trades_average_gain = trades_average_gain[0]
|
|
113
|
+
|
|
114
|
+
if "trades_average_gain_percentage" in metrics:
|
|
115
|
+
backtest_metrics.trades_average_gain_percentage = \
|
|
116
|
+
trades_average_gain[1]
|
|
117
|
+
|
|
118
|
+
if "trades_average_loss" in metrics \
|
|
119
|
+
or "trades_average_loss_percentage" in metrics:
|
|
120
|
+
trades_average_loss = get_average_loss(
|
|
121
|
+
backtest_run.trades
|
|
122
|
+
)
|
|
123
|
+
|
|
124
|
+
if "trades_average_loss" in metrics:
|
|
125
|
+
backtest_metrics.trades_average_loss = trades_average_loss[0]
|
|
126
|
+
|
|
127
|
+
if "trades_average_loss_percentage" in metrics:
|
|
128
|
+
backtest_metrics.trades_average_loss_percentage = \
|
|
129
|
+
trades_average_loss[1]
|
|
130
|
+
|
|
131
|
+
number_of_negative_trades = 0.0
|
|
132
|
+
number_of_positive_trades = 0.0
|
|
133
|
+
number_of_trades_closed = 0
|
|
134
|
+
number_of_trades_open = 0
|
|
135
|
+
total_duration = 0
|
|
136
|
+
total_trade_size = 0.0
|
|
137
|
+
total_cost = 0.0
|
|
138
|
+
trades = backtest_run.trades
|
|
139
|
+
|
|
140
|
+
for trade in trades:
|
|
141
|
+
total_cost += trade.cost
|
|
142
|
+
total_duration += \
|
|
143
|
+
((trade.closed_at - trade.opened_at).total_seconds() /
|
|
144
|
+
3600) if trade.closed_at else 0
|
|
145
|
+
total_trade_size += trade.size
|
|
146
|
+
if trade.status == TradeStatus.CLOSED.value:
|
|
147
|
+
number_of_trades_closed += 1
|
|
148
|
+
|
|
149
|
+
if trade.status == TradeStatus.OPEN.value:
|
|
150
|
+
number_of_trades_open += 1
|
|
151
|
+
|
|
152
|
+
if trade.net_gain > 0:
|
|
153
|
+
number_of_positive_trades += 1
|
|
154
|
+
elif trade.net_gain < 0:
|
|
155
|
+
number_of_negative_trades += 1
|
|
156
|
+
|
|
157
|
+
if "percentage_positive_trades" in metrics:
|
|
158
|
+
backtest_metrics.percentage_positive_trades = \
|
|
159
|
+
(number_of_positive_trades / len(trades)) * 100.0 \
|
|
160
|
+
if len(trades) > 0 else 0.0
|
|
161
|
+
|
|
162
|
+
if "percentage_negative_trades" in metrics:
|
|
163
|
+
backtest_metrics.percentage_negative_trades = \
|
|
164
|
+
(number_of_negative_trades / len(trades)) * 100.0 \
|
|
165
|
+
if len(trades) > 0 else 0.0
|
|
166
|
+
|
|
167
|
+
if "number_of_trades" in metrics:
|
|
168
|
+
backtest_metrics.number_of_trades = len(trades)
|
|
169
|
+
|
|
170
|
+
if "number_of_trades_closed" in metrics:
|
|
171
|
+
backtest_metrics.number_of_trades_closed = number_of_trades_closed
|
|
172
|
+
|
|
173
|
+
if "number_of_trades_open_at_end" in metrics:
|
|
174
|
+
backtest_metrics.number_of_trades_open_at_end = \
|
|
175
|
+
len(trades) - number_of_trades_closed
|
|
176
|
+
|
|
177
|
+
number_of_trades = len(trades)
|
|
178
|
+
|
|
179
|
+
if 'average_trade_duration' in metrics:
|
|
180
|
+
backtest_metrics.average_trade_duration = \
|
|
181
|
+
total_duration / number_of_trades \
|
|
182
|
+
if number_of_trades > 0 else 0.0
|
|
183
|
+
|
|
184
|
+
if 'average_trade_size' in metrics:
|
|
185
|
+
backtest_metrics.average_trade_size = (
|
|
186
|
+
total_trade_size / number_of_trades) \
|
|
187
|
+
if number_of_trades > 0 else 0.0
|
|
188
|
+
|
|
189
|
+
if "trades_average_return" in metrics:
|
|
190
|
+
average_return = get_average_return(trades)
|
|
191
|
+
backtest_metrics.trades_average_return = average_return[0]
|
|
192
|
+
|
|
193
|
+
if "equity_curve" in metrics:
|
|
194
|
+
backtest_metrics.equity_curve = get_equity_curve(
|
|
195
|
+
backtest_run.portfolio_snapshots
|
|
196
|
+
)
|
|
197
|
+
|
|
198
|
+
if "final_value" in metrics:
|
|
199
|
+
backtest_metrics.final_value = get_final_value(
|
|
200
|
+
backtest_run.portfolio_snapshots
|
|
201
|
+
)
|
|
202
|
+
|
|
203
|
+
if "cagr" in metrics:
|
|
204
|
+
backtest_metrics.cagr = get_cagr(backtest_run.portfolio_snapshots)
|
|
205
|
+
|
|
206
|
+
if "sharpe_ratio" in metrics:
|
|
207
|
+
backtest_metrics.sharpe_ratio = get_sharpe_ratio(
|
|
208
|
+
backtest_run.portfolio_snapshots,
|
|
209
|
+
risk_free_rate=risk_free_rate
|
|
210
|
+
)
|
|
211
|
+
|
|
212
|
+
if "rolling_sharpe_ratio" in metrics:
|
|
213
|
+
backtest_metrics.rolling_sharpe_ratio = get_rolling_sharpe_ratio(
|
|
214
|
+
backtest_run.portfolio_snapshots,
|
|
215
|
+
risk_free_rate=risk_free_rate
|
|
216
|
+
)
|
|
217
|
+
|
|
218
|
+
if "sortino_ratio" in metrics:
|
|
219
|
+
backtest_metrics.sortino_ratio = get_sortino_ratio(
|
|
220
|
+
backtest_run.portfolio_snapshots, risk_free_rate=risk_free_rate
|
|
221
|
+
)
|
|
222
|
+
|
|
223
|
+
if "profit_factor" in metrics:
|
|
224
|
+
backtest_metrics.profit_factor = get_profit_factor(backtest_run.trades)
|
|
225
|
+
|
|
226
|
+
if "calmar_ratio" in metrics:
|
|
227
|
+
backtest_metrics.calmar_ratio = \
|
|
228
|
+
get_calmar_ratio(backtest_run.portfolio_snapshots)
|
|
229
|
+
|
|
230
|
+
if "annual_volatility" in metrics:
|
|
231
|
+
backtest_metrics.annual_volatility = get_annual_volatility(
|
|
232
|
+
backtest_run.portfolio_snapshots
|
|
233
|
+
)
|
|
234
|
+
|
|
235
|
+
if "monthly_returns" in metrics:
|
|
236
|
+
backtest_metrics.monthly_returns = get_monthly_returns(
|
|
237
|
+
backtest_run.portfolio_snapshots
|
|
238
|
+
)
|
|
239
|
+
|
|
240
|
+
if "yearly_returns" in metrics:
|
|
241
|
+
backtest_metrics.yearly_returns = get_yearly_returns(
|
|
242
|
+
backtest_run.portfolio_snapshots
|
|
243
|
+
)
|
|
244
|
+
|
|
245
|
+
if "drawdown_series" in metrics:
|
|
246
|
+
backtest_metrics.drawdown_series = get_drawdown_series(
|
|
247
|
+
backtest_run.portfolio_snapshots
|
|
248
|
+
)
|
|
249
|
+
|
|
250
|
+
if "max_drawdown" in metrics:
|
|
251
|
+
backtest_metrics.max_drawdown = get_max_drawdown(
|
|
252
|
+
backtest_run.portfolio_snapshots
|
|
253
|
+
)
|
|
254
|
+
|
|
255
|
+
if "max_drawdown_absolute" in metrics:
|
|
256
|
+
backtest_metrics.max_drawdown_absolute = get_max_drawdown_absolute(
|
|
257
|
+
backtest_run.portfolio_snapshots
|
|
258
|
+
)
|
|
259
|
+
|
|
260
|
+
if "max_daily_drawdown" in metrics:
|
|
261
|
+
backtest_metrics.max_daily_drawdown = get_max_daily_drawdown(
|
|
262
|
+
backtest_run.portfolio_snapshots
|
|
263
|
+
)
|
|
264
|
+
|
|
265
|
+
if "max_drawdown_duration" in metrics:
|
|
266
|
+
backtest_metrics.max_drawdown_duration = get_max_drawdown_duration(
|
|
267
|
+
backtest_run.portfolio_snapshots
|
|
268
|
+
)
|
|
269
|
+
|
|
270
|
+
if "trades_per_year" in metrics:
|
|
271
|
+
backtest_metrics.trades_per_year = get_trades_per_year(
|
|
272
|
+
backtest_run.trades,
|
|
273
|
+
backtest_run.backtest_start_date,
|
|
274
|
+
backtest_run.backtest_end_date
|
|
275
|
+
)
|
|
276
|
+
|
|
277
|
+
if "trades_per_day" in metrics:
|
|
278
|
+
backtest_metrics.trades_per_day = get_trades_per_day(
|
|
279
|
+
backtest_run.trades,
|
|
280
|
+
backtest_run.backtest_start_date,
|
|
281
|
+
backtest_run.backtest_end_date
|
|
282
|
+
)
|
|
283
|
+
|
|
284
|
+
if "exposure_ratio" in metrics:
|
|
285
|
+
backtest_metrics.exposure_ratio = get_exposure_ratio(
|
|
286
|
+
backtest_run.trades,
|
|
287
|
+
backtest_run.backtest_start_date,
|
|
288
|
+
backtest_run.backtest_end_date
|
|
289
|
+
)
|
|
290
|
+
|
|
291
|
+
if "cumulative_exposure" in metrics:
|
|
292
|
+
backtest_metrics.cumulative_exposure = get_cumulative_exposure(
|
|
293
|
+
backtest_run.trades,
|
|
294
|
+
backtest_run.backtest_start_date,
|
|
295
|
+
backtest_run.backtest_end_date
|
|
296
|
+
)
|
|
297
|
+
|
|
298
|
+
if "best_trade" in metrics:
|
|
299
|
+
backtest_metrics.best_trade = get_best_trade(backtest_run.trades)
|
|
300
|
+
|
|
301
|
+
if "worst_trade" in metrics:
|
|
302
|
+
backtest_metrics.worst_trade = get_worst_trade(backtest_run.trades)
|
|
303
|
+
|
|
304
|
+
if 'win_rate' in metrics:
|
|
305
|
+
backtest_metrics.win_rate = get_win_rate(backtest_run.trades)
|
|
306
|
+
|
|
307
|
+
if 'win_loss_ratio' in metrics:
|
|
308
|
+
backtest_metrics.win_loss_ratio = \
|
|
309
|
+
get_win_loss_ratio(backtest_run.trades)
|
|
310
|
+
|
|
311
|
+
if 'percentage_winning_months' in metrics:
|
|
312
|
+
backtest_metrics.percentage_winning_months = \
|
|
313
|
+
get_percentage_winning_months(
|
|
314
|
+
backtest_run.portfolio_snapshots
|
|
315
|
+
)
|
|
316
|
+
|
|
317
|
+
if 'percentage_winning_years' in metrics:
|
|
318
|
+
backtest_metrics.percentage_winning_years = \
|
|
319
|
+
get_percentage_winning_years(backtest_run.portfolio_snapshots)
|
|
320
|
+
|
|
321
|
+
if 'percentage_negative_trades' in metrics:
|
|
322
|
+
backtest_metrics.percentage_negative_trades = (
|
|
323
|
+
(number_of_negative_trades / number_of_trades) * 100.0
|
|
324
|
+
) if number_of_trades > 0 else 0.0
|
|
325
|
+
|
|
326
|
+
if 'percentage_positive_trades' in metrics:
|
|
327
|
+
backtest_metrics.percentage_positive_trades = (
|
|
328
|
+
(number_of_positive_trades / number_of_trades) * 100.0
|
|
329
|
+
) if number_of_trades > 0 else 0.0
|
|
330
|
+
|
|
331
|
+
if 'average_monthly_return' in metrics:
|
|
332
|
+
backtest_metrics.average_monthly_return = get_average_monthly_return(
|
|
333
|
+
backtest_run.portfolio_snapshots
|
|
334
|
+
)
|
|
335
|
+
|
|
336
|
+
if 'average_monthly_return_winning_months' in metrics:
|
|
337
|
+
backtest_metrics.average_monthly_return_winning_months = \
|
|
338
|
+
get_average_monthly_return_winning_months(
|
|
339
|
+
backtest_run.portfolio_snapshots
|
|
340
|
+
)
|
|
341
|
+
|
|
342
|
+
if 'average_monthly_return_losing_months' in metrics:
|
|
343
|
+
backtest_metrics.average_monthly_return_losing_months = \
|
|
344
|
+
get_average_monthly_return_losing_months(
|
|
345
|
+
backtest_run.portfolio_snapshots
|
|
346
|
+
)
|
|
347
|
+
|
|
348
|
+
if 'best_month' in metrics:
|
|
349
|
+
backtest_metrics.best_month = get_best_month(
|
|
350
|
+
backtest_run.portfolio_snapshots
|
|
351
|
+
)
|
|
352
|
+
|
|
353
|
+
if 'best_year' in metrics:
|
|
354
|
+
backtest_metrics.best_year = get_best_year(
|
|
355
|
+
backtest_run.portfolio_snapshots
|
|
356
|
+
)
|
|
357
|
+
|
|
358
|
+
if 'worst_month' in metrics:
|
|
359
|
+
backtest_metrics.worst_month = get_worst_month(
|
|
360
|
+
backtest_run.portfolio_snapshots
|
|
361
|
+
)
|
|
362
|
+
|
|
363
|
+
if 'worst_year' in metrics:
|
|
364
|
+
backtest_metrics.worst_year = get_worst_year(
|
|
365
|
+
backtest_run.portfolio_snapshots
|
|
366
|
+
)
|
|
367
|
+
|
|
368
|
+
if 'gross_loss' in metrics:
|
|
369
|
+
backtest_metrics.gross_loss = get_gross_loss(backtest_run.trades)
|
|
370
|
+
|
|
371
|
+
if 'gross_profit' in metrics:
|
|
372
|
+
backtest_metrics.gross_profit = get_gross_profit(backtest_run.trades)
|
|
373
|
+
|
|
374
|
+
if 'growth' in metrics:
|
|
375
|
+
backtest_metrics.growth = get_growth(
|
|
376
|
+
backtest_run.portfolio_snapshots
|
|
377
|
+
)
|
|
378
|
+
|
|
379
|
+
if 'growth_percentage' in metrics:
|
|
380
|
+
backtest_metrics.growth_percentage = get_growth_percentage(
|
|
381
|
+
backtest_run.portfolio_snapshots
|
|
382
|
+
)
|
|
383
|
+
|
|
384
|
+
if 'cumulative_return_series' in metrics:
|
|
385
|
+
backtest_metrics.cumulative_return_series = \
|
|
386
|
+
get_cumulative_return_series(
|
|
387
|
+
backtest_run.portfolio_snapshots
|
|
388
|
+
)
|
|
389
|
+
|
|
390
|
+
if 'cumulative_return' in metrics:
|
|
391
|
+
backtest_metrics.cumulative_return = get_cumulative_return(
|
|
392
|
+
backtest_run.portfolio_snapshots
|
|
393
|
+
)
|
|
394
|
+
|
|
395
|
+
return backtest_metrics
|
|
@@ -149,9 +149,11 @@ def get_average_return(trades: List[Trade]) -> Tuple[float, float]:
|
|
|
149
149
|
if not returns:
|
|
150
150
|
return 0.0, 0.0
|
|
151
151
|
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
152
|
+
percentages = [t.net_gain / t.cost for t in trades if t.cost > 0]
|
|
153
|
+
average_percentage = sum(percentages) / len(
|
|
154
|
+
percentages) if percentages else 0.0
|
|
155
|
+
average_return = sum(returns) / len(trades)
|
|
156
|
+
return average_return, average_percentage
|
|
155
157
|
|
|
156
158
|
|
|
157
159
|
def get_median_return(trades: List[Trade]) -> Tuple[float, float]:
|
|
@@ -548,3 +550,51 @@ def get_growth_percentage(snapshots: List[PortfolioSnapshot]) -> float:
|
|
|
548
550
|
return 0.0
|
|
549
551
|
|
|
550
552
|
return (final_value - initial_value) / initial_value
|
|
553
|
+
|
|
554
|
+
|
|
555
|
+
def get_cumulative_return(snapshots: list[PortfolioSnapshot]) -> float:
|
|
556
|
+
"""
|
|
557
|
+
Calculate cumulative return over the full period of snapshots.
|
|
558
|
+
Returns a single float (e.g., 0.25 for +25%).
|
|
559
|
+
"""
|
|
560
|
+
if len(snapshots) < 2:
|
|
561
|
+
return 0.0
|
|
562
|
+
|
|
563
|
+
# Sort snapshots by date
|
|
564
|
+
snapshots = sorted(snapshots, key=lambda s: s.created_at)
|
|
565
|
+
|
|
566
|
+
start_value = snapshots[0].total_value
|
|
567
|
+
end_value = snapshots[-1].total_value
|
|
568
|
+
|
|
569
|
+
if start_value == 0:
|
|
570
|
+
return 0.0
|
|
571
|
+
|
|
572
|
+
return (end_value / start_value) - 1
|
|
573
|
+
|
|
574
|
+
|
|
575
|
+
def get_cumulative_return_series(
|
|
576
|
+
snapshots: list[PortfolioSnapshot]
|
|
577
|
+
) -> List[Tuple[float, datetime]]:
|
|
578
|
+
"""
|
|
579
|
+
Calculate cumulative returns from a list of PortfolioSnapshot objects.
|
|
580
|
+
|
|
581
|
+
Args:
|
|
582
|
+
snapshots (list[PortfolioSnapshot]): List of snapshots ordered by time.
|
|
583
|
+
|
|
584
|
+
Returns:
|
|
585
|
+
List[Tuple[float, datetime]]: Cumulative returns for each snapshot.
|
|
586
|
+
"""
|
|
587
|
+
|
|
588
|
+
# Ensure snapshots are sorted by date
|
|
589
|
+
snapshots = sorted(snapshots, key=lambda s: s.get_created_at())
|
|
590
|
+
|
|
591
|
+
initial_value = snapshots[0].get_total_value()
|
|
592
|
+
if initial_value == 0:
|
|
593
|
+
raise ValueError("Initial portfolio value cannot be zero.")
|
|
594
|
+
|
|
595
|
+
cumulative_returns = []
|
|
596
|
+
for snap in snapshots:
|
|
597
|
+
cum_return = (snap.get_total_value() / initial_value) - 1
|
|
598
|
+
cumulative_returns.append((cum_return, snap.created_at))
|
|
599
|
+
|
|
600
|
+
return cumulative_returns
|