-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdemo_cli.py
More file actions
204 lines (171 loc) Β· 7.87 KB
/
demo_cli.py
File metadata and controls
204 lines (171 loc) Β· 7.87 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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
#!/usr/bin/env python3
"""
Demo script for CLI tools
This script demonstrates the CLI tools with sample data and visualizations.
"""
import sys
import os
import time
import numpy as np
import pandas as pd
from rich.console import Console
from rich.panel import Panel
from rich.progress import Progress, SpinnerColumn, TextColumn
import warnings
warnings.filterwarnings('ignore')
# Add parent directory to path
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
# Color codes
class Colors:
RED = '\033[91m'
GREEN = '\033[92m'
YELLOW = '\033[93m'
BLUE = '\033[94m'
MAGENTA = '\033[95m'
CYAN = '\033[96m'
WHITE = '\033[97m'
BOLD = '\033[1m'
END = '\033[0m'
def create_demo_elasticity_chart():
"""Create a demo elasticity chart."""
chart = f"""
{Colors.BOLD}{Colors.CYAN}π― DEMO: ELASTICITY ANALYSIS RESULTS{Colors.END}
{Colors.YELLOW}{'='*60}{Colors.END}
{Colors.GREEN}Method Elasticity Interpretation{Colors.END}
{Colors.YELLOW}{'-'*60}{Colors.END}
{Colors.CYAN}Double ML{Colors.END} -1.234 High sensitivity
{Colors.MAGENTA}PyBLP Structural{Colors.END} -1.156 High sensitivity
{Colors.BLUE}Panel Data{Colors.END} -0.987 Moderate sensitivity
{Colors.GREEN}AIDS Demand{Colors.END} -1.089 High sensitivity
{Colors.YELLOW}Bayesian{Colors.END} -1.201 High sensitivity
{Colors.RED}ML DML{Colors.END} -1.167 High sensitivity
{Colors.YELLOW}{'='*60}{Colors.END}
{Colors.BOLD}π Business Insights:{Colors.END}
β’ Average elasticity: -1.139 (High price sensitivity)
β’ All methods agree: customers are very responsive to price changes
β’ Recommendation: Use promotional pricing to drive volume
β’ Monitor competitor pricing closely
{Colors.BOLD}π‘ Strategic Actions:{Colors.END}
β’ Implement dynamic pricing based on demand elasticity
β’ Focus on value proposition to reduce price sensitivity
β’ Consider bundling strategies for complementary products
β’ Test price changes in controlled experiments
"""
return chart
def create_demo_cross_price_matrix():
"""Create a demo cross-price matrix."""
matrix = f"""
{Colors.BOLD}{Colors.MAGENTA}π DEMO: CROSS-PRICE ELASTICITY MATRIX{Colors.END}
{Colors.YELLOW}{'='*80}{Colors.END}
{Colors.CYAN}Product Cola A Cola B Cola C Pepsi Sprite{Colors.END}
{Colors.YELLOW}{'-'*80}{Colors.END}
{Colors.GREEN}Cola A{Colors.END} π΄ -1.234 π 0.156 π 0.089 π 0.234 π 0.123
{Colors.GREEN}Cola B{Colors.END} π 0.145 π΄ -1.156 π 0.167 π 0.198 π 0.134
{Colors.GREEN}Cola C{Colors.END} π 0.098 π 0.123 π΄ -1.089 π 0.156 π 0.145
{Colors.BLUE}Pepsi{Colors.END} π 0.234 π 0.198 π 0.156 π΄ -1.201 π 0.167
{Colors.BLUE}Sprite{Colors.END} π 0.123 π 0.134 π 0.145 π 0.167 π΄ -1.167
{Colors.YELLOW}{'='*80}{Colors.END}
{Colors.BOLD}π Legend:{Colors.END}
{Colors.RED}π΄ High own-price sensitivity{Colors.END}
{Colors.GREEN}π Substitutes (positive cross-price){Colors.END}
{Colors.BLUE}π Complements (negative cross-price){Colors.END}
{Colors.BOLD}π‘ Portfolio Insights:{Colors.END}
β’ All products are substitutes (positive cross-price elasticities)
β’ Cola brands compete most with each other
β’ Pepsi and Sprite show moderate substitution
β’ Price changes in one product affect others significantly
"""
return matrix
def create_demo_heterogeneity_chart():
"""Create a demo heterogeneity chart."""
chart = f"""
{Colors.BOLD}{Colors.CYAN}π₯ DEMO: CUSTOMER HETEROGENEITY ANALYSIS{Colors.END}
{Colors.YELLOW}{'='*60}{Colors.END}
{Colors.BOLD}π Price Sensitivity by Customer Segment:{Colors.END}
{Colors.RED}High Income (>$75k):{Colors.END}
π΄ Elasticity: -0.856 (Low sensitivity)
π‘ Premium pricing strategies effective
{Colors.YELLOW}Medium Income ($35k-$75k):{Colors.END}
π‘ Elasticity: -1.234 (Moderate sensitivity)
π‘ Balanced pricing approach recommended
{Colors.GREEN}Low Income (<$35k):{Colors.END}
π΄ Elasticity: -1.567 (High sensitivity)
π‘ Promotional pricing drives volume
{Colors.BOLD}π Geographic Segmentation:{Colors.END}
{Colors.BLUE}Urban Areas:{Colors.END}
π΅ Elasticity: -1.089 (Moderate sensitivity)
π‘ Focus on convenience and quality
{Colors.MAGENTA}Rural Areas:{Colors.END}
π΄ Elasticity: -1.456 (High sensitivity)
π‘ Price-based strategies more effective
{Colors.YELLOW}{'='*60}{Colors.END}
{Colors.BOLD}π― Strategic Recommendations:{Colors.END}
β’ Implement income-based pricing tiers
β’ Use geographic pricing strategies
β’ Target high-income segments with premium products
β’ Focus promotions on price-sensitive segments
"""
return chart
def run_demo():
"""Run the demo."""
console = Console()
# Banner
banner = f"""
{Colors.CYAN}{Colors.BOLD}
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β β
β π― ELASTICITY ANALYSIS CLI DEMO FOR MARKETING MANAGERS π― β
β β
β π Interactive Command-Line Interface with Colorful Visualizations β
β π Powered by Rich Python Library β
β π‘ Marketing-Friendly Explanations and Business Insights β
β β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
{Colors.END}
"""
console.print(banner)
# Demo sections
demos = [
("Elasticity Analysis", create_demo_elasticity_chart),
("Cross-Price Matrix", create_demo_cross_price_matrix),
("Customer Heterogeneity", create_demo_heterogeneity_chart)
]
for title, demo_func in demos:
console.print(f"\n[bold cyan]π {title} Demo[/bold cyan]")
with Progress(
SpinnerColumn(),
TextColumn("[progress.description]{task.description}"),
console=console,
) as progress:
task = progress.add_task(f"Generating {title.lower()}...", total=None)
time.sleep(1) # Simulate processing
progress.update(task, description=f"β
{title} demo ready!")
# Display the demo
demo_content = demo_func()
console.print(demo_content)
input(f"\n[bold blue]Press Enter to continue to next demo...[/bold blue]")
# Final message
final_panel = Panel(
"[bold green]π Demo Complete![/bold green]\n\n"
"You've seen examples of:\n"
"β’ Colorful ASCII elasticity charts\n"
"β’ Cross-price substitution matrices\n"
"β’ Customer heterogeneity analysis\n"
"β’ Business insights and recommendations\n\n"
"To run the full CLI tools:\n"
"β’ python example_econml_cli.py\n"
"β’ python example_pyblp_cli.py\n"
"β’ python example_all_methods_cli.py\n\n"
"These tools provide interactive analysis with real data!",
title="π Next Steps",
border_style="green",
padding=(1, 2)
)
console.print(final_panel)
if __name__ == "__main__":
try:
run_demo()
except KeyboardInterrupt:
print(f"\n{Colors.YELLOW}π Demo interrupted by user. Goodbye!{Colors.END}")
except Exception as e:
print(f"\n{Colors.RED}β Error: {e}{Colors.END}")