File size: 14,726 Bytes
59e2ce6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
def render_decision_simulator(startup_data):
    """
    Render the AI-powered decision simulator page.
    
    This feature helps startup founders test the financial impact of business
    decisions before implementing them, using AI to analyze risks and benefits.
    """
    st.markdown("<h1 class='main-header'>Decision Simulator</h1>", unsafe_allow_html=True)
    st.markdown("<p class='sub-header'>AI-powered analysis of business decisions</p>", unsafe_allow_html=True)
    
    # How AI helps with decision-making
    with st.expander("ℹ️ How AI enhances your decision-making"):
        st.markdown("""
        ### How AI Powers Your Decision Simulator
        
        The decision simulator uses AI to help you make better strategic decisions:
        
        - **Scenario Analysis**: Our AI model simulates multiple financial scenarios based on your input variables
        - **Risk Assessment**: The system automatically evaluates risk levels based on your cash runway and growth metrics
        - **Return Prediction**: AI algorithms predict potential returns on investments like hiring or marketing
        - **Opportunity Cost Analysis**: The model compares different allocations of capital to maximize growth
        - **Personalized Recommendations**: Based on your specific situation, the AI provides tailored alternatives
        
        This helps founders make data-driven decisions with less guesswork, avoid costly mistakes, and optimize resource allocation.
        """)
    
    st.write("Test the financial impact of key business decisions before implementing them. Our AI advisor will analyze the risks and benefits.")
    
    # Quick decision templates
    st.subheader("Common Scenarios")
    
    decision_templates = {
        "Hiring Engineering Team": {
            "description": "Evaluate the impact of growing your engineering team",
            "new_hires": 3,
            "new_marketing": 0,
            "other_expenses": 2000,
            "growth_impact": 0.02,
            "question": "We're considering hiring 3 more engineers to accelerate product development. How will this affect our runway and what growth impact should we expect to justify this investment?"
        },
        "Marketing Expansion": {
            "description": "Test increasing your marketing budget",
            "new_hires": 0,
            "new_marketing": 15000,
            "other_expenses": 0,
            "growth_impact": 0.04,
            "question": "We want to increase our marketing spend by $15K/month to drive growth. What growth rate would we need to achieve to make this financially viable?"
        },
        "Office Expansion": {
            "description": "Analyze the cost of moving to a larger office",
            "new_hires": 0,
            "new_marketing": 0,
            "other_expenses": 8000,
            "growth_impact": 0.01,
            "question": "We're considering moving to a larger office space that would add $8K/month to our expenses. Is this justified at our current stage?"
        },
        "Custom Scenario": {
            "description": "Create your own custom scenario",
            "new_hires": 0,
            "new_marketing": 0,
            "other_expenses": 0,
            "growth_impact": 0.0,
            "question": ""
        }
    }
    
    # Template selection
    template_cols = st.columns(4)
    selected_template = None
    
    for i, (template_name, template) in enumerate(decision_templates.items()):
        with template_cols[i]:
            if st.button(f"{template_name}\n{template['description']}", key=f"template_{i}"):
                selected_template = template_name
    
    # Initialize form values based on selected template
    if selected_template and selected_template != "Custom Scenario":
        new_hires = decision_templates[selected_template]["new_hires"]
        new_marketing = decision_templates[selected_template]["new_marketing"]
        other_expenses = decision_templates[selected_template]["other_expenses"]
        growth_impact = decision_templates[selected_template]["growth_impact"]
        question = decision_templates[selected_template]["question"]
    else:
        new_hires = 0
        new_marketing = 0
        other_expenses = 0
        growth_impact = 0.0
        question = ""
    
    # Decision input form
    with st.form("decision_form"):
        st.subheader("Scenario Parameters")
        
        col1, col2 = st.columns(2)
        
        with col1:
            new_hires = st.number_input("New Engineering Hires", min_value=0, max_value=10, value=new_hires, 
                                       help=f"Each engineer costs ${ENGINEER_SALARY:,} per month")
            st.caption(f"Monthly Cost: ${new_hires * ENGINEER_SALARY:,}")
            
            new_marketing = st.number_input("Additional Monthly Marketing Budget", 
                                           min_value=0, max_value=50000, value=new_marketing, step=1000,
                                           help="Additional marketing spend per month")
        
        with col2:
            other_expenses = st.number_input("Other Additional Monthly Expenses", 
                                            min_value=0, max_value=50000, value=other_expenses, step=1000,
                                            help="Any other additional monthly expenses")
            
            growth_impact = st.slider("Estimated Impact on Monthly Growth Rate", 
                                     min_value=0.0, max_value=0.10, value=growth_impact, step=0.01, 
                                     format="%.2f",
                                     help="Estimated increase in monthly growth rate due to these investments")
            st.caption(f"New Growth Rate: {(startup_data['growth_rate'] + growth_impact) * 100:.1f}% (current: {startup_data['growth_rate'] * 100:.1f}%)")
        
        question = st.text_area("Describe your decision scenario", 
                               value=question,
                               height=100, 
                               placeholder="E.g., We're considering hiring two more engineers and increasing our marketing budget...")
        
        decision_summary = f"""
        - {new_hires} new engineers: ${new_hires * ENGINEER_SALARY:,}/month
        - Marketing increase: ${new_marketing:,}/month
        - Other expenses: ${other_expenses:,}/month
        - Total additional burn: ${new_hires * ENGINEER_SALARY + new_marketing + other_expenses:,}/month
        - Growth impact: +{growth_impact * 100:.1f}% monthly growth
        """
        
        st.markdown(f"**Decision Summary:**\n{decision_summary}")
        
        submitted = st.form_submit_button("Simulate Decision")
    
    if submitted:
        # Calculate current and new runway
        current_runway, new_runway, current_df, new_df = simulate_decision(
            startup_data['cash'],
            startup_data['burn_rate'],
            startup_data['revenue'],
            startup_data['growth_rate'],
            other_expenses,
            new_hires,
            new_marketing,
            growth_impact
        )
        
        # Display results
        st.markdown("<h3>Decision Impact Analysis</h3>", unsafe_allow_html=True)
        
        # Summary metrics
        col1, col2, col3 = st.columns(3)
        
        with col1:
            st.metric("Current Runway", f"{current_runway} months")
        with col2:
            runway_change = new_runway - current_runway
            st.metric("New Runway", f"{new_runway} months", 
                     delta=f"{runway_change} months", 
                     delta_color="off" if runway_change == 0 else ("normal" if runway_change > 0 else "inverse"))
        with col3:
            new_burn = startup_data['burn_rate'] + other_expenses + (new_hires * ENGINEER_SALARY) + new_marketing
            burn_change = new_burn - startup_data['burn_rate']
            burn_percentage = burn_change / startup_data['burn_rate'] * 100
            st.metric("New Monthly Burn", f"${new_burn:,}", 
                     delta=f"${burn_change:,} ({burn_percentage:.1f}%)", 
                     delta_color="inverse")
        
        # Cash projection comparison
        st.subheader("Cash Projection Comparison")
        
        # Combine dataframes for comparison
        current_df['Scenario'] = 'Current'
        new_df['Scenario'] = 'After Decision'
        
        combined_df = pd.concat([current_df, new_df])
        combined_df = combined_df.reset_index()
        combined_df = combined_df.rename(columns={'index': 'Date'})
        
        # Plot comparison
        fig = px.line(combined_df, x='Date', y='Cumulative_Cash', color='Scenario',
                     title="Cash Runway Comparison",
                     labels={'Cumulative_Cash': 'Remaining Cash'},
                     color_discrete_sequence=['#4c78a8', '#f58518'])
        
        fig.add_hline(y=0, line_dash="dash", line_color="red", annotation_text="Out of Cash")
        
        fig.update_layout(
            height=400,
            plot_bgcolor='rgba(240,247,255,0.8)',
            xaxis_title="Date",
            yaxis_title="Cash Balance ($)",
            font=dict(family="Arial, sans-serif", size=12),
            margin=dict(l=20, r=20, t=40, b=20),
        )
        
        st.plotly_chart(fig, use_container_width=True)
        
        # Get AI analysis
        if question:
            decision_params = {
                "new_hires": new_hires,
                "new_marketing": new_marketing,
                "other_expenses": other_expenses,
                "growth_impact": growth_impact
            }
            
            analysis = get_decision_analysis(question, startup_data, decision_params)
            
            st.markdown("<div class='advisor-card'>", unsafe_allow_html=True)
            st.markdown("<span class='ai-badge'>AI Decision Analysis</span>", unsafe_allow_html=True)
            st.markdown(f"<p class='advice-text'>{analysis}</p>", unsafe_allow_html=True)
            st.markdown("</div>", unsafe_allow_html=True)
            
            # Break down impacts of each component
            st.subheader("Component Impact Analysis")
            
            # Calculate the impact of each component in isolation
            _, hiring_runway, _, _ = simulate_decision(
                startup_data['cash'],
                startup_data['burn_rate'],
                startup_data['revenue'],
                startup_data['growth_rate'],
                0,
                new_hires,
                0,
                0
            )
            
            _, marketing_runway, _, _ = simulate_decision(
                startup_data['cash'],
                startup_data['burn_rate'],
                startup_data['revenue'],
                startup_data['growth_rate'],
                0,
                0,
                new_marketing,
                growth_impact
            )
            
            _, expenses_runway, _, _ = simulate_decision(
                startup_data['cash'],
                startup_data['burn_rate'],
                startup_data['revenue'],
                startup_data['growth_rate'],
                other_expenses,
                0,
                0,
                0
            )
            
            component_data = {
                "Component": ["Engineering Hires", "Marketing Increase", "Other Expenses", "Combined Impact"],
                "Runway Impact (months)": [
                    hiring_runway - current_runway,
                    marketing_runway - current_runway,
                    expenses_runway - current_runway,
                    new_runway - current_runway
                ]
            }
            
            component_df = pd.DataFrame(component_data)
            
            fig = px.bar(component_df, x='Component', y='Runway Impact (months)',
                        title="Impact of Each Component on Runway",
                        color='Runway Impact (months)',
                        color_continuous_scale=['#dc3545', '#ffc107', '#28a745'],
                        text='Runway Impact (months)')
            
            fig.update_layout(
                height=400,
                plot_bgcolor='rgba(240,247,255,0.8)',
                font=dict(family="Arial, sans-serif", size=12),
                margin=dict(l=20, r=20, t=40, b=20),
            )
            
            fig.update_traces(texttemplate='%{text:.1f}', textposition='outside')
            st.plotly_chart(fig, use_container_width=True)
            
            # Risk assessment
            risk_level = "High" if new_runway < 3 else ("Medium" if new_runway < 6 else "Low")
            risk_color = "danger-metric" if risk_level == "High" else ("warning-metric" if risk_level == "Medium" else "good-metric")
            
            st.markdown(f"""
            <div class='metric-card'>
                <p class='metric-label'>Risk Assessment</p>
                <p class='metric-value {risk_color}'>{risk_level} Risk Decision</p>
                <p>This decision would give you {new_runway} months of runway.</p>
            </div>
            """, unsafe_allow_html=True)
            
            # Recommendations
            st.info("💡 **Want personalized guidance on this decision?** [Book a session](#book-a-session) with our AI financial advisor for detailed analysis.")

def get_decision_analysis(question, financial_data, decision_params):
    """Get AI analysis for a specific business decision."""
    prompt = f"""
    You are a financial advisor for startups. A founder asks:
    "{question}"

    Here's their current financial situation:
    - Current cash: ${financial_data['cash']}
    - Monthly burn rate: ${financial_data['burn_rate']}
    - Monthly revenue: ${financial_data['revenue']}
    - Monthly growth rate: {financial_data['growth_rate'] * 100}%
    
    They're considering these changes:
    - Adding {decision_params['new_hires']} new engineers (${ENGINEER_SALARY}/month each)
    - Increasing marketing budget by ${decision_params['new_marketing']}/month
    - Adding ${decision_params['other_expenses']}/month in other expenses
    - Expecting {decision_params['growth_impact'] * 100}% additional monthly growth

    Analyze this decision thoroughly:
    1. Quantify the impact on runway (exact calculation)
    2. Assess the risk level (low, medium, high)
    3. Compare the ROI potential
    4. Provide 3 specific recommendations or alternatives
    5. Suggest timeline and milestones for implementation if approved

    Be direct and specific with numbers and timeframes.
    """
    
    return generate_ai_response(prompt)