Skip to content

Commit

Permalink
added tests (not currently working)
Browse files Browse the repository at this point in the history
  • Loading branch information
grzesir committed Aug 3, 2021
1 parent 4e71e60 commit 15eaa56
Show file tree
Hide file tree
Showing 7 changed files with 1,901 additions and 3 deletions.
6 changes: 4 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ setup.py
/lumibot_profiles.png
/notebooks/scanner_parameters.xml
/lumibot/strategies/examples/technical_analysis.py
/technical_analysis.py
/technical_analysis.pyx
/lumibot/tests/test_ib_broker.py
test.csv
test_strategy.py
test_strategy.py
venv
my_dev
2 changes: 1 addition & 1 deletion lumibot/strategies/examples/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
from .intraday_momentum import IntradayMomentum
from .momentum import Momentum
from .simple import Simple
from .strangle import Strangle
from .strangle import Strangle
1 change: 1 addition & 0 deletions pylintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
known-third-party=lumibot
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def increment_version():
url="https://github.com/Lumiwealth/lumibot",
packages=setuptools.find_packages(),
install_requires=[
"pydantic",
"alpaca_trade_api",
"alpha_vantage",
"ibapi==9.81.1.post1",
Expand Down
1,795 changes: 1,795 additions & 0 deletions tests/data/spy_test.csv

Large diffs are not rendered by default.

54 changes: 54 additions & 0 deletions tests/test_pandas.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#####
# Used to load local lumibot folder into a venv
import os
import sys

myPath = os.path.dirname(os.path.abspath(__file__))
sys.path.insert(0, myPath + "/../")
#####

from datetime import datetime

import pandas as pd

from credentials import AlpacaConfig
from lumibot.backtesting import PandasDataBacktesting
from lumibot.brokers import Alpaca
from lumibot.strategies.examples import Momentum

budget = 50000
logfile = "logs/test.log"
broker = Alpaca(AlpacaConfig)

backtesting_start = datetime(2020, 1, 7)
backtesting_end = datetime(2020, 1, 9)

asset = "SPY"
df = pd.read_csv("tests/data/spy_test.csv")
df = df.set_index("time")
df.index = pd.to_datetime(df.index)
my_data = dict()
my_data[asset] = df

strategy_name = "Momentum"
strategy = Momentum(name=strategy_name, budget=budget, broker=broker)

datestring = datetime.now().strftime("%Y-%m-%d_%H-%M-%S")
stats_file = f"logs/{strategy_name}_{datestring}.csv"
plot_file = f"logs/{strategy_name}_{datestring}.jpg"
# result = strategy.backtest(
# strategy_name,
# budget,
# PandasDataBacktesting,
# backtesting_start,
# backtesting_end,
# stats_file=stats_file,
# plot_file=plot_file,
# config=None,
# pandas_data=my_data,
# )


def test_result():
# Not currently working!
assert 1 == 5
45 changes: 45 additions & 0 deletions tests/test_yahoo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#####
# Used to load local lumibot folder into a venv
import os
import sys

myPath = os.path.dirname(os.path.abspath(__file__))
sys.path.insert(0, myPath + "/../")
#####

from datetime import datetime

import pandas as pd

from credentials import AlpacaConfig
from lumibot.backtesting import YahooDataBacktesting
from lumibot.brokers import Alpaca
from lumibot.strategies.examples import Momentum

budget = 50000
logfile = "logs/test.log"
broker = Alpaca(AlpacaConfig)

backtesting_start = datetime(2020, 1, 1)
backtesting_end = datetime(2020, 2, 1)

strategy_name = "Momentum"
strategy = Momentum(name=strategy_name, budget=budget, broker=broker)

datestring = datetime.now().strftime("%Y-%m-%d_%H-%M-%S")
stats_file = f"logs/{strategy_name}_{datestring}.csv"
plot_file = f"logs/{strategy_name}_{datestring}.jpg"
result = strategy.backtest(
strategy_name,
budget,
YahooDataBacktesting,
backtesting_start,
backtesting_end,
stats_file=stats_file,
plot_file=plot_file,
config=None,
)


def test_result():
assert result == 5

0 comments on commit 15eaa56

Please sign in to comment.