# 导入聚宽函数库 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函数用于将错误信息写入日志文件。