<output id="qn6qe"></output>

    1. <output id="qn6qe"><tt id="qn6qe"></tt></output>
    2. <strike id="qn6qe"></strike>

      亚洲 日本 欧洲 欧美 视频,日韩中文字幕有码av,一本一道av中文字幕无码,国产线播放免费人成视频播放,人妻少妇偷人无码视频,日夜啪啪一区二区三区,国产尤物精品自在拍视频首页,久热这里只有精品12
      TOP

      市場寬度實時定時版

      from jqdata import *
      import datetime as dt
      import numpy as np
      import pandas as pd
      import seaborn as sns
      import matplotlib.pyplot as plt
      import json, textwrap
      
      # 獲取股票和價格數據
      stocks = get_index_stocks("000985.XSHG")
      now = dt.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
      yesterday = (dt.datetime.now() - dt.timedelta(days=1)).strftime("%Y-%m-%d")
      
      count = 90  #1年的交易日
      price_hist = get_price(stocks,end_date=yesterday,frequency="1d",fields=["close"],count=count + 19,panel=False)
      
      
      # 獲取行業信息
      def getStockIndustry(stocks):
          industry = get_industry(stocks)
          dict = {
              stock: info["sw_l1"]["industry_name"]
              for stock, info in industry.items()
              if "sw_l1" in info
          }
          industry_2_stock = {}
          for stock, info in industry.items():
              if "sw_l1" in info:
                  industry_name = info["sw_l1"]["industry_name"]
                  ls = industry_2_stock.get(industry_name, [])
                  ls.append(stock)
                  industry_2_stock[industry_name] = ls
          return pd.Series(dict), industry_2_stock
      
      
      def update_price():
          cur_price = get_price(stocks,end_date=now,frequency="1m",fields=["close"],count=1,panel=False)
          cur_price['time'] = pd.to_datetime(cur_price['time']).dt.floor('d')
          new_price = pd.concat([price_hist, cur_price], ignore_index=True)
          new_price= new_price.sort_values(['code', 'time']).reset_index(drop=True)
          return new_price
      
      
      def update_df():
          # 處理數據
          h = update_price()
          h["date"] = pd.DatetimeIndex(h.time).date
          df_close = h.pivot(index="code", columns="date", values="close").dropna(axis=0)
          df_ma20 = df_close.rolling(window=20, axis=1).mean().iloc[:, -count:]
          df_bias = df_close.iloc[:, -count:] > df_ma20
          df_bias["industry_name"], industry_2_stock = getStockIndustry(stocks)
          df_ratio = (
              (df_bias.groupby("industry_name").sum() * 100.0)
              / df_bias.groupby("industry_name").count()
          ).round()
          df_ratio.loc['合計'] = df_ratio.sum().astype("int32")
          DF = df_ratio.T
          return DF
      
      
      #======================================================================
      
      def update_html(DF):
          industry_cols = DF.columns[:-1]
          df = DF.iloc[:, :-1].copy()  # 創建數據框副本,避免修改原始數據
          df.insert(len(industry_cols), '市場平均', df[industry_cols].mean(axis=1).round().astype(int))
          df.index = pd.to_datetime(df.index)
          use_cols = [c for c in df.columns if c not in {'合計'}]
      
          # 1. 只保留 [x, y, value] 三元組給 ECharts
          data_js = [
              [j, i, int(df.iloc[i, j])]
              for i in range(len(df))
              for j in range(len(df.columns))
          ]
      #     print("data_js:", data_js)
      
          # 2. 行業名、日期單獨傳兩份數組,前端用索引去取
          cols   = df.columns.tolist()
      #     print("cols:", cols)
          dates  = [str(d) for d in df.index.date]
      #     print("dates:", dates)
      
          cell_w  = 40          # 每列寬 80 px
          cell_h  = 40          # 每行高 26 px(足夠看清文字)
          width   = len(use_cols) * cell_w    # 留邊給 visualMap
          height  = len(df)        * cell_h    # 隨行情自動增高
          # 寫進單文件 HTML
      
          html = textwrap.dedent(f'''\
          <!doctype html>
          <html>
          <head>
              <meta charset="utf-8"><title>行業熱力圖(可點擊)</title>
              <script src="https://cdn.jsdelivr.net/npm/echarts@5/dist/echarts.min.js"></script>
              <style>
                  #wrapper{{width:100%;max-height:70vh;overflow:auto;border:1px solid #ddd}}
                  #chart{{width:{width}px;height:{height}px;margin:auto}}
              </style>
          </head>
          <body>
          <div id="chart" style="width:{{width}}px;height:{{height}}px;margin:auto"></div>
          <script>
          const raw      = {json.dumps(data_js)};
          const cols     = {json.dumps(cols)};
          const dates    = {json.dumps(dates)};
          const myChart = echarts.init(document.getElementById('chart'));
      
          const option = {{
              tooltip: {{
                  position: 'top',
                  formatter: p => {{
                      const [x, y, val] = p.data;
                      return `${{dates[y]}}<br/>${{cols[x]}}: <b>${{val}}</b>`;
                  }}
              }},
              animation: true,
              grid: {{left: '10%', right: '5%', bottom: '5%', top: '2%'}},
              xAxis: {{
                  type: 'category',
                  data: cols,
                  position: 'top', 
                  axisLabel: {{interval: 0,rotate: 45,fontSize: 11}},
                  splitArea: {{show: true}}
              }},
              yAxis: {{
                  type: 'category',
                  data: dates,
                  splitArea: {{show: true}}
              }},
              visualMap: {{
                  min: 0, max: 100, calculable: true, type: 'continuous',
                  orient: 'horizontal', left: 'center', bottom: '2%',
                  inRange: {{color: [
                      '#005824','#238b45','#5cb85c','#90ee90','#ffff99',
                      '#ffaa99','#ff7d66','#f54437','#b00000'
                  ]}}
              }},
              series: [{{
                  name: '熱力圖',
                  type: 'heatmap',
                  data: raw,
                  label: {{show: true, fontSize: 11, color: '#000'}},
                  itemStyle: {{borderWidth: 1, borderColor: '#fff'}},
                  emphasis: {{itemStyle: {{shadowBlur: 12, shadowColor: 'rgba(0,0,0,.4'}}}}
              }}]
          }};
          myChart.setOption(option);
      
          // 點擊事件
          myChart.on('click', params => {{
              const [,,val,ind,dt] = params.data;
              alert(`${{dt}}\\n${{ind}}: ${{val}}`);
          }});
          </script>
          </body>
          </html>''')
      
          open('行業寬度-定時刷新版.html','w',encoding='utf-8').write(html)
          print("可以打開-行業寬度-定時刷新版.html")
      
      # 定時刷新 10分鐘一次
      while True:
          DF = update_df()
          update_html(DF)
          time.sleep(60 * 10) 
      
          

       

      posted @ 2025-10-09 14:21  羊駝之歌  閱讀(8)  評論(0)    收藏  舉報
      主站蜘蛛池模板: 天堂在线精品亚洲综合网| 国产成人亚洲老熟女精品| 蜜桃av无码免费看永久| 在线 | 国产精品99传媒a| 麻豆天美国产一区在线播放| 日韩欧美精品suv| 男人的天堂va在线无码| 亚洲性日韩精品一区二区三区| 亚洲三级香港三级久久| 野外做受三级视频| 2020年最新国产精品正在播放| 爆乳日韩尤物无码一区| 欧美极品色午夜在线视频| 人妻丝袜AV中文系列先锋影音| 亚洲中文字幕一区精品自| 狠狠色噜噜狠狠狠狠色综合久av| 无码人妻久久一区二区三区app| 99精品国产成人一区二区| 熟女亚洲综合精品伊人久久| 国产精品女在线观看| 国产欧亚州美日韩综合区| 人妻无码ΑV中文字幕久久琪琪布 国产乱人伦AV在线麻豆A | 中文字幕日本一区二区在线观看| 亚洲国产精品久久电影欧美| 久久这里只精品热免费99| 九九热在线视频观看这里只有精品| 99久久精品国产综合一区| 免费网站看V片在线毛| 国产成年码av片在线观看| 成人网站国产在线视频内射视频 | 国产精品v欧美精品∨日韩| 亚洲色偷偷色噜噜狠狠99| 蜜桃久久精品成人无码av| 久久久久国产精品熟女影院| 久久夜色精品国产亚洲av| 伊人色综合一区二区三区影院视频| 石原莉奈日韩一区二区三区| 波多野结衣免费一区视频| 国产爽视频一区二区三区| 午夜免费福利小电影| 免费观看欧美猛交视频黑人|