Browse Source

Cleaning

master
Barthélemy Paléologue 5 months ago
parent
commit
e3e4f23e5a
  1. 4
      auto_trading/strat/buyupselldown.py
  2. 26
      tests/strat/test_buyUpSellDown.py

4
auto_trading/strat/buyupselldown.py

@ -50,10 +50,6 @@ class BuyUpSellDown(Strategy):
for (index, row) in indicators_results.iterrows():
trust += row[stock_name]
logging.info(trust)
#logging.info(indicators_results.get("AAPL"))
if market_price is None:
# retry later
continue

26
tests/strat/test_buyUpSellDown.py

@ -10,25 +10,24 @@ from pandas import DataFrame, Series # type: ignore
from auto_trading.interfaces import PTFState as State
from auto_trading.orders import Long, Short
date = datetime.strptime("2015-03-31", "%Y-%m-%d")
today = date.today()
today = datetime.today()
@pytest.mark.parametrize(
"data, state, output",
[
(DataFrame(), State(balance=0, stocks={}), []),
(
DataFrame({"close": {(date, "AAPL"): []}}),
DataFrame({"close": {(today, "AAPL"): []}}),
State(balance=10, stocks={}),
[],
),
(
DataFrame({"close": {(date, "AAPL"): 10}}),
DataFrame({"close": {(today, "AAPL"): 10}}),
State(balance=10, stocks={}),
[],
),
(
DataFrame({"close": {(date, "AAPL"): 10}}),
DataFrame({"close": {(today, "AAPL"): 10}}),
State(
balance=10,
stocks={"AAPL": 5},
@ -36,7 +35,7 @@ today = date.today()
[],
),
(
DataFrame({"close": {(date, "AAPL"): 10, (date, "TSLA"): 10}}),
DataFrame({"close": {(today, "AAPL"): 10, (today, "TSLA"): 10}}),
State(
balance=10,
stocks={"AAPL": 5, "TSLA": 5},
@ -46,8 +45,8 @@ today = date.today()
(
DataFrame({
"close": {
(date, "AAPL"): 5,
(date, "TSLA"): 50,
(today, "AAPL"): 5,
(today, "TSLA"): 50,
(today + timedelta(days=1), "AAPL"): 7,
(today + timedelta(days=1), "TSLA"): 40,
@ -63,22 +62,13 @@ today = date.today()
(today + timedelta(days=5), "AAPL"): 30,
(today + timedelta(days=5), "TSLA"): 5,
(today + timedelta(days=6), "AAPL"): 40,
(today + timedelta(days=6), "TSLA"): 2,
(today + timedelta(days=7), "AAPL"): 60,
(today + timedelta(days=7), "TSLA"): 1,
(today + timedelta(days=8), "AAPL"): 80,
(today + timedelta(days=8), "TSLA"): 1,
}
}),
State(
balance=100,
stocks={"TSLA":20},
),
[Long(stock="AAPL", amount=0.625, price=80), Short(stock="TSLA", amount=20, price=1)],
[Long(stock="AAPL", amount=1.6666666666666667, price=30), Short(stock="TSLA", amount=20, price=5)],
),
],
)

Loading…
Cancel
Save