当前位置:网站首页>ubiquant量化竞赛
ubiquant量化竞赛
2022-08-03 14:48:00 【人工智能曾小健】
import pickle
def load_pickle(path):
with open(path, 'rb') as f:
return pickle.load(f)
path = '/home/mw/input/debug2469/debug'
x_A = load_pickle(f'{path}/A.pickle')
x_H = load_pickle(f'{path}/H.pickle')
all_dict = {}
all_dict['A'] = x_A
all_dict['H'] = x_H
INT_dates_all = list(sorted(set(all_dict['A']['INT_dates']).union(set(all_dict['H']['INT_dates']))))
all_dict['INT_dates_all'] = INT_dates_allx_A['close'].shape, x_H['close'].shape #![]()
list(x_A.keys()) # 所有字段 
x_A['INT_tickers'] # 股票id ![]()
list(x_A['INT_dates']) # 日期

x_A['INT_date_2_di'] # 日期对应数据的di, 因为存在A股和H股不同时开市的情况 
import numpy as np
import pandas as pd
class DepthInfo:
def __init__(self):
self.prices = []
self.volumes = []
class BasicStockInfo():
def __init__(self):
self.buy_infos = DepthInfo()
self.sell_infos = DepthInfo()
def show_all(self):
print(f'[+] stock_id = {self.stock_id}')
print(f' market_id = {self.market_id}')
print(f' open = {self.open}')
print(f' close = {self.close}')
print(f' close_prev = {self.close_prev}')
print(f' high = {self.high}')
print(f' low = {self.low}')
print(f' volume = {self.volume}')
print(f' tvr = {self.tvr}')
print(f' is_tradable = {self.is_tradable}')
print(f' buy_infos.prices = {self.buy_infos.prices}')
print(f' buy_infos.volumes = {self.buy_infos.volumes}')
print(f' sell_infos.prices = {self.sell_infos.prices}')
print(f' sell_infos.volumes = {self.sell_infos.volumes}')
class StockManager:
def __init__(self, all_dict):
self.all_dict = all_dict
def get_stock_info_dict(self, x_dict, di, ti, market_id):
stock_info_dict = {}
if di == -1:
return stock_info_dict
if market_id == 0 and ti >= 25 + 3:
return stock_info_dict
if market_id == 1 and ti >= 34:
return stock_info_dict
# A:
if market_id == 0:
# 11:30-12:00, not open
if ti >= 13 and ti < 13 + 3:
return stock_info_dict
# A: 13:00-15:00: [13+3, 24+3]
if ti >= 16:
ti -= 3
# not valid di
if di >= x_dict['open'].shape[0]:
return {}
# eacho stock
for si, stock_id in enumerate(x_dict['INT_tickers']):
stock_info = BasicStockInfo()
stock_info.stock_id = stock_id
stock_info.market_id = market_id
stock_info.open = x_dict['open'][di, ti, si]
stock_info.close = x_dict['close'][di, ti, si]
stock_info.high = x_dict['high'][di, ti, si]
stock_info.low = x_dict['low'][di, ti, si]
stock_info.volume = x_dict['volume'][di, ti, si]
stock_info.tvr = x_dict['tvr'][di, ti, si]
stock_info.is_tradable = x_dict['mask'][di, ti, si]
stock_info.close_prev = x_dict['close_prev'][di, si] if ti == 0 else np.nan
for a in list(x_dict['bidprice'][:, di, ti, si]):
stock_info.buy_infos.prices.append(a)
for a in list(x_dict['bidvolume'][:, di, ti, si]):
stock_info.buy_infos.volumes.append(a)
for a in list(x_dict['askprice'][:, di, ti, si]):
stock_info.sell_infos.prices.append(a)
for a in list(x_dict['askvolume'][:, di, ti, si]):
stock_info.sell_infos.volumes.append(a)
stock_info_dict[stock_id] = stock_info
return stock_info_dict
def get_sequence_stocks_info(self, date_i, ti):
print(f'date_i = {date_i}, ti = {ti}')
# A: 09:30-11:30, 13:00-15:00, total = 4 hours, 4 * 6 + 1 = 25
# H: 09:30-12:00, 13:00-16:00, total = 5.5 hours, 5 * 6 + 3 + 1 = 34
# A:
# 1) 09:30-11:30: [0, 12]
# 2) 13:00-15:00: [13+3, 24+3]
# H:
# 1) 09:30-12:30: [0, 15]
# 2) 13:00-16:00: [16, 33]
all_dict = self.all_dict
date_i += 20 # 20 days for history data
date = all_dict['INT_dates_all'][date_i]
res = []
di = all_dict['A']['INT_date_2_di'].get(date, -1)
stock_info_dict = self.get_stock_info_dict(all_dict['A'], di, ti, market_id = 0)
res.append(stock_info_dict)
di = all_dict['H']['INT_date_2_di'].get(date, -1)
stock_info_dict = self.get_stock_info_dict(all_dict['H'], di, ti, market_id = 1)
res.append(stock_info_dict)
return res 模拟拿到数据, 方便debug. date = , ti =
边栏推荐
- 正则表达式入门二(普通字符)
- 【R语言科研绘图】--- 柱状图
- 进程通信的方式
- 如何把MapGIS的区文件转为ArcGIS的SHAPE面文件
- 爬虫——代理搭建、爬取视频网站、爬取新闻、BeautifulSoup4介绍、bs4 遍历文档树、bs4搜索文档树、bs4使用选择器
- 【指针内功修炼】函数指针 + 函数指针数组 + 回调函数(二)
- 你没见过的《老友记》镜头,AI给补出来了|ECCV 2022
- 网络中的交换机和路由器
- 162_Power Query is a custom function for quickly merging tables in a folder TableXlsxCsv_2.0
- 基于matlab的遥测信道的基本特性仿真分析
猜你喜欢
随机推荐
UE4 C disk cache solution
atrace和systrace的基本使用方法
可视化数据库设计软件有哪些_数据库可视化编程
[The Beauty of Software Engineering - Column Notes] 36 | What exactly do DevOps engineers do?
树莓派 USB摄像头 实现网络监控( MJPG-Streamer)
个人秋招记录——欢迎交流
Currency ATM: Solana Wallet Has Unknown Security Vulnerability, A Large Number Of Users' Digital Assets Are Stolen
2022-随便学学
币圈提款机:Solana钱包出现未知安全漏洞 大量用户数字资产被盗
【实战】Next.js + 云函数开发一个面试刷题网站
阿里大牛最新总结分享的高并发编程核心笔记(终极版),高并发系统架构场景一应俱全
兔起鹘落全端涵盖,Go lang1.18入门精炼教程,由白丁入鸿儒,全平台(Sublime 4)Go lang开发环境搭建EP00
DeepLink在转转的实践
Linux安装Mysql的几种方法
liunx服务器遇到SYN_SENT洪水攻击
Ansible中的角色使用
正则表达式入门一
chrome浏览器对应驱动_chrome手机浏览器
苹果开发「AI 建筑师」GAUDI:根据文本生成超逼真 3D 场景!
网络通信的过程









