File size: 6,782 Bytes
bb4e28f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8e6aa10
bb4e28f
 
 
 
8e6aa10
bb4e28f
 
 
 
 
 
 
 
 
8e6aa10
bb4e28f
 
 
 
 
 
 
 
 
 
 
 
 
8e6aa10
bb4e28f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8e6aa10
bb4e28f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8e6aa10
bb4e28f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8e6aa10
bb4e28f
 
 
8e6aa10
bb4e28f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8e6aa10
bb4e28f
 
 
8e6aa10
bb4e28f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8e6aa10
bb4e28f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import sys
import os
import streamlit as st
import pandas as pd

sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))

from agents.equity_analyst import answer_equity_question
from agents.news_summarizer import summarize_market_news
from agents.macro_strategist import analyze_macro_trends
from agents.quant_backtester import run_simple_backtest
from agents.regu_radar import monitor_regulatory_changes
from agents.client_advisor import advise_client

st.set_page_config(page_title="FinSightX", layout="wide")

st.title("FinSightX: AI-Powered Financial Agent Suite")

agent = st.sidebar.selectbox(
    "Choose Agent",
    [
        "Home",
        "Equity Analyst",
        "News Summarizer",
        "Macro Strategist",
        "Quant Backtester",
        "ReguRadar",
        "Client Advisor"
    ]
)

if agent == "Home":
    st.header("A Multi-Agent Financial Intelligence Assistant")
    st.markdown("""
    A **modular industry-grade application** where agents collaborate to handle:

    - **Equity Research**
    - **News Summarization**
    - **Macroeconomic Analysis**
    - **Quantitative Backtesting**
    - **Regulatory Updates**
    - **Client Portfolio Q&A**
    """)

elif agent == "Equity Analyst":
    st.subheader("Equity Analyst")
    st.markdown("""
    ### Role:
    Analyzes individual stocks or companies using:
    - Financial filings (e.g., 10-K, 10-Q)
    - Earnings call summaries
    - Market sentiment

    ### Capabilities:
    - Retrieve documents from a knowledge base using **AutoRAG**
    - Run sentiment analysis (FinBERT)
    - Generate insight using LLM (Groq Mistral)
    - Summarize risks, opportunities, and outlook

    ### Example Use Cases:
    - "What’s the market sentiment around Tesla this quarter?"
    - "Give me an analysis of Apple’s earnings call."
    """)
    query = st.text_input("Enter your financial query about a stock or company:")
    if st.button("Analyze"):
        with st.spinner("Analyzing equity..."):
            response = answer_equity_question(query)
        st.markdown(response)

elif agent == "News Summarizer":
    st.subheader("News Summarizer")
    st.markdown("""
    ### Role:
    Digest and summarize **real-time or bulk market news** to extract insights and relevance.

    ### Capabilities:
    - Accept raw headlines or long-form articles
    - Retrieve context (e.g., related documents or sectors)
    - Summarize using LLM (via Groq or fallback)

    ### Use Cases:
    - "Summarize today’s financial news relevant to energy stocks."
    - "Give me a brief on Nvidia's latest product announcement."
    """)
    news = st.text_area("Paste financial news or headlines:")
    if st.button("Summarize News"):
        with st.spinner("Summarizing..."):
            summary = summarize_market_news(news)
        st.markdown(summary)

elif agent == "Macro Strategist":
    st.subheader("Macro Trend Forecaster")
    st.markdown("""
    ### Role:
    Analyzes **macroeconomic indicators** and helps in trend forecasting.

    ### Capabilities:
    - Forecasts economic time series (CPI, GDP, unemployment) using `neuralprophet`
    - Returns structured future outlooks
    - Used in multi-agent reasoning for “market climate”

    ### Use Cases:
    - "Forecast US inflation for the next 3 months."
    - "What does the GDP trend look like post-2023?"
    """)
    st.markdown("Upload a time series CSV with columns `ds` (date) and `y` (value).")
    uploaded_file = st.file_uploader("Upload CSV", type=["csv"])
    if uploaded_file:
        df = pd.read_csv(uploaded_file)
        if st.button("Forecast"):
            with st.spinner("Forecasting..."):
                forecast_result = analyze_macro_trends(df)
            st.write("Forecasted Value:")
            st.json(forecast_result)

elif agent == "Quant Backtester":
    st.subheader("Quant Strategy Backtester")
    st.markdown("""
    ### Role:
    Tests trading strategies on historical price data.

    ### Capabilities:
    - Define and run strategies using `bt` or `vectorbt`
    - Simple moving average crossovers, rebalancing, etc.
    - Return backtest performance metrics

    ### Use Cases:
    - "Backtest an SMA crossover on AAPL from 2020 to 2023."
    - "Run a balanced ETF strategy on SPY, QQQ, and VTI."

    > This agent focuses on backtesting, not execution or portfolio construction (those can be added later).
    """)
    tickers = st.text_input("Enter tickers (comma-separated)", value="AAPL,MSFT")
    sma_short = st.number_input("Short SMA", value=20)
    sma_long = st.number_input("Long SMA", value=50)
    if st.button("Run Backtest"):
        with st.spinner("Backtesting strategy..."):
            result = run_simple_backtest(
                tickers=[t.strip() for t in tickers.split(",")],
                sma_short=sma_short,
                sma_long=sma_long
            )
        st.write("Backtest completed. Check your terminal/logs for output.")
        st.markdown("Note: Visual performance plots not yet integrated in Streamlit.")

elif agent == "ReguRadar":
    st.subheader("ReguRadar – Regulatory Monitor")
    st.markdown("""
    ### Role:
    Monitors and interprets **regulatory updates** that may affect sectors, firms, or compliance requirements.

    ### Capabilities:
    - AutoRAG over legal and regulatory filings (e.g., RBI circulars, SEC rules)
    - LLM summarization to extract impact
    - Optional: track historical regulatory shifts

    ### Use Cases:
    - "Has the RBI changed anything that affects crypto investors?"
    - "Summarize the SEC’s latest ESG compliance memo."
    """)
    reg_query = st.text_area("Paste a regulatory update or query:")
    if st.button("Analyze Regulation"):
        with st.spinner("Scanning for relevance..."):
            reg_response = monitor_regulatory_changes(reg_query)
        st.markdown(reg_response)

elif agent == "Client Advisor":
    st.subheader("Client Advisor")
    st.markdown("""
    ### Role:
    Acts as a **virtual financial advisor**, helping individual users based on their queries and emotional tone.

    ### Capabilities:
    - Understand user intent + emotion using FinBERT
    - Generate personalized advice using Groq LLM
    - Can be expanded into user profile tracking (e.g., risk appetite, goals)

    ### Use Cases:
    - "Should I invest in tech during a recession? I’m scared of losing money."
    - "I’ve retired and need a low-risk investment plan."

    > In the future, this can evolve into a memory-based portfolio coach.
    """)
    user_msg = st.text_area("What does your client say?")
    if st.button("Advise"):
        with st.spinner("Analyzing sentiment and crafting advice..."):
            advice = advise_client(user_msg)
        st.markdown(advice)