VeighNa量化社区
你的开源社区量化交易平台
woodlandnight's Avatar
Member
离线
41 帖子
声望: 1

在jupyter里使用get_price报错,

rb888_raw = rqdatac.get_price('RB888', '20230301', '20230331', '1m')

TypeError Traceback (most recent call last)
Cell In[9], line 1
----> 1 rb888_raw = rqdatac.get_price('RB888', '20230301', '20230331', '1m')

File c:\veighna_studio\lib\site-packages\rqdatac\decorators.py:150, in compatible_with_parm..wrap(args, **kwargs)
148 if item != value:
149 raise ValueError("'{}': except '{}', got '{}'".format(name, value, item))
--> 150 return func(
args, **kwargs)

File c:\veighna_studio\lib\site-packages\rqdatac\services\get_price.py:86, in get_price(order_book_ids, start_date, end_date, frequency, fields, adjust_type, skip_suspended, expect_df, time_slice, market, kwargs)
83 raise ValueError("time_slice: invalid, expect tuple or list value like ('09:55', '10:11'), got {}".format(time_slice))
84 start, end = to_time(time_slice[0]), to_time(time_slice[1])
---> 86 df = _get_price(
87 order_book_ids, start_date, end_date, frequency,
88 fields, adjust_type, skip_suspended, expect_df, market,
kwargs
89 )
91 if df is None or not sliceable or not time_slice:
92 # 非tick、minbar或者不指定切片时间,直接返回
93 return df

File c:\veighna_studio\lib\site-packages\rqdatac\decorators.py:67, in retry..decorate..wrap(args, **kwargs)
65 while c > 0:
66 try:
---> 67 return func(
args, **kwargs)
...
4129 )
4130 indexer = key
4131 else:

TypeError: Slicing a positional slice with .loc is not allowed, Use .loc with labels or .iloc with positions instead.

以前也用get_price,没出现过这个问题,不知道为什么现在会报错。现在使用query_bar_history则不报错,照道理query_bar_history里也调用get_price了,问什么会出现这种情况呢

配置完influxdb后,下载数据时出现以下报错`Traceback (most recent call last):
File "C:\veighna_studio\lib\site-packages\vnpy_datamanager\ui\widget.py", line 620, in download
count: int = self.engine.download_bar_data(symbol, exchange, interval, start, self.output)
File "C:\veighna_studio\lib\site-packages\vnpy_datamanager\engine.py", line 215, in download_bar_data
self.database.save_bar_data(data)
File "C:\veighna_studio\lib\site-packages\vnpy_influxdb\influxdb_database.py", line 94, in save_bar_data
self.write_api.write(
File "C:\veighna_studio\lib\site-packages\influxdb_client\client\write_api.py", line 378, in write
results = list(map(write_payload, payloads.items()))
File "C:\veighna_studio\lib\site-packages\influxdb_client\client\write_api.py", line 376, in write_payload
return self._post_write(_async_req, bucket, org, final_string, payload[0])
File "C:\veighna_studio\lib\site-packages\influxdb_client\client\write_api.py", line 509, in _post_write
return self._write_service.post_write(org=org, bucket=bucket, body=body, precision=precision,
File "C:\veighna_studio\lib\site-packages\influxdb_client\service\write_service.py", line 60, in post_write
(data) = self.post_write_with_http_info(org, bucket, body, **kwargs) # noqa: E501
File "C:\veighna_studio\lib\site-packages\influxdb_client\service\write_service.py", line 90, in post_write_with_http_info
return self.api_client.call_api(
File "C:\veighna_studio\lib\site-packages\influxdb_client_sync\api_client.py", line 343, in call_api
return self.call_api(resource_path, method,
File "C:\veighna_studio\lib\site-packages\influxdb_client_sync\api_client.py", line 173, in
call_api
response_data = self.request(
File "C:\veighna_studio\lib\site-packages\influxdb_client_sync\api_client.py", line 388, in request
return self.rest_client.POST(url,
File "C:\veighna_studio\lib\site-packages\influxdb_client_sync\rest.py", line 311, in POST
return self.request("POST", url,
File "C:\veighna_studio\lib\site-packages\influxdb_client_sync\rest.py", line 261, in request
raise ApiException(http_resp=r)
influxdb_client.rest.ApiException: (401)
Reason: Unauthorized
HTTP response headers: HTTPHeaderDict({'Content-Type': 'application/json; charset=utf-8', 'X-Influxdb-Build': 'OSS', 'X-Influxdb-Version': 'v2.7.0', 'X-Platform-Error-Code': 'unauthorized', 'Date': 'Sat, 10 Jun 2023 16:20:33 GMT', 'Content-Length': '55', 'Connection': 'close'})
HTTP response body: {"code":"unauthorized","message":"unauthorized access"}

`
是token没有配置的原因吗,该如何解决呢

请教一下,我看on_tick,on_trade,on_order等等里面都有两个self.on_event(),请问为什么需要两个呢,我交易某个合约的话只保留第二个(里面有vt_symbol)的那个行不行?没太理解为什么要这样设计。

有几个不太理解的地方
第一个是
elif ((self.bar.datetime.minute != tick.datetime.minute) or (self.bar.datetime.hour != tick.datetime.hour)): #???
self.bar.datetime = self.bar.datetime.replace(second=0, microsecond=0)
self.on_bar(self.bar) #推送处理合成好的K线
new_minute = True
这里既然比较了分钟,为什么还要比较小时呢?这样做的意义在哪?

第二个问题是
self.bar.high_price = max(self.bar.high_price, tick.last_price)#???
if tick.high_price > self.last_tick.high_price:
self.bar.high_price = max(self.bar.high_price, tick.high_price)

self.bar.low_price = min(self.bar.low_price, tick.last_price)
if tick.low_price < self.last_tick.low_price:
self.bar.low_price = min(self.bar.low_price, tick.low_price)
为什么不直接max(self.bar.high_price, tick.high_price)呢

我在bargenerator里写了个时间判断的方法,想用tick.symbol来判断是不是螺纹,等号后面应该是rb还是RB呢?数据服务商用的是米筐,对这里会有影响吗?

def tradetime(self, exchange: Exchange, tick: TickData) -> bool:
    if exchange == Exchange.SHFE:
            if re.findall('[a-zA-Z]+', tick.symbol)[0] == "rb":
                if (
                时间部分
                ):
                    return True

请问应该添加在哪里呢

使用米筐下载了tick数据,但是在数据管理那里看不了tick的数据,请问怎么查看并且导出成csv呢?数据库用的默认的sqlite

1成交价格和目标价格不一致的疑惑:
bar1的收盘价是4043,bar2的收盘价是4050,我理解的执行逻辑是bar1结束,bar2刚开始走的时候触发了self.buy(bar.close_price + 3, self.fixed_size),也就是希望以4043成交,最多3个滑点(4046)?这样的理解对么?为什么实盘成交价格却是4050呢,盘后回测的时候成交价格也是4043,就算实盘有滑点,也不应该是4050?不太理解

2持仓均价的疑惑:
一笔单子是白天在4050开了一手,右下角那个持仓均价显示的也是4050,但是晚上实盘的时候,持仓均价变成4022了?我查询账单后看到开仓价是4050,昨结算4030,结算价4022,为什么持仓均价会变成结算价呢?盈亏难道不是只和开仓价有关系么?

3self.sell(6000, abs(self.pos), True)的意思是不是价格低于6000就触发停止单卖出?

参数优化后,优化结果不显示,station那边显示
description

另一个问题是云主机上安装veighna后,显示
description
当时试了下可以回测于是没管这个问题继续跑优化了,这是优化结果导致不显示的原因吗?
该如何解决这两个问题呢

如图,米框上的RB888数据和快期里看到的数据相差了一千多接近两千,这样应该相信哪个呢?如果回测的话是否有意义呢?数值相差很大的话是不是参数优化时要避开这段时间?
description

description

description

我的策略要同时用到一分钟和五分钟的K线,在策略文件中是这么写的,是哪里错了吗? self.put_event()是on_bar和on_5_min_bar下面都要加吗?
def init(self, cta_engine, strategy_name, vt_symbol, setting):
""""""
super().init(cta_engine, strategy_name, vt_symbol, setting)

    self.bg1 = BarGenerator(self.on_bar)
    self.am1 = ArrayManager()

    self.bg5 = BarGenerator(self.on_bar, 5, self.on_5_min_bar)
    self.am5 = ArrayManager()

def on_tick(self, tick: TickData):
    """
    Callback of new tick data update.
    """
    self.bg1.update_tick(tick)
    self.bgx.update_tick(tick)

def on_bar(self, bar: BarData):
    """
    Callback of new bar data update.
    """
    self.bg1.update_bar(bar)
    self.bg5.update_bar(bar)
    if not self.am1.inited:
         return

def on_5_min_bar(self, bar: BarData):
    """"""
    self.cancel_all()

    self.am5.update_bar(bar)
    if not self.am5.inited:
        return

目前已经在用默认的sqlite数据库,能否再创建一个sqlite数据库呢?

我设置了亏损15个点止损的条件,大部分情况是正常触发的,但是有几笔交易没有正常触发,出现了大量亏损。
定位到那几笔交易后发现并不是特别剧烈的下跌,在中间的某些bar本应该可以触发止损的,但是并没有正常触发,这是为什么呢?

description
description
description
description
description

另外,我在右侧面板看到2月21日有一个大额亏损,但是点开K线图表和成交记录却没有找到相关交易?好诡异

description

请问回测的参数优化是并行的吗?是的话是基于mpi还是openmp呢?如何设置核数

我想自定义一个函数profit_monitor用于计算实时的盈利情况,因此需要获得真实的开仓均价。查询了一下论坛,好像是用on_trade获取开仓均价。
研究了下TradeData,发现有九个值
symbol: str
exchange: Exchange
orderid: str
tradeid: str
direction: Direction = None
offset: Offset = Offset.NONE
price: float = 0
volume: float = 0
datetime: datetime = None

我想在utility中写这个profit_monitor函数并在策略文件中使用,是否可行?需要import其他内容吗?
def profit_monitor(self):
return self.close_array[-1] - self.on_trade[6]

另外PositionData和TradeData区别在哪呢?

请教一下各位大佬,我想缓存近100个bar的macd信息,一开始看到了时间序列容器Arraymanager,想把macd直接写到Arraymanager里,后来发现,得先有Arraymanager,才能开始计算指标。似乎直接写在Arraymanager里不成立。
如何才能让近100个bar除了高开低收以外,多一列MACD的信息呢?

一不小心将python版本更新到了3.10,回测的时候python.exe提示“应用程序无法正常启动0xc000012d”,不知道是不是更新了python版本导致的,请问如何在不影响其他组件的情况下,降低版本呢

我在策略中定义了一个变量A,初始值是0,希望用来计数,并且每次开仓后清零,
但是回测中出现了UnboundLocalError: local variable 'A' referenced before assignment,
百度后好像是全局变量的问题,于是加了global A,
再次回测出现了NameError: name 'A' is not defined
编程小白整不会了,晕,请问该如何解决呢

请问策略中的这个bar是哪来的,翻了一下没有找到,其他文件里似乎也没看到
description

© 2015-2022 微信 18391752892
备案服务号:沪ICP备18006526号

沪公网安备 31011502017034号

【用户协议】
【隐私政策】
【免责条款】