| | |
| | | # print(f"open_growth=={open_growth}") |
| | | |
| | | |
| | | # 计算瞬时涨幅公式 |
| | | # 初始化历史价格 |
| | | price_history = {} |
| | | # # 计算瞬时涨幅公式 |
| | | # # 初始化历史价格 |
| | | # price_history = {} |
| | | # |
| | | # |
| | | # def calculate_growth(symbol, price): |
| | | # try: |
| | | # if symbol not in price_history: |
| | | # return 0 # 不足两个历史价格,无法计算涨幅 |
| | | # last_price = price_history[symbol] |
| | | # # print(f"price_history[symbol]~~~~~~~~~{price_history[symbol]}") |
| | | # if last_price != 0: |
| | | # growth = (price - last_price) / last_price * 100 # 计算涨幅百分比 |
| | | # return growth |
| | | # finally: |
| | | # price_history[symbol] = price |
| | | # # print(f"price======={price}") |
| | | # # print(f"price_history=={price_history}") |
| | | # # print(f"price_history[symbol]=={price_history[symbol]}") |
| | | |
| | | |
| | | def calculate_growth(symbol, price): |
| | | try: |
| | | if symbol not in price_history: |
| | | return 0 # 不足两个历史价格,无法计算涨幅 |
| | | last_price = price_history[symbol] |
| | | # print(f"price_history[symbol]~~~~~~~~~{price_history[symbol]}") |
| | | if last_price != 0: |
| | | growth = (price - last_price) / last_price * 100 # 计算涨幅百分比 |
| | | return growth |
| | | finally: |
| | | price_history[symbol] = price |
| | | # print(f"price======={price}") |
| | | # print(f"price_history=={price_history}") |
| | | # print(f"price_history[symbol]=={price_history[symbol]}") |
| | | |
| | | |
| | | # 计算tick涨幅公式【为卖出策略单独创建函数】 |
| | | # # 计算瞬时间隔涨幅公式【为卖出策略单独创建函数】 |
| | | # 初始化历史价格 |
| | | history_price = {} |
| | | |
| | |
| | | if last_price != 0: |
| | | growth = (price - last_price) / last_price * 100 # 计算涨幅百分比 |
| | | return growth |
| | | |
| | | finally: |
| | | history_price[symbol] = price |
| | | # print(f"price======={price}") |
| | |
| | | frying_plate_day_min_index = next((i for i, d in enumerate(k_line_data[0:7]) if 'attribute' in d and d['attribute'] in data_cache.frying_plate_type), None) # 如果没有找到,返回None |
| | | # 找到最近7日内的有跌停的序号 |
| | | limit_down_day_min_index = next((i for i, d in enumerate(k_line_data[0:7]) if 'attribute' in d and d['attribute'] in data_cache.limit_down_type), None) # 如果没有找到,返回None |
| | | |
| | | # 最近的涨停序号存在 且 非昨日 |
| | | if limit_up_day_min_index is not None and limit_up_day_min_index > 0: |
| | | # 开盘价 < 涨停当日最高价 <= 今日涨停价 |
| | |
| | | def secure_volume(now_date_time): |
| | | # 定义时间段的开始和结束时间(使用字符串格式) |
| | | time_slots = [ |
| | | (("09:30:00", "09:30:30"), 0.05), |
| | | (("09:30:00", "09:30:30"), 0.04), |
| | | (("09:30:30", "09:31:00"), 0.08), |
| | | (("09:31:00", "09:31:30"), 0.1), |
| | | (("09:31:30", "09:32:00"), 0.15), |
| | |
| | | return 0 |
| | | |
| | | |
| | | # 示例使用 |
| | | # now = datetime.now() |
| | | # print(f"secure_volume(now)=={secure_volume(now)}") |
| | | # 充分交易量公式 用于计算日内涨幅段理论的安全交易量值 |
| | | def sufficient_volume(current_volume, yesterday_volume, today_growth): |
| | | if today_growth > 0 and round(current_volume / yesterday_volume, 2) >= 0.01: |
| | | if current_volume > yesterday_volume * (today_growth/10) * 0.5: |
| | | return True |
| | | else: |
| | | return False |
| | | |
| | | |
| | | # 计算 委买和委卖的比例函数(获取买盘强度数据)【掘金数据结构】 |
| | | def buying_and_selling_ratio(current_quotes): |
| | |
| | | else: |
| | | buying_ratio = 0.01 |
| | | return buying_ratio |
| | | |
| | | |
| | | # 统计有意买股票出现次数函数 |
| | | def count_willing_buy_times(sec_name): |
| | | willing_buy_times = data_cache.willing_buy_list.count(sec_name) |
| | | return willing_buy_times |