-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsetup_script.py
More file actions
146 lines (119 loc) · 4.55 KB
/
Copy pathsetup_script.py
File metadata and controls
146 lines (119 loc) · 4.55 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#!/usr/bin/env python3
"""
Setup and Run Script for Momentum Portfolio Manager
This script helps set up the environment and provides easy commands to run the portfolio manager.
"""
import subprocess
import sys
import os
from datetime import datetime
def install_requirements():
"""Install required packages"""
print("Installing required packages...")
try:
subprocess.check_call([sys.executable, "-m", "pip", "install", "-r", "requirements.txt"])
print("✅ All packages installed successfully!")
except subprocess.CalledProcessError as e:
print(f"❌ Error installing packages: {e}")
return False
return True
def create_sample_config():
"""Create a sample configuration file"""
config = {
"max_stocks": 30,
"exit_rank": 60,
"dma_period": 200,
"lookback_periods": [3, 6, 9, 12],
"high_percentage_threshold": 30,
"use_all_time_high": False,
"portfolio_file": "current_portfolio.json",
"data_cache_file": "stock_data_cache.json"
}
import json
with open('portfolio_config.json', 'w') as f:
json.dump(config, f, indent=2)
print("✅ Created sample configuration file: portfolio_config.json")
def show_menu():
"""Show the main menu"""
print("\n" + "="*60)
print("MOMENTUM PORTFOLIO MANAGER")
print("="*60)
print("1. Setup Environment (Install packages)")
print("2. Run Monthly Rebalancing")
print("3. Run Daily Monitoring")
print("4. Show Current Configuration")
print("5. Create Sample Configuration")
print("6. Exit")
print("="*60)
def run_rebalancing():
"""Run the monthly rebalancing"""
print(f"\n🔄 Starting Monthly Rebalancing - {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}")
try:
import momentum_portfolio
portfolio_manager = momentum_portfolio.MomentumPortfolioManager()
results = portfolio_manager.rebalance_portfolio()
# Save results
filename = f'rebalance_results_{datetime.now().strftime("%Y%m%d_%H%M%S")}.json'
import json
with open(filename, 'w') as f:
json.dump(results, f, indent=2)
print(f"\n✅ Rebalancing completed! Results saved to: {filename}")
except Exception as e:
print(f"❌ Error during rebalancing: {e}")
def run_monitoring():
"""Run the daily monitoring"""
print(f"\n👁️ Starting Daily Monitoring - {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}")
try:
import momentum_portfolio
portfolio_manager = momentum_portfolio.MomentumPortfolioManager()
results = portfolio_manager.daily_monitoring()
# Save results
filename = f'monitoring_results_{datetime.now().strftime("%Y%m%d_%H%M%S")}.json'
import json
with open(filename, 'w') as f:
json.dump(results, f, indent=2)
print(f"\n✅ Monitoring completed! Results saved to: {filename}")
except Exception as e:
print(f"❌ Error during monitoring: {e}")
def show_config():
"""Show current configuration"""
try:
import json
if os.path.exists('portfolio_config.json'):
with open('portfolio_config.json', 'r') as f:
config = json.load(f)
print("\n📋 Current Configuration:")
print(json.dumps(config, indent=2))
else:
print("❌ Configuration file not found. Please create one first.")
except Exception as e:
print(f"❌ Error reading configuration: {e}")
def main():
"""Main function"""
while True:
show_menu()
try:
choice = input("\nEnter your choice (1-6): ").strip()
if choice == '1':
install_requirements()
elif choice == '2':
run_rebalancing()
elif choice == '3':
run_monitoring()
elif choice == '4':
show_config()
elif choice == '5':
create_sample_config()
elif choice == '6':
print("👋 Goodbye!")
break
else:
print("❌ Invalid choice. Please enter 1-6.")
except KeyboardInterrupt:
print("\n👋 Goodbye!")
break
except Exception as e:
print(f"❌ An error occurred: {e}")
input("\nPress Enter to continue...")
if __name__ == "__main__":
main()