Skip to content

Commit

Permalink
Merge pull request #656 from Lumiwealth/m-dev
Browse files Browse the repository at this point in the history
Implement strategy.run_live() in example strategies
  • Loading branch information
grzesir authored Dec 7, 2024
2 parents 51c9b72 + 78cef9a commit 31321dd
Show file tree
Hide file tree
Showing 14 changed files with 14 additions and 79 deletions.
7 changes: 1 addition & 6 deletions lumibot/example_strategies/crypto_important_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
from lumibot.brokers import Ccxt
from lumibot.entities import Asset
from lumibot.strategies.strategy import Strategy
from lumibot.traders import Trader


class ImportantFunctions(Strategy):
def initialize(self):
Expand Down Expand Up @@ -123,8 +121,6 @@ def on_trading_iteration(self):


if __name__ == "__main__":
trader = Trader()

KRAKEN_CONFIG = {
"exchange_id": "kraken",
"apiKey": "YOUR_API_KEY",
Expand All @@ -145,5 +141,4 @@ def on_trading_iteration(self):
broker=broker,
)

trader.add_strategy(strategy)
strategy_executors = trader.run_all()
strategy.run_live()
8 changes: 1 addition & 7 deletions lumibot/example_strategies/forex_hold_to_expiry.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,8 @@ def on_trading_iteration(self):
is_live = True

if is_live:
from lumibot.traders import Trader

trader = Trader()

strategy = FuturesHoldToExpiry()

trader.add_strategy(strategy)
strategy_executors = trader.run_all()
strategy.run_live()

else:
from lumibot.backtesting import PolygonDataBacktesting
Expand Down
8 changes: 1 addition & 7 deletions lumibot/example_strategies/futures_hold_to_expiry.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,5 @@ def on_trading_iteration(self):
)

else:
from lumibot.traders import Trader

trader = Trader()

strategy = FuturesHoldToExpiry()

trader.add_strategy(strategy)
strategy_executors = trader.run_all()
strategy.run_live()
5 changes: 1 addition & 4 deletions lumibot/example_strategies/lifecycle_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,7 @@ def after_market_closes(self):
else:
from lumibot.credentials import ALPACA_CONFIG
from lumibot.brokers import Alpaca
from lumibot.traders import Trader

trader = Trader()
broker = Alpaca(ALPACA_CONFIG)
strategy = LifecycleLogger(broker=broker)
trader.add_strategy(strategy)
strategy_executors = trader.run_all()
strategy.run_live()
6 changes: 1 addition & 5 deletions lumibot/example_strategies/options_hold_to_expiry.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,11 @@ def on_trading_iteration(self):
from credentials import INTERACTIVE_BROKERS_CONFIG

from lumibot.brokers import InteractiveBrokers
from lumibot.traders import Trader

trader = Trader()

broker = InteractiveBrokers(INTERACTIVE_BROKERS_CONFIG)
strategy = OptionsHoldToExpiry(broker=broker)

trader.add_strategy(strategy)
strategy_executors = trader.run_all()
strategy.run_live()

else:
from lumibot.backtesting import PolygonDataBacktesting
Expand Down
6 changes: 1 addition & 5 deletions lumibot/example_strategies/simple_start_single_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
from lumibot.backtesting import YahooDataBacktesting
from lumibot.brokers import Alpaca
from lumibot.strategies.strategy import Strategy
from lumibot.traders import Trader


class MyStrategy(Strategy):
def initialize(self, symbol=""):
Expand All @@ -26,7 +24,6 @@ def on_trading_iteration(self):
if __name__ == "__main__":
live = True

trader = Trader()
broker = Alpaca(AlpacaConfig)
strategy = MyStrategy(broker, symbol="SPY")

Expand All @@ -42,5 +39,4 @@ def on_trading_iteration(self):
)
else:
# Run the strategy live
trader.add_strategy(strategy)
trader.run_all()
strategy.run_live()
7 changes: 1 addition & 6 deletions lumibot/example_strategies/stock_bracket.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,11 @@ def on_trading_iteration(self):
from credentials import ALPACA_CONFIG

from lumibot.brokers import Alpaca
from lumibot.traders import Trader

trader = Trader()

broker = Alpaca(ALPACA_CONFIG)

strategy = StockBracket(broker=broker)

trader.add_strategy(strategy)
strategy_executors = trader.run_all()
strategy.run_live()

else:
from lumibot.backtesting import YahooDataBacktesting
Expand Down
7 changes: 1 addition & 6 deletions lumibot/example_strategies/stock_buy_and_hold.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,8 @@ def on_trading_iteration(self):
}

from lumibot.brokers import Alpaca
from lumibot.traders import Trader

trader = Trader()

broker = Alpaca(ALPACA_CONFIG)

strategy = BuyAndHold(broker=broker)

trader.add_strategy(strategy)
strategy_executors = trader.run_all()
strategy.run_live()
5 changes: 1 addition & 4 deletions lumibot/example_strategies/stock_diversified_leverage.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from lumibot.brokers import Alpaca
from lumibot.entities import TradingFee
from lumibot.strategies.strategy import Strategy
from lumibot.traders import Trader

"""
Strategy Description
Expand Down Expand Up @@ -127,11 +126,9 @@ def rebalance_portfolio(self):
####
from credentials import ALPACA_CONFIG

trader = Trader()
broker = Alpaca(ALPACA_CONFIG)
strategy = DiversifiedLeverage(broker=broker)
trader.add_strategy(strategy)
trader.run_all()
strategy.run_live()

else:
####
Expand Down
6 changes: 1 addition & 5 deletions lumibot/example_strategies/stock_limit_and_trailing_stops.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,16 +68,12 @@ def on_trading_iteration(self):
from credentials import ALPACA_CONFIG

from lumibot.brokers import Alpaca
from lumibot.traders import Trader

trader = Trader()

broker = Alpaca(ALPACA_CONFIG)

strategy = LimitAndTrailingStop(broker=broker)

trader.add_strategy(strategy)
strategy_executors = trader.run_all()
strategy.run_live()

else:
from lumibot.backtesting import YahooDataBacktesting
Expand Down
7 changes: 1 addition & 6 deletions lumibot/example_strategies/stock_momentum.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,16 +153,11 @@ def get_assets_momentums(self):
if is_live:
from lumibot.credentials import ALPACA_CONFIG
from lumibot.brokers import Alpaca
from lumibot.traders import Trader

trader = Trader()

broker = Alpaca(ALPACA_CONFIG)

strategy = Momentum(broker=broker)

trader.add_strategy(strategy)
strategy_executors = trader.run_all()
strategy.run_live()

else:
from lumibot.backtesting import YahooDataBacktesting
Expand Down
7 changes: 1 addition & 6 deletions lumibot/example_strategies/stock_oco.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,11 @@ def on_trading_iteration(self):
from credentials import ALPACA_CONFIG

from lumibot.brokers import Alpaca
from lumibot.traders import Trader

trader = Trader()

broker = Alpaca(ALPACA_CONFIG)

strategy = StockOco(broker=broker)

trader.add_strategy(strategy)
strategy_executors = trader.run_all()
strategy.run_live()

else:
from lumibot.backtesting import YahooDataBacktesting
Expand Down
3 changes: 1 addition & 2 deletions lumibot/example_strategies/strangle.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
import time
from itertools import cycle

import pandas as pd
from yfinance import Ticker, download
from yfinance import Ticker

from lumibot.strategies.strategy import Strategy

Expand Down
11 changes: 1 addition & 10 deletions lumibot/example_strategies/test_broker_functions.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
from datetime import date, datetime
from decimal import Decimal

import logging
from lumibot.brokers import InteractiveBrokers, Tradier, InteractiveBrokersREST, ExampleBroker
from lumibot.entities import Asset, Order
from lumibot.strategies.strategy import Strategy
from lumibot.traders import Trader
import yfinance as yf
from datetime import timedelta

# from lumiwealth_tradier import Tradier as _Tradier
Expand Down Expand Up @@ -132,8 +126,5 @@ def on_new_order(self, order):
# broker = ExampleBroker()

strategy = BrokerTest()
strategy.run_live()

trader = Trader()

trader.add_strategy(strategy)
strategy_executors = trader.run_all()

0 comments on commit 31321dd

Please sign in to comment.