Skip to content

Commit a0b380f

Browse files
committed
Check if market data source is not None
1 parent fafd7e6 commit a0b380f

File tree

5 files changed

+29
-23
lines changed

5 files changed

+29
-23
lines changed

investing_algorithm_framework/app/app.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,10 +278,12 @@ def _initialize_app_for_backtest(
278278
backtest_market_data_sources = [
279279
market_data_source.to_backtest_market_data_source()
280280
for market_data_source in market_data_sources
281+
if market_data_source is not None
281282
]
282283

283284
for market_data_source in backtest_market_data_sources:
284-
market_data_source.config = self.config
285+
if market_data_source is not None:
286+
market_data_source.config = self.config
285287

286288
self.container.market_data_source_service.override(
287289
BacktestMarketDataSourceService(

investing_algorithm_framework/services/backtesting/backtest_service.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from datetime import datetime, timedelta
2-
2+
from dateutil import parser
33
import pandas as pd
44
from tqdm import tqdm
55

@@ -68,8 +68,6 @@ def run_backtest(
6868
strategy_profiles = []
6969
portfolios = self._portfolio_repository.get_all()
7070
initial_unallocated = 0
71-
config = self._configuration_service.config
72-
datetime_format = config.get("DATETIME_FORMAT")
7371

7472
for portfolio in portfolios:
7573
initial_unallocated += portfolio.unallocated
@@ -100,7 +98,7 @@ def run_backtest(
10098
strategy_profile = self.get_strategy_from_strategy_profiles(
10199
strategy_profiles, row['id']
102100
)
103-
index_date = datetime.strptime(str(index), datetime_format)
101+
index_date = parser.parse(str(index))
104102
self.run_backtest_for_profile(
105103
algorithm=algorithm,
106104
strategy=algorithm.get_strategy(strategy_profile.strategy_id),

tests/app/backtesting/test_run_backtests.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,13 @@ def test_run_backtests(self):
6363
initial_balance=1000
6464
)
6565
)
66+
start_date = datetime.utcnow() - timedelta(days=1)
67+
end_date = datetime.utcnow()
68+
app._initialize_app_for_backtest(
69+
backtest_start_date=start_date,
70+
backtest_end_date=end_date,
71+
pending_order_check_interval='2h'
72+
)
6673
reports = app.run_backtests(
6774
algorithms=[algorithm_one, algorithm_two, algorithm_three],
6875
start_date=datetime.utcnow() - timedelta(days=1),

tests/resources/stubs/market_service_stub.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,9 @@ class MarketServiceStub(MarketService):
2020
'EUR': 1000,
2121
}
2222

23-
def __init__(self, config, market_credential_service):
23+
def __init__(self, market_credential_service):
2424
super().__init__(
2525
market_credential_service=market_credential_service,
26-
config=config
2726
)
2827
self._market_credential_service = market_credential_service
2928
self._orders = []

tests/services/test_order_backtest_service.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,7 @@ def test_has_executed_buy_order(self):
513513
"Low": 0.24262,
514514
"Close": 0.24262,
515515
"Volume": 0.24262,
516-
"Timestamp": datetime.now(tz=tzutc())
516+
"Timestamp": datetime.now()
517517
}
518518
]
519519
ohlcv_df = pd.DataFrame(
@@ -532,7 +532,7 @@ def test_has_executed_buy_order(self):
532532
"Low": 0.24162,
533533
"Close": 0.24162,
534534
"Volume": 0.24162,
535-
"Timestamp": datetime.now(tz=tzutc())
535+
"Timestamp": datetime.now()
536536
}
537537
]
538538
ohlcv_df = pd.DataFrame(
@@ -552,7 +552,7 @@ def test_has_executed_buy_order(self):
552552
"Low": 0.24362,
553553
"Close": 0.24362,
554554
"Volume": 0.24362,
555-
"Timestamp": datetime.now(tz=tzutc())
555+
"Timestamp": datetime.now()
556556
}
557557
]
558558
ohlcv_df = pd.DataFrame(
@@ -572,15 +572,15 @@ def test_has_executed_buy_order(self):
572572
"Low": 0.24462,
573573
"Close": 0.24462,
574574
"Volume": 0.24462,
575-
"Timestamp": datetime.now(tz=tzutc())
575+
"Timestamp": datetime.now()
576576
},
577577
{
578578
"Open": 0.24300,
579579
"High": 0.24300,
580580
"Low": 0.24300,
581581
"Close": 0.24300,
582582
"Volume": 0.24300,
583-
"Timestamp": datetime.now(tz=tzutc())
583+
"Timestamp": datetime.now()
584584
}
585585
]
586586
ohlcv_df = pd.DataFrame(
@@ -599,23 +599,23 @@ def test_has_executed_buy_order(self):
599599
"Low": 0.24162,
600600
"Close": 0.24162,
601601
"Volume": 0.24162,
602-
"Timestamp": datetime.now(tz=tzutc())
602+
"Timestamp": datetime.now()
603603
},
604604
{
605605
"Open": 0.24200,
606606
"High": 0.24200,
607607
"Low": 0.24200,
608608
"Close": 0.24200,
609609
"Volume": 0.24200,
610-
"Timestamp": datetime.now(tz=tzutc())
610+
"Timestamp": datetime.now()
611611
},
612612
{
613613
"Open": 0.24300,
614614
"High": 0.24300,
615615
"Low": 0.24300,
616616
"Close": 0.24300,
617617
"Volume": 0.24300,
618-
"Timestamp": datetime.now(tz=tzutc())
618+
"Timestamp": datetime.now()
619619
}
620620
]
621621
ohlcv_df = pd.DataFrame(
@@ -688,7 +688,7 @@ def test_has_executed_sell_order(self):
688688
"Low": 0.24262,
689689
"Close": 0.24262,
690690
"Volume": 0.24262,
691-
"Timestamp": datetime.now(tz=tzutc())
691+
"Timestamp": datetime.now()
692692
}
693693
]
694694
ohlcv_df = pd.DataFrame(
@@ -707,7 +707,7 @@ def test_has_executed_sell_order(self):
707707
"Low": 0.24362,
708708
"Close": 0.24362,
709709
"Volume": 0.24362,
710-
"Timestamp": datetime.now(tz=tzutc())
710+
"Timestamp": datetime.now()
711711
}
712712
]
713713
ohlcv_df = pd.DataFrame(
@@ -727,7 +727,7 @@ def test_has_executed_sell_order(self):
727727
"Low": 0.24162,
728728
"Close": 0.24162,
729729
"Volume": 0.24162,
730-
"Timestamp": datetime.now(tz=tzutc())
730+
"Timestamp": datetime.now()
731731
}
732732
]
733733
ohlcv_df = pd.DataFrame(
@@ -747,15 +747,15 @@ def test_has_executed_sell_order(self):
747747
"Low": 0.24162,
748748
"Close": 0.24162,
749749
"Volume": 0.24162,
750-
"Timestamp": datetime.now(tz=tzutc())
750+
"Timestamp": datetime.now()
751751
},
752752
{
753753
"Open": 0.24000,
754754
"High": 0.24000,
755755
"Low": 0.24000,
756756
"Close": 0.24000,
757757
"Volume": 0.24000,
758-
"Timestamp": datetime.now(tz=tzutc())
758+
"Timestamp": datetime.now()
759759
}
760760
]
761761
ohlcv_df = pd.DataFrame(
@@ -774,23 +774,23 @@ def test_has_executed_sell_order(self):
774774
"Low": 0.24300,
775775
"Close": 0.24300,
776776
"Volume": 0.24300,
777-
"Timestamp": datetime.now(tz=tzutc())
777+
"Timestamp": datetime.now()
778778
},
779779
{
780780
"Open": 0.24162,
781781
"High": 0.24162,
782782
"Low": 0.24162,
783783
"Close": 0.24162,
784784
"Volume": 0.24162,
785-
"Timestamp": datetime.now(tz=tzutc())
785+
"Timestamp": datetime.now()
786786
},
787787
{
788788
"Open": 0.24000,
789789
"High": 0.24000,
790790
"Low": 0.24000,
791791
"Close": 0.24000,
792792
"Volume": 0.24000,
793-
"Timestamp": datetime.now(tz=tzutc())
793+
"Timestamp": datetime.now()
794794
}
795795
]
796796
ohlcv_df = pd.DataFrame(

0 commit comments

Comments
 (0)