Skip to content

Commit 92529ba

Browse files
committed
Fix flake8 issues
1 parent fb30e63 commit 92529ba

File tree

21 files changed

+121
-175
lines changed

21 files changed

+121
-175
lines changed

investing_algorithm_framework/app/algorithm.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1413,7 +1413,7 @@ def add_trailing_stop_loss(self, trade, percentage: int) -> None:
14131413
"""
14141414
self.trade_service.add_trailing_stop_loss(trade, percentage=percentage)
14151415

1416-
def close_trade(self, trade, precision = None) -> None:
1416+
def close_trade(self, trade, precision=None) -> None:
14171417
"""
14181418
Function to close a trade. This function will close a trade by
14191419
creating a market order to sell the position. If the precision

investing_algorithm_framework/app/app.py

Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -197,21 +197,24 @@ def initialize(self):
197197
# Initialize services in backtest
198198
if Environment.BACKTEST.equals(config[ENVIRONMENT]):
199199

200+
configuration_service = self.container.configuration_service()
201+
portfolio_conf_service = self.container \
202+
.portfolio_configuration_service()
203+
portfolio_snap_service = self.container \
204+
.portfolio_snapshot_service()
205+
market_cred_service = self.container.market_credential_service()
200206
# Override the portfolio service with the backtest
201207
# portfolio service
202208
self.container.portfolio_service.override(
203209
BacktestPortfolioService(
204-
configuration_service=self.container.configuration_service(),
205-
market_credential_service=self.container
206-
.market_credential_service(),
210+
configuration_service=configuration_service,
211+
market_credential_service=market_cred_service,
207212
market_service=self.container.market_service(),
208213
position_service=self.container.position_service(),
209214
order_service=self.container.order_service(),
210215
portfolio_repository=self.container.portfolio_repository(),
211-
portfolio_configuration_service=self.container
212-
.portfolio_configuration_service(),
213-
portfolio_snapshot_service=self.container
214-
.portfolio_snapshot_service(),
216+
portfolio_configuration_service=portfolio_conf_service,
217+
portfolio_snapshot_service=portfolio_snap_service
215218
)
216219
)
217220

@@ -232,19 +235,24 @@ def initialize(self):
232235
)
233236
)
234237

238+
portfolio_conf_service = self.container.\
239+
portfolio_configuration_service()
240+
portfolio_snap_service = self.container.\
241+
portfolio_snapshot_service()
242+
configuration_service = self.container.configuration_service()
243+
market_data_source_service = self.container.\
244+
market_data_source_service()
235245
# Override the order service with the backtest order service
236246
self.container.order_service.override(
237247
OrderBacktestService(
238248
trade_service=self.container.trade_service(),
239249
order_repository=self.container.order_repository(),
240250
position_repository=self.container.position_repository(),
241251
portfolio_repository=self.container.portfolio_repository(),
242-
portfolio_configuration_service=self.container
243-
.portfolio_configuration_service(),
244-
portfolio_snapshot_service=self.container
245-
.portfolio_snapshot_service(),
246-
configuration_service=self.container.configuration_service(),
247-
market_data_source_service=self.container.market_data_source_service(),
252+
portfolio_configuration_service=portfolio_conf_service,
253+
portfolio_snapshot_service=portfolio_snap_service,
254+
configuration_service=configuration_service,
255+
market_data_source_service=market_data_source_service
248256
)
249257
)
250258

@@ -319,15 +327,17 @@ def initialize(self):
319327
)
320328

321329
for portfolio_configuration \
322-
in portfolio_configuration_service.get_all():
330+
in portfolio_configuration_service.get_all():
323331

324332
if not portfolio_service.exists(
325333
{"identifier": portfolio_configuration.identifier}
326334
):
327-
portfolio = portfolio_service\
328-
.create_portfolio_from_configuration(
329-
portfolio_configuration, initial_amount=initial_backtest_amount,
335+
portfolio = (
336+
portfolio_service.create_portfolio_from_configuration(
337+
portfolio_configuration,
338+
initial_amount=initial_backtest_amount,
330339
)
340+
)
331341
else:
332342
synced_portfolios = []
333343

@@ -637,7 +647,9 @@ def run_backtest(
637647
BACKTESTING_END_DATE: backtest_date_range.end_date,
638648
DATABASE_NAME: "backtest-database.sqlite3",
639649
DATABASE_DIRECTORY_NAME: "backtest_databases",
640-
BACKTESTING_PENDING_ORDER_CHECK_INTERVAL: pending_order_check_interval,
650+
BACKTESTING_PENDING_ORDER_CHECK_INTERVAL: (
651+
pending_order_check_interval
652+
),
641653
BACKTESTING_INITIAL_AMOUNT: initial_amount
642654
})
643655

@@ -748,7 +760,9 @@ def run_backtests(
748760
BACKTESTING_END_DATE: date_range.end_date,
749761
DATABASE_NAME: "backtest-database.sqlite3",
750762
DATABASE_DIRECTORY_NAME: "backtest_databases",
751-
BACKTESTING_PENDING_ORDER_CHECK_INTERVAL: pending_order_check_interval
763+
BACKTESTING_PENDING_ORDER_CHECK_INTERVAL: (
764+
pending_order_check_interval
765+
)
752766
})
753767
self.initialize_config()
754768

investing_algorithm_framework/app/strategy.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from investing_algorithm_framework.domain import OperationalException, Position
66
from investing_algorithm_framework.domain import \
77
TimeUnit, StrategyProfile, Trade, ENVIRONMENT, Environment, \
8-
BACKTESTING_INDEX_DATETIME, TradeStatus
8+
BACKTESTING_INDEX_DATETIME
99
from .algorithm import Algorithm
1010

1111

@@ -617,4 +617,4 @@ def last_run(self) -> datetime:
617617
Returns:
618618
DateTime: The last run of the strategy
619619
"""
620-
return self.algorithm.last_run()
620+
return self.algorithm.last_run()

investing_algorithm_framework/domain/models/backtesting/backtest_report.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,10 @@ def to_dict(self):
424424
"average_trade_duration": self.average_trade_duration,
425425
"average_trade_size": self.average_trade_size,
426426
"positions": [position.to_dict() for position in self.positions],
427-
"trades": [trade.to_dict(datetime_format=DATETIME_FORMAT) for trade in self.trades],
427+
"trades": [
428+
trade.to_dict(datetime_format=DATETIME_FORMAT)
429+
for trade in self.trades
430+
],
428431
"orders": [
429432
order.to_dict(datetime_format=DATETIME_FORMAT)
430433
for order in self.orders

investing_algorithm_framework/domain/models/market_data_type.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ def from_string(value: str):
1717
if value.upper() == entry.value:
1818
return entry
1919

20-
2120
raise ValueError(
2221
f"Could not convert {value} to MarketDataType"
2322
)

investing_algorithm_framework/domain/models/order/order.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
OrderStatus
1212
from investing_algorithm_framework.domain.models.order.order_type import \
1313
OrderType
14-
from investing_algorithm_framework.domain import DATETIME_FORMAT
1514

1615
logger = logging.getLogger("investing_algorithm_framework")
1716

investing_algorithm_framework/domain/models/time_frame.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ class TimeFrame(Enum):
2020
ONE_MONTH = "1M"
2121
ONE_YEAR = "1Y"
2222

23-
2423
@staticmethod
2524
def from_string(value: str):
2625

investing_algorithm_framework/domain/models/trade/trade.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from investing_algorithm_framework.domain.models.base_model import BaseModel
22
from investing_algorithm_framework.domain.models.order import OrderSide
3-
from investing_algorithm_framework.domain.constants import DATETIME_FORMAT
43
from investing_algorithm_framework.domain.models.trade.trade_status import \
54
TradeStatus
65

@@ -35,8 +34,10 @@ class Trade(BaseModel):
3534
created_at (datetime): the datetime when the trade was created
3635
updated_at (datetime): the datetime when the trade was last updated
3736
status (str): the status of the trade
38-
stop_loss_percentage (float): the stop loss percentage of the trade
39-
trailing_stop_loss_percentage (float): the trailing stop loss percentage
37+
stop_loss_percentage (float): the stop loss percentage of
38+
the trade
39+
trailing_stop_loss_percentage (float): the trailing stop
40+
loss percentage
4041
"""
4142

4243
def __init__(
@@ -52,13 +53,13 @@ def __init__(
5253
cost,
5354
remaining,
5455
status,
55-
net_gain = 0,
56-
last_reported_price = None,
57-
high_water_mark = None,
58-
updated_at = None,
59-
stop_loss_percentage = None,
60-
trailing_stop_loss_percentage = None,
61-
stop_loss_triggered = False,
56+
net_gain=0,
57+
last_reported_price=None,
58+
high_water_mark=None,
59+
updated_at=None,
60+
stop_loss_percentage=None,
61+
trailing_stop_loss_percentage=None,
62+
stop_loss_triggered=False,
6263
):
6364
self.id = id
6465
self.orders = orders

investing_algorithm_framework/infrastructure/models/market_data_sources/csv.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,6 @@ def get_data(
119119
if start_date > self._end_date_data_source:
120120
return polars.DataFrame()
121121

122-
123122
df = polars.read_csv(
124123
self.csv_file_path, columns=self._columns, separator=","
125124
)

investing_algorithm_framework/infrastructure/models/market_data_sources/pandas.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from datetime import datetime
21
from pandas import DataFrame
32

43
from investing_algorithm_framework.domain import OHLCVMarketDataSource, \
@@ -41,10 +40,7 @@ def prepare_data(self, config, backtest_start_date, backtest_end_date,
4140
def empty(self):
4241
pass
4342

44-
def get_data(self,
45-
config,
46-
date
47-
):
43+
def get_data(self, config, date):
4844
pass
4945

5046
def _validate_dataframe_with_ohlcv_structure(self):

0 commit comments

Comments
 (0)