python_PyQt5运行股票研究python方法工具V1.1_增加表格展示控件

news2024/11/25 1:03:56

承接 【python_PyQt5运行股票研究python方法工具V1.0】

地址 python_PyQt5运行股票研究python方法工具V1.0_程序猿与金融与科技的博客-CSDN博客

目录

 结果展示:

 代码:

示例py文件代码(计算股票日横截面数据)

参数json文件

表格控件

ExcuteShowWidget 中 process_excute_event 方法修改


 结果展示:

1 选择py文件所在目录

2 选择py文件目录后,会提起该目录下所有的py文件,放入下拉列表

3 选择要执行的方法,点击“执行”,子线程会执行对应py文件中的代码,执行完毕后会返回结果

4 返回结果为map形式,map中的key用于识别不用结果分别对应什么内容,key会在下拉列表中展示,可以通过下拉列表切换,或上一个,下一个切换表格内容

5 显示执行结果内容

 代码:

示例py文件代码(计算股票日横截面数据)

def excute_code(json_obj:dict):
    '''
    横截面股票日数据查看
    :param json_obj:
    :return:
    '''
    import pandas as pd
    import os

    code_list = json_obj['code_list']
    daily_dir = json_obj['daily_dir']
    start_date = json_obj['start_date']
    end_date = json_obj['end_date']
    # second_level {行业名:[股票代码]}
    second_level = json_obj['second_level']

    res_target_name_map = {}

    df = None
    column_list = ['ticker','tradeDate','o','c','h','l','turnoverVol','dealAmount','turnoverRate','negMarketValue','marketValue','chgPct','PE']

    for code in code_list:
        daily_file_path = daily_dir + os.path.sep + code + '.csv'
        one_df = pd.read_csv(daily_file_path,encoding='utf-8')
        one_df['o_date'] = pd.to_datetime(one_df['tradeDate'])
        one_df = one_df.loc[(one_df['o_date'] >= start_date) & (one_df['o_date'] <= end_date)].copy()
        one_df = one_df.loc[one_df['openPrice'] > 0].copy()
        one_df['o'] = one_df['openPrice'] * one_df['accumAdjFactor']
        one_df['c'] = one_df['closePrice'] * one_df['accumAdjFactor']
        one_df['h'] = one_df['highestPrice'] * one_df['accumAdjFactor']
        one_df['l'] = one_df['lowestPrice'] * one_df['accumAdjFactor']
        one_df['chgPct'] = one_df['chgPct']*100

        one_df['ticker'] = code
        one_df.sort_values(by='o_date',ascending=False,inplace=True)

        one_df = one_df.loc[:,column_list]

        if df is None:
            df = one_df
        else:
            df = pd.concat([df,one_df])
        pass

    df_group = df.groupby(by='tradeDate')
    for name,group in df_group:
        key_name = f'{name},all'
        val_data = group.loc[:,column_list].values.tolist()
        res_target_name_map[key_name] = val_data
        pass

    for key,val in second_level.items():
        df_two = df.loc[df['ticker'].isin(val)].copy()
        df_two_group = df_two.groupby(by='tradeDate')
        for name, group in df_two_group:
            key_name = f'{name},{key}'
            val_data = group.loc[:, column_list].values.tolist()
            res_target_name_map[key_name] = val_data
            pass
        pass

    target_style = 'table'
    target_data = res_target_name_map
    header_list = ['ticker','日期','开盘价','收盘价','最高价','最低价','成交量','成交笔数','日换手率','流通市值','总市值','涨跌幅','滚动市盈率']

    final_map = {
        'target_style':target_style,
        'target_header':header_list,
        'target_data':target_data
    }
    return final_map

参数json文件

{
	"code_list":["000025","000031","000058","000061","000068","000096","000410","000428","000503","000509","000514","000523","000536","000548","000557","000558","000565","000566","000599","000605","000632","000638","000652","000655","000701","000709","000727","000755","000758","000767","000797","000825","000850","000856","000878","000897","000898","000901","000912","000927","000952","000958","000960","000972","001896","002022","002037","002047","002061","002097","002106","002114","002160","002168","002183","002217","002278","002285","002305","002339","002343","002344","002354","002366","002400","002427","002431","002479","002480","002500","002522","002542","002573","002642","002659","002672","002673","002676","002682","002712","002722","002783","002807","600022","600037","600058","600076","600100","600108","600115","600119","600149","600150","600156","600169","600198","600202","600239","600249","600287","600292","600299","600300","600307","600320","600322","600343","600358","600376","600397","600403","600423","600433","600448","600526","600550","600601","600604","600617","600623","600626","600629","600630","600637","600648","600649","600650","600651","600653","600675","600676","600679","600684","600686","600692","600705","600708","600712","600716","600726","600743","600748","600758","600783","600798","600800","600805","600815","600825","600844","600855","600864","600871","600874","600880","600881","600889","600939","600959","600960","600981","600986","601016","601106","601168","601198","601368","601588","601600","601718","601727","601766","601857","601866","601918","601989","601991","603021","603169","603817","603999"],
	"daily_dir":"E:/daily/",
	"start_date":"2023-07-01",
	"end_date":"2023-08-11",
	"second_level":{"\u4ea4\u901a\u8fd0\u8f93": ["000548", "000557", "000755", "002183", "002682", "600115", "600119", "600650", "600798", "601866"], "\u4f20\u5a92": ["002343", "002354", "002400", "002712", "600037", "600358", "600637", "600825", "600959", "600986", "603999"], "\u516c\u7528\u4e8b\u4e1a": ["000767", "001896", "002479", "002480", "600149", "600617", "600726", "601016", "601991"], "\u519c\u6797\u7267\u6e14": ["000972", "600108"], "\u533b\u836f\u751f\u7269": ["000566", "000952", "002022"], "\u5546\u8d38\u96f6\u552e": ["000058", "000061", "002344", "600058", "600287", "600712", "600981"], "\u56fd\u9632\u519b\u5de5": ["600150", "601989"], "\u57fa\u7840\u5316\u5de5": ["000565", "000912", "002037", "002427", "002522", "002783", "600299", "600423", "600623", "600844", "600889"], "\u5bb6\u7528\u7535\u5668": ["002676"], "\u5efa\u7b51\u88c5\u9970": ["002047", "002061", "002431", "002542", "600629", "600939"], "\u623f\u5730\u4ea7": ["000031", "000514", "000558", "000797", "000897", "002285", "002305", "600239", "600322", "600376", "600604", "600648", "600649", "600675", "600684", "600692", "600708", "600716", "600743", "600748", "601588"], "\u6709\u8272\u91d1\u5c5e": ["000758", "000878", "000960", "002114", "002160", "601168", "601600"], "\u673a\u68b0\u8bbe\u5907": ["000410", "000856", "000927", "002097", "002278", "600169", "600202", "600320", "600343", "600783", "600815", "601106", "601766", "603169"], "\u6c7d\u8f66": ["000599", "000901", "600626", "600653", "600679", "600686", "600960"], "\u7164\u70ad": ["600397", "600403", "600758", "601918"], "\u73af\u4fdd": ["000068", "000605", "002573", "002672", "600292", "600526", "600874", "601368", "603817"], "\u7535\u529b\u8bbe\u5907": ["002168", "002339", "002366", "600550", "601727"], "\u7535\u5b50": ["000509", "000536", "000701", "000727", "002106", "002217", "600601", "600651"], "\u77f3\u6cb9\u77f3\u5316": ["000096", "600800", "600871", "601857"], "\u793e\u4f1a\u670d\u52a1": ["000428", "002659", "600880"], "\u7eba\u7ec7\u670d\u9970": ["000850", "002722", "600156", "600448", "600630", "601718"], "\u7efc\u5408": ["000025", "000632", "000652", "600676", "600805", "600881"], "\u7f8e\u5bb9\u62a4\u7406": ["000523", "600249"], "\u8ba1\u7b97\u673a": ["000503", "000638", "002642", "600100", "600855"], "\u8f7b\u5de5\u5236\u9020": ["600076", "600433", "603021"], "\u901a\u4fe1": ["600198"], "\u94a2\u94c1": ["000655", "000709", "000825", "000898", "600022", "600307"], "\u94f6\u884c": ["002807"], "\u975e\u94f6\u91d1\u878d": ["000958", "002500", "002673", "600705", "600864", "601198"], "\u98df\u54c1\u996e\u6599": ["600300"]}
}

表格控件

class TableNodeWidget(QtWidgets.QWidget):
    def __init__(self):
        super().__init__()
        self.init_data()
        self.init_ui()
        pass
    def init_data(self):
        self.whole_data:Dict = None
        self.target_name_list: List = None
        self.current_target_name: str = None
        self.please_select_str: str = '-- 请选择 --'
        pass
    def init_ui(self):
        pre_btn = QtWidgets.QPushButton('上一个')
        pre_btn.clicked.connect(self.pre_btn_clicked)
        self.target_combox = QtWidgets.QComboBox()
        self.target_combox.currentTextChanged.connect(self.target_combox_currentTextChanged)
        next_btn = QtWidgets.QPushButton('下一个')
        next_btn.clicked.connect(self.next_btn_clicked)

        layout_one = QtWidgets.QHBoxLayout()
        layout_one.addStretch(1)
        layout_one.addWidget(pre_btn)
        layout_one.addWidget(self.target_combox)
        layout_one.addWidget(next_btn)
        layout_one.addStretch(1)

        self.title_label = QtWidgets.QLabel()
        self.title_label.setAlignment(Qt.AlignCenter)
        self.title_label.setStyleSheet('QLabel{font-size:32px;font-weight:bold;}')

        tip_label = QtWidgets.QLabel('提示:最多显示500条数据')

        self.table = QtWidgets.QTableWidget()

        layout = QtWidgets.QVBoxLayout()
        layout.addLayout(layout_one)
        layout.addWidget(self.title_label)
        layout.addWidget(tip_label)
        layout.addWidget(self.table)
        self.setLayout(layout)
        pass
    def set_data(self,data:Dict):
        self.table.clear()
        self.target_combox.clear()

        header = data['header']
        self.whole_data = data['data']
        self.target_name_list = list(self.whole_data.keys())
        self.current_target_name = self.target_name_list[0]

        self.target_combox.addItem(self.please_select_str)
        self.target_combox.addItems(self.target_name_list)

        self.table.setColumnCount(len(header))
        self.table.setHorizontalHeaderLabels(header)

        self.fill_table_content()
        pass
    def fill_table_content(self):
        data = self.whole_data[self.current_target_name]
        self.title_label.setText(self.current_target_name)
        self.table.setRowCount(len(data))
        for i_r, row in enumerate(data):
            for i_c, col in enumerate(row):
                self.table.setItem(i_r, i_c, QtWidgets.QTableWidgetItem(str(col)))
        pass

    def pre_btn_clicked(self):
        cur_i = self.target_name_list.index(self.current_target_name)
        if cur_i<=0:
            cur_i = len(self.target_name_list)-1
        else:
            cur_i = cur_i -1
        self.current_target_name = self.target_name_list[cur_i]
        self.fill_table_content()
        pass
    def next_btn_clicked(self):
        cur_i = self.target_name_list.index(self.current_target_name)
        if cur_i >= len(self.target_name_list) - 1:
            cur_i = 0
        else:
            cur_i = cur_i + 1
        self.current_target_name = self.target_name_list[cur_i]
        self.fill_table_content()
        pass
    def target_combox_currentTextChanged(self,txt:str):
        cur_txt = self.target_combox.currentText()
        if not cur_txt or cur_txt == self.please_select_str:
            return
        self.current_target_name = cur_txt
        self.fill_table_content()
        pass

ExcuteShowWidget 中 process_excute_event 方法修改

    def process_excute_event(self,data:Dict):
        mark_str = data['mark_str']
        status = data['status']
        if status == 'success':
            self.excute_info_label.setText(f'{mark_str} 执行成功')

            ret = data['ret']
            target_style = ret['target_style']
            if target_style == 'table':
                # 表格类型结果
                pre_map = {
                    'header':ret['target_header'],
                    'data':ret['target_data']
                }
                node_widget = TableNodeWidget()
                node_widget.set_data(pre_map)
                self.fill_scroll_area([node_widget])
                pass
        else:
            self.excute_info_label.setText(f'{mark_str} 失败!失败!')
            now_str = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
            log_str = f'{now_str}::{mark_str}::{data["msg"]}'
            self.log_list.append(log_str)

            self.thread_caculate = None
            self.progress_finished()
            pass
        pass

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/876618.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

Java SPI机制

Java SPI机制 java的spi就是一种服务提供发现机制&#xff0c;在一方制定好接口规范后&#xff0c;通过spi的机制可以它的子实现类进行服务发现&#xff0c;以及加载它的子实现类&#xff0c;通过这种机制&#xff0c;让我们在引入第三方库时&#xff0c;不用讲第三方库中的类…

Dubbo 核心概念和架构

以上是 Dubbo 的工作原理图&#xff0c;从抽象架构上分为两层&#xff1a;服务治理抽象控制面 和 Dubbo 数据面 。 服务治理控制面。服务治理控制面不是特指如注册中心类的单个具体组件&#xff0c;而是对 Dubbo 治理体系的抽象表达。控制面包含协调服务发现的注册中心、流量管…

如何批量上传截图

转载&#xff1a;如何批量上传截图 目前用的截图是把iphone上的宣传图改大了分辨率而已&#xff0c;并不是真正ipad上的效果&#xff0c;举例&#xff0c;假设目前在做一个项目是 uniapp开发的&#xff0c;可以通过浏览器运行&#xff0c;运行的分辨率改成ipad截图就可以了&a…

ATRank: An Attention-Based User Behavior Modeling Framework for Recommendation

Abstract 异构用户行为 我们的模型考虑了【异构用户行为】,我们将所有类型的行为投射到多个潜在的语义空间中,在这些语义空间中,行为之间可以通过自关注产生影响。 异构用户行为(Heterogeneous User Behavior)指的是在一个系统、平台或社交网络中,不同用户在行为模式、兴…

利用windows服务器自带的IIS搭建网站并发布公网访问【内网穿透】

文章目录 1.前言2.Windows网页设置2.1 Windows IIS功能设置2.2 IIS网页访问测试 3. Cpolar内网穿透3.1 下载安装Cpolar3.2 Cpolar云端设置3.3 Cpolar本地设置 4.公网访问测试5.结语 1.前言 在网上各种教程和介绍中&#xff0c;搭建网页都会借助各种软件的帮助&#xff0c;比如…

前端CSS居中布局

在前端开发中&#xff0c;实现居中布局是一项必备技能&#xff0c;无论是垂直居中、水平居中&#xff0c;还是同时实现垂直和水平居中。这不仅对于构建响应式网页至关重要&#xff0c;还在设计弹窗、创建导航菜单和设计登录界面时都能派上用场。精通居中布局将为你的前端技能提…

C++初阶之模板深化讲解

模板深化讲解 非类型模板模板的特化1.函数模板特化2.类模板特化 模板分离编译1.什么是分离编译2.模板的分离编译 模板总结 非类型模板 非类型模板&#xff08;Non-Type Template&#xff09;是 C 中的一种模板形式&#xff0c;它允许你在模板中传递除了类型以外的其他值&#x…

BLE 学习小结

GAP 和 GATT https://www.youtube.com/watch?vyKJtnkEjPFI GAP: Generic Access Profile. 定义的是Scanner跟Advertiser的角色。负责连接相关的服务 (设备的搜寻&#xff0c;用来建立连接&#xff0c;连接的管理&#xff0c;等)。 GATT: Generic Attribute Profile. 定义的是…

Java实现DTLS之技术背景原理(一)

文章目录 前言一、DTLS是什么&#xff1f;二、RFC6347标准定义DTLS1.中文翻译 总结感谢 前言 需求&#xff1a;升级服务侧SDK&#xff0c;实现与灯控器之间DTLS加密通信&#xff0c;代替SM4国密。目前通信是采用UDP协议并实现SM4国密加密&#xff0c;为了提升产品竞争力需要实…

5,Lambda

Lambda Lambda https://blog.csdn.net/A1138474382/article/details/111149792 Lambda 捕获列表。在C 规范中也称为Lambda导入器&#xff0c; 捕获列表总是出现在Lambda函数的开始处。实际上&#xff0c;[]是Lambda引出符。编译器根据该引出符判断接下来的代码是否是Lambda函数…

【gogogo专栏】指针

go语言指针 为什么需要指针指针使用实例值传递地址传递多级指针 为什么需要指针 作为一个大学划水&#xff0c;毕业一直写java的程序员来说&#xff0c;多多少少对于指针有点陌生&#xff0c;由于近期需要转go&#xff0c;正好学到指针这里&#xff0c;就来探究下指针的使用场景…

springboot 数据库版本管理升级常用解决方案

目录 一、前言 1.1 单独执行初始化sql 1.2 程序自动执行 二、数据库版本升级管理问题 三、spring 框架sql自动管理机制 3.1 jdbcTemplate 方式 3.1.1 创建数据库 3.1.2 创建 springboot 工程 3.1.3 初始化sql脚本 3.1.4 核心配置类 3.1.5 执行sql初始化 3.2 配置文…

Baklib:企业Wiki 知识库管理有序更高效

什么是Baklib? Baklib是一种企业Wiki知识库管理工具&#xff0c;旨在帮助企业更好地管理和共享知识。它提供了一个集中存储和组织知识的平台&#xff0c;使团队成员可以轻松地查找和共享信息。Baklib具有直观的用户界面和强大的搜索功能&#xff0c;可以提高团队的工作效率和…

leetcode 516. 最长回文子序列(JAVA)题解

题目链接https://leetcode.cn/problems/longest-palindromic-subsequence/description/?utm_sourceLCUS&utm_mediumip_redirect&utm_campaigntransfer2china 目录 题目描述&#xff1a; 暴力递归&#xff1a; 动态规划&#xff1a; 题目描述&#xff1a; 给你一个…

第06天 静态代理和动态代理

✅作者简介&#xff1a;大家好&#xff0c;我是Leo&#xff0c;热爱Java后端开发者&#xff0c;一个想要与大家共同进步的男人&#x1f609;&#x1f609; &#x1f34e;个人主页&#xff1a;Leo的博客 &#x1f49e;当前专栏&#xff1a;每天一个知识点 ✨特色专栏&#xff1a…

运维监控学习笔记7

Zabbix的安装&#xff1a; 1、基础环境准备&#xff1a; 安装zabbix的yum源&#xff0c;阿里的yum源提供了zabbix3.0。 rpm -ivh http://mirrors.aliyun.com/zabbix/zabbix/3.0/rhel/7/x86_64/zabbix-release-3.0-1.el7.noarch.rpm 这个文件就是生成了一个zabbix.repo 2、安…

海量数据迁移,亚马逊云科技云数据库服务为大库治理提供新思路

1.背景 目前&#xff0c;文档型数据库由于灵活的schema和接近关系型数据库的访问特点&#xff0c;被广泛应用&#xff0c;尤其是游戏、互联网金融等行业的客户使用MongoDB构建了大量应用程序&#xff0c;比如游戏客户用来处理玩家的属性信息&#xff1b;又如股票APP用来存储与时…

ESP 系列的产品 ULP 协处理器的应用

参考文档&#xff1a; 《ESP32-S2 技术参考手册》 中 “1. 超低功耗协处理器 (ULP)” 章节《ESP32-S3 技术参考手册》 中 “2 超低功耗协处理器 (ULPFSM, ULPRISCV)” 章节《ESP32-C6 技术参考手册》 中 “3 低功耗处理器” 章节ULP 协处理器编程ULP RISC-V 协处理器编程Progr…

leetcode2024. 考试的最大困扰度(java)

考试的最大困扰度 leetcode2024. 考试的最大困扰度题目描述滑动窗口最大值 经典算法 leetcode2024. 考试的最大困扰度 难度 - 中等 原题链接 - 考试的最大困扰度 题目描述 一位老师正在出一场由 n 道判断题构成的考试&#xff0c;每道题的答案为 true &#xff08;用 ‘T’ 表示…

程序设计 堆

✅作者简介&#xff1a;人工智能专业本科在读&#xff0c;喜欢计算机与编程&#xff0c;写博客记录自己的学习历程。 &#x1f34e;个人主页&#xff1a;小嗷犬的个人主页 &#x1f34a;个人网站&#xff1a;小嗷犬的技术小站 &#x1f96d;个人信条&#xff1a;为天地立心&…