File size: 4,687 Bytes
5b3602b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# ---------------- CONFIG ----------------
# This file contains all static configuration data for the application.

CRISIS_PERIODS = {
    "2008 Global Financial Crisis (India)": ("2008-01-01", "2009-03-31"),
    "COVID-19 Crash (India)": ("2020-02-01", "2020-11-30"),
    "Demonetization Shock (2016)": ("2016-11-01", "2017-02-28"),
    "IL&FS Debt Crisis (2018)": ("2018-08-01", "2018-12-31"),
    "Ketan Parekh / Dot-com Burst (India)": ("2000-03-01", "2001-09-30"),
}

BENCHMARK_TICKER = "^NSEI"
BENCHMARK_NAME = "NIFTY 50"
RECOVERY_DAYS = 90

CRISIS_SUMMARY = {
    "2008 Global Financial Crisis (India)": "Global credit and liquidity crisis; banks and financials hit hard; heavy foreign outflows.",
    "COVID-19 Crash (India)": "Rapid market fall in Mar 2020 due to pandemic lockdowns; tech & pharma were more resilient.",
    "Demonetization Shock (2016)": "Policy shock in Nov 2016 causing short-term consumption & liquidity effects.",
    "IL&FS Debt Crisis (2018)": "Infrastructure debt/default scare leading to liquidity risk concerns for NBFCs and financials.",
    "Ketan Parekh / Dot-com Burst (India)": "Late 1990s / early 2000s Indian IT/tech boom and subsequent bust after financial irregularities.",
}

CRISIS_INSIGHTS = {
    "COVID-19 Crash (India)": {
        "Information Technology": "IT companies showed resilience as global digital adoption rose; services exports continued.",
        "Banks": "Banks faced short-term credit stress and moratoriums; credit growth slowed.",
        "Energy": "Lower demand due to lockdowns hit energy & fuel consumption.",
        "Pharmaceuticals": "Pharma and healthcare often outperformed due to demand for medical supplies.",
    },
    "2008 Global Financial Crisis (India)": {
        "Finance": "Banks and NBFCs suffered due to global liquidity freeze and foreign capital outflows.",
        "Metals & Mining": "Commodity demand slump affected exporters and metal companies.",
    },
    "Demonetization Shock (2016)": {
        "Consumer Discretionary": "Spending fell short-term; small businesses faced cash shortages.",
        "Banking": "Short-term spike in deposits but transactional disruption.",
    },
    "IL&FS Debt Crisis (2018)": {
        "Financial Services": "NBFCs and related sectors were directly impacted due to counterparty risk.",
    },
    "Ketan Parekh / Dot-com Burst (India)": {
        "Information Technology": "Large re-rating and correction after speculative run-up in tech/IT names.",
    },
}

EXAMPLE_PORTFOLIOS = {
    "Large-Cap (Default)": {
        "tickers": "RELIANCE.NS, TCS.NS, HDFCBANK.NS",
        "weights": "0.4, 0.3, 0.3",
    },
    "IT / Tech Focus": {
        "tickers": "TCS.NS, INFY.NS, WIPRO.NS, HCLTECH.NS",
        "weights": "0.3, 0.3, 0.2, 0.2",
    },
    "Banking Focus": {
        "tickers": "HDFCBANK.NS, ICICIBANK.NS, SBIN.NS, KOTAKBANK.NS",
        "weights": "0.3, 0.3, 0.2, 0.2",
    },
    "Diversified (Mock)": {
        "tickers": "RELIANCE.NS, HDFCBANK.NS, INFY.NS, HINDUNILVR.NS, ITC.NS",
        "weights": "0.2, 0.2, 0.2, 0.2, 0.2",
    },
    "Pharma Focus": {
        "tickers": "SUNPHARMA.NS, DRREDDY.NS, CIPLA.NS, DIVISLAB.NS",
        "weights": "0.25, 0.25, 0.25, 0.25",
    },
    "Select Example...": {"tickers": "", "weights": ""},  # Placeholder
}

# -------------------------
# Gemini / LLM Config
# -------------------------
GEMINI_MODEL_NAME = "gemini-2.0-flash-lite-001"

GEMINI_SYSTEM_PROMPT = """

You are a senior Indian equity and portfolio analyst.

You explain historical crisis behaviour of portfolios in short, clear bullet-point insights.



Guidelines:

- Focus on Indian equity context and the specific crisis mentioned.

- Use simple language but keep it financially accurate.

- Use only the metrics scorecard provided (no assumptions about individual sectors or stocks).

- Be concise: 5–7 bullet points, maximum ~200 words.

- Avoid giving investment advice; stay descriptive and educational.

"""

GEMINI_USER_PROMPT_TEMPLATE = """

You are analysing how an investor's portfolio behaved during the historical crisis: {crisis_name}.



Here is a scorecard comparing their portfolio vs NIFTY during that crisis window:



{metrics_text}



TASK:

- Write 5–7 short bullet points.

- Explain:

  - How the portfolio did vs NIFTY overall.

  - What the volatility and max drawdown imply.

  - Whether the portfolio looked relatively resilient or vulnerable in that period.

- Keep it under 200 words.

- Do NOT mention that you are an AI model or talk about prompts.



Extra style/emphasis from the user (if any):

{extra_instructions}

"""