Пример #1
0
def backtesting(
    test_data,
    ticker="KRW-XRP",
):
    seed_movey = 100000
    count = 30

    bot = Trader(
        ticker=ticker,
        seed_movey=seed_movey,
    )

    results = []
    for i in range(test_data.shape[0] - count):
        data = test_data.iloc[i:count + i]
        low, high = data["low"][-1], data["high"][-1]
        bot.current_price = data["close"][-2]
        status, price = bot.check_market_status_price(data)

        result = {"timepoint": data.index[-1]}
        if status == "buy":
            available, price = check_available_bought_price(price, low, high)
            if available:
                if bot.buy(price):
                    result["status"] = "buy"
        elif status == "sell":
            available, price = check_available_sold_price(price, low, high)
            if available:
                if bot.sell(price):
                    result["status"] = "sell"
        if not hasattr(result, "status"):
            result["status"] = "none"

        result.update(bot.wallet)
        results.append(result)

    ROI = (bot.total_money / seed_movey) * 100
    print(ROI, "!!!!!")
    return ROI, results