forked from Lumiwealth/lumibot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
simple_start_alpaca.py
61 lines (52 loc) · 1.28 KB
/
simple_start_alpaca.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import logging
from datetime import datetime
from time import time
from credentials import AlpacaConfig
from lumibot.backtesting import YahooDataBacktesting
from lumibot.brokers import Alpaca
from lumibot.strategies.examples import (
BuyAndHold,
DebtTrading,
Diversification,
DiversifiedLeverage,
FastTrading,
IntradayMomentum,
Momentum,
Simple,
)
from lumibot.tools import indicators
from lumibot.traders import Trader
# Choose your budget and log file locations
budget = 50000
logfile = "logs/test.log"
backtesting_start = datetime(2012, 1, 1)
backtesting_end = datetime(2021, 1, 1)
benchmark_asset = "SPY"
# Initialize all our classes
trader = Trader(logfile=logfile)
broker = Alpaca(AlpacaConfig)
####
# Select our strategy
####
strategy_name = "DiversifiedLeverage"
strategy = DiversifiedLeverage(name=strategy_name, budget=budget, broker=broker)
####
# Backtest
####
stats_file = f"logs/strategy_{strategy_name}_{int(time())}.csv"
plot_file = f"logs/strategy_{strategy_name}_{int(time())}.jpg"
strategy.backtest(
strategy_name,
budget,
YahooDataBacktesting,
backtesting_start,
backtesting_end,
stats_file=stats_file,
plot_file=plot_file,
config=None,
)
####
# Run the strategy
####
trader.add_strategy(strategy)
trader.run_all()