# 导入聚宽函数库 import jqdata log.set_level("system","error") # 初始化程序, 整个回测只运行一次 def initialize(context): # 开启动态复权模式(真实价格) set_option('use_real_price', True) # 股票类交易手续费是:买入时佣金万分之三,卖出时佣金万分之三加千分之一印花税, 每笔交易佣金最低扣5块钱 set_order_cost(OrderCost(open_tax=0, close_tax=0.001, \ open_commission=0.0003, close_commission=0.0003,\ close_today_commission=0, min_commission=5), type='stock') # 股票池 g.stocks = list(get_all_securities(['stock']).index) #上涨家数 g.num = [] #上涨家数(去重) g.b=[] # 计数器 g.run_num = -1 # 运行函数 run_daily(market_open, time='every_bar') def before_trading_start(context): # 得到所有股票前1日收盘价 g.last_df = history(1,'1d','close',g.stocks) def market_open(context): #频率10分钟一次 g.run_num += -1 if g.run_num != 10: return else: g.run_num = 0 #每天每10分钟实时价格 for security in g.stocks: # 得到当前价格 current_data = get_current_data() price = current_data[security].last_price g.one = g.last_df[security][0] if price > g.one: g.num.append(security) g.b = list(set(g.num)) elif price < g.one: if security in g.num: g.num.remove(security) g.b = list(set(g.num)) print(len(g.b))把上述代码改成只在14:30分运行

时间: 2024-02-14 10:25:15 浏览: 24
你可以在`initialize`函数中添加一个定时器,使其在14:30分运行。具体的修改如下: ```python def initialize(context): # 其他代码... # 添加定时器,每天的14:30分运行 run_daily(market_open, time='14:30') ``` 这样修改后,`market_open`函数将在每天的14:30分被调用。你可以在该函数中继续执行你的逻辑。
相关问题

4、下面哪个函数可以设置用户自定义的异常处理函数(10 分) A.set_error_handler B.set_exception_handler C.error_log D.error_reporting

正确的答案是 B.set_exception_handler。 `set_exception_handler()` 函数可以设置用户自定义的异常处理函数,当发生未捕获的异常时,将会调用该函数进行处理。该函数的参数是一个回调函数,用于处理异常信息。 `set_error_handler()` 函数是用于设置自定义错误处理函数,而不是异常处理函数。当发生 PHP 运行时错误时,会调用该函数来处理错误信息。 `error_log()` 和 `error_reporting()` 函数也不是用于设置异常处理函数的。`error_log()` 函数是用于将错误信息写入到服务器的错误日志中,而 `error_reporting()` 函数是用于设置 PHP 错误的报告级别。

下面哪个函数可以设置用户自定义的错误处理函数(1 分) A.set_error_handler B.set_exception_handler C.error_reporting D.error_log

选项 A,set_error_handler函数可以设置用户自定义的错误处理函数。 在PHP中,set_error_handler函数用于设置用户自定义的错误处理函数,该函数会在PHP发生错误时被调用。而set_exception_handler函数用于设置用户自定义的异常处理函数,该函数会在PHP抛出未捕获的异常时被调用。error_reporting函数用于设置PHP报告的错误级别,error_log函数用于将错误信息写入日志文件。

相关推荐

import jqdata # 初始化聚宽账号密码 def initialize(context): # 设置回测日期区间 set_benchmark('000300.XSHG') set_option('use_real_price', True) # 设置买入的股票数量上限 g.max_stock_count = 5 def handle_data(context, data): # 获取当前日期 current_date = context.current_dt.date() # 获取股票池中的股票列表 stocks = get_index_stocks('000852.XSHG') # 按照股票池中的股票进行遍历 for stock in stocks: # 判断股票是否满足买入条件 if check_buy_condition(stock, current_date, context): buy_stock(stock, context) # 判断持有的股票是否满足卖出条件 if check_sell_condition(stock, current_date, context): sell_stock(stock, context) def check_buy_condition(stock, current_date, context): # 判断股票是否连续下跌三天 prices = attribute_history(stock, 3, '1d', ['close']) if len(prices) == 3 and prices['close'][-1] < prices['close'][-2] < prices['close'][-3]: return True else: return False def buy_stock(stock, context): # 判断当前持仓的股票数量是否已达上限 if len(context.portfolio.positions) >= g.max_stock_count: return # 买入股票 order_value(stock, context.portfolio.cash / g.max_stock_count) def check_sell_condition(stock, current_date, context): # 获取持有股票的买入日期 buy_date = context.portfolio.positions[stock].init_time.date() # 判断是否满足卖出条件 if current_date - buy_date >= 3: # 判断是否亏损超过5% if (context.portfolio.positions[stock].last_price - context.portfolio.positions[stock].avg_cost) / context.portfolio.positions[stock].avg_cost <= -0.05: return True return False def sell_stock(stock, context): # 卖出股票 order_target(stock, 0)当中buy_date = context.portfolio.positions[stock].init_time.date()报错'NoneType' object has no attribute 'date'

import sys import os import time from PyQt5 import QtGui #重新导入 from PyQt5 import QtCore #重新导入 from showPic import Ui_MainWindow from PyQt5.QtCore import * from PyQt5.QtGui import * #导入的外面 from PyQt5.QtWidgets import * import cv2 # 方法二 class picShow(QMainWindow, Ui_MainWindow): def __init__(self): super().__init__() self.setupUi(self) # 方法一 # self.picMap = QtGui.QPixmap("img0.jpg") # self.label.setGeometry(QtCore.QRect(40, 40, 960, 560)) # 修改大小 # self.label.setPixmap(self.picMap) # 方法二(常用) self.n = 0 self.timer = QTimer(self) # 创建QT计时器 self.timer.timeout.connect(self.timer_pic) # 链接计时器触发函数 self.timer.start(1000) # 设置轮播间隔,里面单位是毫秒 self.dir_path = r"E:\pycharm\new_subject\image/" # r用来确保斜杠转义问题,最后的/一定要带上 self.file_list = os.listdir(self.dir_path) # print(file_list) def timer_pic(self): self.n += 1 # 调用函数实现自增 if self.n >= len(self.file_list): # 回退索引,轮播效果 self.n = 0 image_name = self.dir_path + self.file_list[self.n] url = image_name pic_image = cv2.imread(url) pic_image = cv2.cvtColor(pic_image, cv2.COLOR_BGR2RGB) # 将BGR格式图像转换成RGB height, width = pic_image.shape[:2] pixMap = QImage(pic_image.data, width, height, width*3, QImage.Format_RGB888) # 将RGB格式图像转换为八位图 pixMap = QPixmap.fromImage(pixMap) ratio = max(width/self.label.width(), height/self.label.height()) pixMap.setDevicePixelRatio(ratio) # 根据图片比例显示 self.label.setAlignment(Qt.AlignCenter) # 设置居中 self.label.setPixmap(pixMap) if __name__ == '__main__': app = QApplication(sys.argv) ui = picShow() ui.show() sys.exit(app.exec_())每一行是什么意思?

最新推荐

recommend-type

c++ 子类构造函数初始化及父类构造初始化的使用

主要介绍了c++ 子类构造函数初始化及父类构造初始化的使用,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
recommend-type

mysql中find_in_set()函数的使用及in()用法详解

主要介绍了mysql中find_in_set()函数的使用以及in()用法详解,需要的朋友可以参考下
recommend-type

完美解决mysql in条件语句只读取一条信息问题的2种方案

使用mysql多表查询时一个表中的某个字段作为另一表的in查询条件,只能读取一条信息,而直接用数字的话可以正常读取
recommend-type

MySQL高效模糊搜索之内置函数locate instr position find_in_set使用详解

常用的一共有4个方法,如下: 1.使用locate()方法 普通用法: SELECT`column`from`table`wherelocate('keyword',`condition`)&gt;0 ...2.使用instr()函数(据说是locate()的别名函数) SELECT `column` from `table`
recommend-type

python统计函数库scipy.stats的用法解析

今天小编就为大家分享一篇python统计函数库scipy.stats的用法解析,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
recommend-type

zigbee-cluster-library-specification

最新的zigbee-cluster-library-specification说明文档。
recommend-type

管理建模和仿真的文件

管理Boualem Benatallah引用此版本:布阿利姆·贝纳塔拉。管理建模和仿真。约瑟夫-傅立叶大学-格勒诺布尔第一大学,1996年。法语。NNT:电话:00345357HAL ID:电话:00345357https://theses.hal.science/tel-003453572008年12月9日提交HAL是一个多学科的开放存取档案馆,用于存放和传播科学研究论文,无论它们是否被公开。论文可以来自法国或国外的教学和研究机构,也可以来自公共或私人研究中心。L’archive ouverte pluridisciplinaire
recommend-type

实现实时数据湖架构:Kafka与Hive集成

![实现实时数据湖架构:Kafka与Hive集成](https://img-blog.csdnimg.cn/img_convert/10eb2e6972b3b6086286fc64c0b3ee41.jpeg) # 1. 实时数据湖架构概述** 实时数据湖是一种现代数据管理架构,它允许企业以低延迟的方式收集、存储和处理大量数据。与传统数据仓库不同,实时数据湖不依赖于预先定义的模式,而是采用灵活的架构,可以处理各种数据类型和格式。这种架构为企业提供了以下优势: - **实时洞察:**实时数据湖允许企业访问最新的数据,从而做出更明智的决策。 - **数据民主化:**实时数据湖使各种利益相关者都可
recommend-type

SPDK_NVMF_DISCOVERY_NQN是什么 有什么作用

SPDK_NVMF_DISCOVERY_NQN 是 SPDK (Storage Performance Development Kit) 中用于查询 NVMf (Non-Volatile Memory express over Fabrics) 存储设备名称的协议。NVMf 是一种基于网络的存储协议,可用于连接远程非易失性内存存储器。 SPDK_NVMF_DISCOVERY_NQN 的作用是让存储应用程序能够通过 SPDK 查询 NVMf 存储设备的名称,以便能够访问这些存储设备。通过查询 NVMf 存储设备名称,存储应用程序可以获取必要的信息,例如存储设备的IP地址、端口号、名称等,以便能
recommend-type

JSBSim Reference Manual

JSBSim参考手册,其中包含JSBSim简介,JSBSim配置文件xml的编写语法,编程手册以及一些应用实例等。其中有部分内容还没有写完,估计有生之年很难看到完整版了,但是内容还是很有参考价值的。