def run_indicator(indicator_name): strat = Strategy(indicator_name) strat.add_market_indicator(indicator_name) click.secho('Running {}'.format(indicator_name), fg='cyan') strat.run(viz=False) click.secho('{}: {}'.format(indicator_name, strat.quant_results['net_profit_pct']), fg='cyan') # import pdb; pdb.set_trace() return strat
def run(datasets): """Runs s strategy based on provided Blockchain dataset codes \b Example: bchain -s NTRAN -s CPTRA \b Available Dataset Codes: - TOTBC - Total Bitcoins - MKTCP - Bitcoin Market Capitalization - TRFEE - Bitcoin Total Transaction Fees - TRFUS - Bitcoin Total Transaction Fees USD - NETDF - Bitcoin Network Deficit - NTRAN - Bitcoin Number of Transactions - NTRAT - Bitcoin Total Number of Transactions - NTREP - Bitcoin Number of Transactions Excluding Popular Addresses - NADDU - Bitcoin Number of Unique Bitcoin Addresses Used - NTRBL - Bitcoin Number of Transaction per Block - TOUTV - Bitcoin Total Output Volume - ETRAV - Bitcoin Estimated Transaction Volume - ETRVU - Bitcoin Estimated Transaction Volume USD - TRVOU - Bitcoin USD Exchange Trade Volume - TVTVR - Bitcoin Trade Volume vs Transaction Volume Ratio - MKPRU - Bitcoin Market Price USD - CPTRV - Bitcoin Cost % of Transaction Volume - CPTRA - Bitcoin Cost Per Transaction - HRATE - Bitcoin Hash Rate - MIREV - Bitcoin Miners Revenue - ATRCT - Bitcoin Median Transaction Confirmation Time - BCDDC - Bitcoin Days Destroyed Cumulative - BCDDE - Bitcoin Days Destroyed - BCDDW - Bitcoin Days Destroyed (Minimum Age 1 Week) - BCDDM - Bitcoin Days Destroyed (Minimum Age 1 Month) - BCDDY - Bitcoin Days Destroyed (Minimum Age 1 Year) - BLCHS - Bitcoin api.blockchain Size - AVBLS - Bitcoin Average Block Size - MWTRV - Bitcoin My Wallet Transaction Volume - MWNUS - Bitcoin My Wallet Number of Users - MWNTD - Bitcoin My Wallet Number of Transaction Per Day - MIOPM - Bitcoin Mining Operating Margin - DIFF - Bitcoin Difficulty """ click.secho("Executing using datasets:\n{}".format(datasets), fg="white") strat = Strategy() strat.use_dataset("quandl", columns=list(datasets)) strat.run()
def run(keywords, asset): """Runs strategy using Google Search Trends Example: trends 'btc' 'btc usd' 'btc price' """ keywords = list(keywords) if asset: keywords.append(CONFIG["ASSET"].replace("_", " ")) strat = Strategy() strat.use_dataset("google", columns=keywords) click.secho("Analysis Google Trends:\n{}".format(keywords), fg="white") strat.run()
log.info("buying position cheaper than cost basis {} < {}".format( context.price, context.cost_basis)) order( asset=context.asset, amount=context.buy_increment, limit_price=context.price * (1 + context.SLIPPAGE_ALLOWED), ) @strat.sell_order def sell(context): profit = (context.price * context.position.amount) - ( context.cost_basis * context.position.amount) log.info("closing position, taking profit: {}".format(profit)) order_target_percent(asset=context.asset, target=0, limit_price=context.price * (1 - context.SLIPPAGE_ALLOWED)) @strat.analyze() def analyze(context, results, pos): ending_cash = results.cash[-1] log.info("Ending cash: ${}".format(ending_cash)) log.info("Completed for {} trading periods".format(context.i)) if __name__ == "__main__": log.info("Strategy Schema:\n{}".format(strat.serialize())) strat.run()