from nibbler.trading import indicators from nibbler import plot import pandas as pd if __name__ == "__main__": from ta import momentum, trend import pathlib as pt cwd = pt.Path(__file__).parent resources_folder = cwd.parent / "../resources" csv_file = resources_folder / "BitcoinBinance1hr.csv" df = pd.read_csv(csv_file) indicator = indicators.Indicator(trend.ema_indicator) indicator_values = indicator(df) p = plot.candlesticks(df) sg_filter = indicators.trend.SavitzkyGolayOpen() sg_filter.plot(df, fig=p) plot.show(indicator.plot(df, fig=p)) sg_filter = indicators.trend.SavitzkyGolayLow.random_initialization( 20, 100, 3, 7) sg_filter.plot(df, fig=p) plot.show(p)
leverage=3) strategy_population = MarketStrategyInitialization( DragonflyDoji, SavitzkyGolayMaxFilteredGrads, MarketLong, buy_signal_kwargs, sell_signal_kwargs, strategy_kwargs, n_population=500) # this guard is necessary for enabling multiprocesssing if __name__ == "__main__": cwd = pt.Path(__file__).parent resource_folder = cwd / "../../resources" data_file = resource_folder / "BitcoinBinance1hr.csv" dataframe = pd.read_csv(data_file) optimizer = BruteForceSingleDataset(strategy_population) optimizer.calculate_fitness(dataframe[0:5000], n_processors=8) p = optimizer.population[-1].plot_trade_and_equity() plot.show(p) print(optimizer.population[-1].trade_log) nd.save(pt.Path(__file__).parent / "best_lad", optimizer.population[-1])
import nibbler as nd from nibbler.trading import signals from nibbler.trading import strategy from nibbler import plot import pandas as pd import pathlib as pt cwd = pt.Path(__file__).parent resource_folder = cwd/"../../resources" data_file = resource_folder/"BitcoinBinance1hr.csv" dataframe = pd.read_csv(data_file) if __name__ == "__main__": buy_signal = signals.buy.SavitzkyGolayMin() sell_signal = signals.sell.SavitzkyGolayMax() strategy = strategy.MarketLong( buy_signal, sell_signal, leverage = 1, use_leverage = True ) strategy.walk_dataset(dataframe.iloc[0:5000]) plot.show( strategy.plot_trade_and_equity() ) print(strategy.trade_log) strategy.save("strat")
from nibbler import trading as td from nibbler import plot import pathlib as pt import pandas as pd if __name__ == "__main__": cwd = pt.Path(__file__).parent resources_folder = cwd / "../../resources" corn_file = resources_folder / "BitcoinBinance1hr.csv" p = plot.csv.candlesticks(corn_file, skip=20000) plot.show(p) df = pd.read_csv(corn_file) plot.show(plot.candlesticks(df))