-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
73 lines (55 loc) · 1.86 KB
/
main.py
File metadata and controls
73 lines (55 loc) · 1.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import argparse
import sys
import pandas as pd
from invest import run_dca
from performance import analyse_performance
from scenarios import SCENARIOS, create_strategy_from_scenario, list_scenarios
def main():
parser = argparse.ArgumentParser(
description="DCA Backtesting Framework - Run scenarios",
formatter_class=argparse.RawDescriptionHelpFormatter,
epilog="""
Examples:
python main.py default
python main.py aggressive
python main.py --list
""",
)
parser.add_argument(
"scenario_id",
nargs="?",
help="ID of the scenario to run (use --list to see all available scenarios)",
)
parser.add_argument(
"--list", action="store_true", help="List all available scenarios and exit"
)
args = parser.parse_args()
if args.list:
list_scenarios()
return
if not args.scenario_id:
parser.print_help()
print(
"\nError: Please provide a scenario ID or use --list to see available scenarios"
)
sys.exit(1)
if args.scenario_id not in SCENARIOS:
print(f"Error: Scenario '{args.scenario_id}' not found.")
print("\nAvailable scenarios:")
for scenario_id in SCENARIOS.keys():
print(f" - {scenario_id}")
sys.exit(1)
scenario = SCENARIOS[args.scenario_id]
print(f"Running scenario: {scenario.name}")
print()
strategy = create_strategy_from_scenario(scenario)
df = pd.read_csv(strategy.dataset_path)
df = df.set_index("time")
lookup = df.to_dict(orient="index")
result = run_dca(lookup, strategy)
analyse_performance(strategy, result)
if __name__ == "__main__":
main()
# Fractional shares -> more modern approach
# or Whole shares -> old school, depend of the constraints (if backtest for broker using whole shares)
# quant always us fractional shares