Chinaunix首页 | 论坛 | 博客
  • 博客访问: 3657440
  • 博文数量: 365
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 2522
  • 用 户 组: 普通用户
  • 注册时间: 2019-10-28 13:40
文章分类

全部博文(365)

文章存档

2023年(8)

2022年(130)

2021年(155)

2020年(50)

2019年(22)

我的朋友

分类: Python/Ruby

2021-06-04 17:28:57

max_consume_money = consume_money

for day_up_down in data.index:

    open = data.loc[day_up_down].values[0]

    high = data.loc[day_up_down].values[1]

    low = data.loc[day_up_down].values[2]

    # close = data.loc[day_up_down].values[3]

    # 盘前

    # 如果 opt 为空,没有任何操作, 基准价 > 开盘价,触发买入

    # if len(opt) == 0 and benchmark > open:

    if benchmark * (1 - grid) > open:

        # 一手买入 或者 倍数买入

        # 买入

        # 基准价变更

        benchmark = open

        print(day_up_down, "开盘买入", benchmark)

        # 计算的操作

        consume_money += Decimal(benchmark) * Decimal(count)

        if consume_money.compare(max_consume_money) > 0:

            max_consume_money = consume_money

        # 添加记录

        h = history.History(stock_code, 1, open, count)

        opt.append(h)

        opt_b.append([day_up_down, benchmark, 1])

    elif benchmark * (1 + grid) <= open:

        if len(opt) > 0:

            # 卖出

            # 基准价变更

            benchmark = open

            # 计算的操作

            # 利润

            temp = float(

                ((Decimal(benchmark) - Decimal(opt[len(opt) - 1].price)) * count).quantize(Decimal('0.00')))

            profit += temp

            consume_money -= Decimal(benchmark) * Decimal(count)

            print(day_up_down, "开盘卖出", benchmark, opt[len(opt) - 1].price, "收益", temp)

            # 修改记录

            h = history.History(stock_code, -1, benchmark, count)

            opt.pop()

            opt_s.append([day_up_down, benchmark, -1])

    while benchmark * (1 - grid) >= low:

        # 盘中

        # 一手买入 或者 倍数买入

        # 买入

        # 基准价变更

        benchmark = float(Decimal(benchmark * (1 - grid)).quantize(Decimal('0.000')))

        print(day_up_down, "盘中买入", benchmark)

        # 计算的操作

        consume_money += Decimal(benchmark) * Decimal(count)

        if consume_money.compare(max_consume_money) > 0:

            max_consume_money = consume_money

        # 添加记录

        h = history.History(stock_code, 1, benchmark, count)

        opt.append(h)

        opt_b.append([day_up_down, benchmark, 1])

    # open = high开盘价就是最高价的情况 到时候再触发 low 会多买,这是一个假收益

    # 不会那么巧吧开盘价跟最高价一样

    if len(opt) > 0 and open != high:

        while len(opt) > 0 and benchmark * (1 + grid) <= high:

            # 卖出

            # 基准价变更

            benchmark = float(Decimal(benchmark * (1 + grid)).quantize(Decimal('0.000')))

            # 计算的操作

            temp = float(

                ((Decimal(benchmark) - Decimal(opt[len(opt) - 1].price)) * count)

                    .quantize(Decimal('0.00')))

            profit += temp

            consume_money -= Decimal(benchmark) * Decimal(count)

            print(day_up_down, "盘中卖出", benchmark, opt[len(opt) - 1].price, "收益", temp)

            # 修改记录

            h = history.History(stock_code, -1, benchmark, count)

            opt.pop()

            opt_s.append([day_up_down, benchmark, -1])

阅读(1167) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~