eshan6704 commited on
Commit
2df3369
·
verified ·
1 Parent(s): 75487aa

Create index.py

Browse files
Files changed (1) hide show
  1. index.py +61 -0
index.py ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import io
2
+ import requests
3
+ import pandas as pd
4
+ import yfinance as yf
5
+ from datetime import datetime, timedelta
6
+
7
+ from common import html_card, wrap_html
8
+ from ta_indi_pat import talib_df
9
+
10
+
11
+ def nifty50_daily(max_rows=200):
12
+ """
13
+ Fetch NIFTY 50 (^NSEI) 1-year OHLCV data from Yahoo Finance,
14
+ add TA-Lib indicators + candlestick patterns,
15
+ return HTML table inside a scrollable container.
16
+ """
17
+
18
+ try:
19
+ # ----------------------------------
20
+ # Fetch NIFTY 50 data
21
+ # ----------------------------------
22
+ df = yf.download("^NSEI", period="1y", interval="1d").round(2)
23
+
24
+ if df.empty:
25
+ return html_card("Error", "No data found for NIFTY 50 (^NSEI).")
26
+
27
+ # Standardize column names
28
+ df.columns = ["Close", "High", "Low", "Open", "Volume"]
29
+ df.reset_index(inplace=True) # make Date a column
30
+
31
+ # Limit display rows
32
+ df_display = df.head(max_rows)
33
+
34
+ # ----------------------------------
35
+ # Generate TA-Lib indicators
36
+ # ----------------------------------
37
+ combined_df = talib_df(df_display)
38
+
39
+ # ----------------------------------
40
+ # Convert to HTML
41
+ # ----------------------------------
42
+ table_html = combined_df.to_html(
43
+ classes="table table-striped table-bordered",
44
+ index=False
45
+ )
46
+
47
+ scrollable_html = f"""
48
+ <div style="overflow-x:auto; overflow-y:auto; max-height:650px; border:1px solid #ccc; padding:8px;">
49
+ {table_html}
50
+ </div>
51
+ """
52
+
53
+ content = f"""
54
+ <h2>NIFTY 50 (^NSEI) — Daily (OHLCV + Indicators + Patterns)</h2>
55
+ {html_card("Technical Analysis Table", scrollable_html)}
56
+ """
57
+
58
+ return wrap_html(content, title="NIFTY 50 Daily Data")
59
+
60
+ except Exception as e:
61
+ return html_card("Error", str(e))