eshan6704 commited on
Commit
3f54611
·
verified ·
1 Parent(s): 9f3fbf8

Update daily.py

Browse files
Files changed (1) hide show
  1. daily.py +22 -25
daily.py CHANGED
@@ -1,40 +1,37 @@
1
  # daily.py
2
- import yfinance as yf
3
  import pandas as pd
4
- from common import wrap_html, make_table
 
 
5
  from chart_builder import build_chart
6
 
7
- # ============================================================
8
- # DAILY DATA PROCESSING
9
- # ============================================================
10
-
11
- def fetch_daily(symbol, indicators=None):
12
  """
13
- Fetch daily data for 1 year, apply indicators, and return full HTML.
 
14
  """
15
- yfsymbol = f"{symbol}.NS"
16
  try:
17
- # Fetch 1-year daily data
18
- df = yf.download(yfsymbol, period="1y", interval="1d").round(2)
 
 
19
  if df.empty:
20
- return wrap_html(f"<h1>No daily data available for {symbol}</h1>")
21
 
22
- # Reset MultiIndex if exists
23
- if isinstance(df.columns, pd.MultiIndex):
24
- df.columns = df.columns.get_level_values(0)
25
 
26
- # Build chart with optional indicators
27
- chart_html = build_chart(df, indicators=['macd','supertrend','keltner','zigzag','swing','stockstick'])
28
 
29
- #chart_html = build_chart(df, indicators=indicators, volume=True)
 
30
 
31
- # Format last 30 rows for table
32
- table_html = make_table(df.tail(30))
33
 
34
- # Wrap in full HTML
35
- full_html = wrap_html(f"{chart_html}<h2>Recent Daily Data (last 30 rows)</h2>{table_html}",
36
- title=f"Daily Data for {symbol}")
37
- return full_html
38
 
39
  except Exception as e:
40
- return wrap_html(f"<h1>Error fetching daily data for {symbol}</h1><p>{str(e)}</p>")
 
1
  # daily.py
 
2
  import pandas as pd
3
+ import yfinance as yf
4
+ from common import wrap_html, html_error, clean_df, make_table
5
+ from indicater import calculate_indicators
6
  from chart_builder import build_chart
7
 
8
+ def fetch_daily(symbol):
 
 
 
 
9
  """
10
+ Fetches daily OHLCV data, calculates indicators, builds chart,
11
+ and returns the complete HTML for Gradio UI.
12
  """
 
13
  try:
14
+ yfsymbol = symbol + ".NS"
15
+
16
+ # ---------------- Fetch daily data ----------------
17
+ df = yf.download(yfsymbol, period="6mo", interval="1d")
18
  if df.empty:
19
+ return html_error(f"No daily data found for {symbol}")
20
 
21
+ df = clean_df(df)
 
 
22
 
23
+ # ---------------- Calculate indicators ----------------
24
+ indicators = calculate_indicators(df)
25
 
26
+ # ---------------- Build chart ----------------
27
+ html_chart = build_chart(df, indicators)
28
 
29
+ # ---------------- Build table ----------------
30
+ table_html = make_table(df)
31
 
32
+ # ---------------- Wrap into full HTML ----------------
33
+ html = wrap_html(f"{html_chart}<br>{table_html}", title=f"{symbol} Daily Chart")
34
+ return html
 
35
 
36
  except Exception as e:
37
+ return html_error(f"Error generating daily chart for {symbol}: {e}")