Run the strategy object

Finally, we need to build our observations and we can run our strategy.

if __name__ == '__main__':
    # Load prices from Binance
    binance_prices = BinanceDayPriceLoader('BTCUSDT', loader_type=LoaderType.CSV).read(with_run=True)

    # Build observations list
    observations: List[Observation] = [
        Observation(timestamp=timestamp, states={'exchange': BinanceGlobalState(price=price)})
        for timestamp, price in zip(binance_prices.index, binance_prices['price'])
    ]

    # Run the strategy
    params: HolderStrategyParams = HolderStrategyParams(
        BUY_PRICE=50_000, SELL_PRICE=60_000,
        TRADE_SHARE=0.01, INITIAL_BALANCE=100_000
    )
    strategy = BinanceHodlerStrategy(debug=True, params=params)
    result = strategy.run(observations)
    print(result.get_default_metrics())  # show metrics
    result.to_dataframe().to_csv()  # save results of strategy states

Last updated