wbfdm 1.46.11__py2.py3-none-any.whl → 1.46.13__py2.py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of wbfdm might be problematic. Click here for more details.

@@ -14,6 +14,7 @@ from wbfdm.models import Instrument, InstrumentPrice
14
14
 
15
15
  from ..dto import Metric, MetricField, MetricKey
16
16
  from ..exceptions import MetricInvalidParameterException
17
+ from .utils import get_today
17
18
 
18
19
  T = TypeVar("T", bound=Model)
19
20
 
@@ -82,11 +83,16 @@ class InstrumentMetricBaseBackend(AbstractBackend[Instrument]):
82
83
  return super().get_queryset().filter(is_investable_universe=True)
83
84
 
84
85
  def _get_valid_date(self, instrument: Instrument) -> date:
86
+ val_date = None
85
87
  if self.val_date is None and instrument.last_price_date:
86
- return instrument.last_price_date
88
+ val_date = instrument.last_price_date
87
89
  elif self.val_date:
88
90
  with suppress(InstrumentPrice.DoesNotExist):
89
- return instrument.prices.filter(date__lte=self.val_date).latest("date").date
91
+ val_date = instrument.prices.filter(date__lte=self.val_date).latest("date").date
92
+ if val_date:
93
+ return min(
94
+ [val_date, (get_today() - pd.tseries.offsets.BDay(1)).date()]
95
+ ) # ensure that value date is at least lower than today (otherwise, we might compute performance for intraday, which we do not want yet
90
96
  else:
91
97
  raise MetricInvalidParameterException()
92
98
 
@@ -12,6 +12,7 @@ from wbfdm.models import Instrument, InstrumentPrice, RelatedInstrumentThroughMo
12
12
  from ..decorators import register
13
13
  from ..dto import Metric, MetricField, MetricKey
14
14
  from .base import BaseDataloader, InstrumentMetricBaseBackend
15
+ from .utils import get_today
15
16
 
16
17
  PERFORMANCE_METRIC = MetricKey(
17
18
  key="performance",
@@ -247,7 +248,7 @@ class InstrumentPerformanceMetricBackend(InstrumentMetricBaseBackend):
247
248
  attrs = super().get_serializer_field_attr(metric_field)
248
249
  pivot_date = self.val_date
249
250
  if not pivot_date:
250
- pivot_date = (date.today() - pd.tseries.offsets.BDay(1)).date()
251
+ pivot_date = (get_today() - pd.tseries.offsets.BDay(1)).date()
251
252
  if "previous" in metric_field.key:
252
253
  pivot_date = Dataloader.get_performance_date_map(pivot_date)[metric_field.key.replace("previous_", "")]
253
254
 
@@ -0,0 +1,5 @@
1
+ from datetime import date
2
+
3
+
4
+ def get_today(): # utility function to be able to mock today in the test suit
5
+ return date.today()
@@ -1,5 +1,6 @@
1
1
  from datetime import timedelta
2
2
  from decimal import Decimal
3
+ from unittest.mock import patch
3
4
 
4
5
  import pandas as pd
5
6
  import pytest
@@ -14,13 +15,18 @@ fake = Faker()
14
15
 
15
16
  @pytest.mark.django_db
16
17
  class TestInstrumentPerformanceMetricBackend:
17
- def test_compute_metrics(self, weekday, instrument, instrument_price_factory):
18
+ @patch("wbfdm.contrib.metric.backends.performances.get_today")
19
+ def test_compute_metrics(self, mock_fct, weekday, instrument, instrument_price_factory):
18
20
  from wbfdm.contrib.metric.backends.performances import ( # we import locally to avoid database access pytest error
19
21
  InstrumentPerformanceMetricBackend,
20
22
  )
21
23
 
24
+ # mock_fct.return_value = weekday # return weekday as date.today
22
25
  backend = InstrumentPerformanceMetricBackend(weekday)
23
26
 
27
+ price_intraday = instrument_price_factory( # noqa
28
+ instrument=instrument, calculated=False, date=(weekday + BDay(1)).date()
29
+ )
24
30
  price_today = instrument_price_factory.create(instrument=instrument, calculated=False, date=weekday)
25
31
  price_yesterday = instrument_price_factory.create(
26
32
  instrument=instrument, calculated=False, date=weekday - BDay(1)
wbfdm/tasks.py CHANGED
@@ -63,7 +63,7 @@ def update_of_investable_universe_data(
63
63
  investable_universe_updated.send(sender=Instrument, end_date=end)
64
64
  if with_background_tasks:
65
65
  daily_update_instrument_price_statistics.delay(from_date=start, to_date=end)
66
- update_instrument_metrics_as_task.delay()
66
+ update_instrument_metrics_as_task.delay()
67
67
 
68
68
 
69
69
  @shared_task(queue="portfolio")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: wbfdm
3
- Version: 1.46.11
3
+ Version: 1.46.13
4
4
  Summary: The workbench module ensures rapid access to diverse financial data (market, fundamental, forecasts, ESG), with features for storing instruments, classifying them, and conducting financial analysis.
5
5
  Author-email: Christopher Wittlinger <c.wittlinger@stainly.com>
6
6
  Requires-Dist: roman==4.*
@@ -6,7 +6,7 @@ wbfdm/jinja2.py,sha256=pkIC1U-0rf6vn0DDEUzZ8dPYiTGEPY8LBTRMi9wYiuc,199
6
6
  wbfdm/menu.py,sha256=c_uP0wIxboHvY0BfHbYPI9GI4F41UxSgREqbzcaxzHM,399
7
7
  wbfdm/preferences.py,sha256=8ghDcaapOMso1kjtNfKbSFykPUTxzqI5R77gM3BgiMs,927
8
8
  wbfdm/signals.py,sha256=PhAsFpQZF1YVe5UpedaRelUD_TVjemqRYm1HzV-bhmY,597
9
- wbfdm/tasks.py,sha256=55yXOyVe6-TeJRHAElGzt-VCw3a_23liQP8B8S2PFRM,4359
9
+ wbfdm/tasks.py,sha256=2jb5K3qqsA-IKjT2Jf7Ogl7Bp9XBDM8TCcd-L61VckY,4363
10
10
  wbfdm/urls.py,sha256=pDp9I0kktxicad8sXXEUT7402jZPMJNcE5R1doTlcMw,8887
11
11
  wbfdm/utils.py,sha256=4cWrCpqXxHIjtSlt4DDPFvmtaqXw_H0nqhM6sGuXx0o,1938
12
12
  wbfdm/admin/__init__.py,sha256=Z1VtH_gjD71K79KcD-2Q2Lu_p_7j0akMZj7gNxdz1CQ,1398
@@ -60,9 +60,10 @@ wbfdm/contrib/metric/admin/__init__.py,sha256=FW3qhfmS5tA4RNOv9Zse56dICDG7zgdHgB
60
60
  wbfdm/contrib/metric/admin/instruments.py,sha256=mPwwdwxeuo6nvyJ2_xolVdlpK05KMlzOPLaSlh1PtHE,419
61
61
  wbfdm/contrib/metric/admin/metrics.py,sha256=SJU-5ona3npgRjTgDoHvo9aCztq-VMnIVvvsdk5bWSs,1133
62
62
  wbfdm/contrib/metric/backends/__init__.py,sha256=Bl7bGEYVx38uiN2BS-0pr2WpIkbhUl7yPCEwt1W4tUg,128
63
- wbfdm/contrib/metric/backends/base.py,sha256=xFFYcDA9a0B3jrLRLfsvu7VFWqghtSlcmGYJ_6vlDYc,6432
64
- wbfdm/contrib/metric/backends/performances.py,sha256=MZvm35NVMjFjCebrzFec6kDXojtvyaimTrgMbqiGaME,11614
63
+ wbfdm/contrib/metric/backends/base.py,sha256=TTTcNHjuzGCnzoDBqYZOb-nT7fnuYjjp0D6ACqR5yXk,6765
64
+ wbfdm/contrib/metric/backends/performances.py,sha256=yt9E7A_OEWQBQabf9bqt4Rc3S6oUXbSeM6NR1nYidtg,11642
65
65
  wbfdm/contrib/metric/backends/statistics.py,sha256=6DWMsFAZUaTA2v0VTBudx2QiX0E4umMEoyyqS3ZM3e4,6695
66
+ wbfdm/contrib/metric/backends/utils.py,sha256=xpsDmoL2Jv9-KTuo-ay65D4m9Kf35jGc9cbeejhFLQU,131
66
67
  wbfdm/contrib/metric/migrations/0001_initial.py,sha256=EwXRJrG7zQYT1bD6jjaf1gZNfpd8f2gzta09GYqukiM,3403
67
68
  wbfdm/contrib/metric/migrations/0002_remove_instrumentmetric_unique_instrument_metric_and_more.py,sha256=xp6MACDohMSs4YfFbprCLa5G7zEuBhfZgpVXyMsZPWI,808
68
69
  wbfdm/contrib/metric/migrations/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -73,7 +74,7 @@ wbfdm/contrib/metric/tests/test_models.py,sha256=xtJYIst2B55LnGJyWggA2C2S04psGLh
73
74
  wbfdm/contrib/metric/tests/test_tasks.py,sha256=Jqr8utdFiHDvzvZPywkPHgqMxI-ukEfYlRinK2F336U,628
74
75
  wbfdm/contrib/metric/tests/test_viewsets.py,sha256=KE75dlOVhnw59hvWV5C0ktGh9Pxuc_3txeCi0J9t-d4,3156
75
76
  wbfdm/contrib/metric/tests/backends/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
76
- wbfdm/contrib/metric/tests/backends/test_performances.py,sha256=npCWw_iRDgUnfaenRyxcfvCS9dXTo7ec2GFmBS0B5bQ,7560
77
+ wbfdm/contrib/metric/tests/backends/test_performances.py,sha256=SvZerb0y2ifpr2gLKWgXIiV6Shqne6di0ONeC7lFoRs,7896
77
78
  wbfdm/contrib/metric/tests/backends/test_statistics.py,sha256=jtQOslHiCdZcfSJy9NU-xhoz1_BUx6FrdmhPZpJU03I,1921
78
79
  wbfdm/contrib/metric/viewsets/__init__.py,sha256=LTOyOBlhagANq164m7f0oJuz8qCkuq2R8-3lwEZejGs,85
79
80
  wbfdm/contrib/metric/viewsets/mixins.py,sha256=Z8RJ4QUVjYIki9FdGySXoE29v2wcVTSAdXn1WKzLJ9c,11074
@@ -351,6 +352,6 @@ wbfdm/viewsets/statements/__init__.py,sha256=odxtFYUDICPmz8WCE3nx93EvKZLSPBEI4d7
351
352
  wbfdm/viewsets/statements/statements.py,sha256=kmtM0uZ3f7eJJe5gVmd-iVra9dHwTB9x12p7f5qTEx8,4084
352
353
  wbfdm/viewsets/technical_analysis/__init__.py,sha256=qtCIBg0uSiZeJq_1tEQFilnorMBkMe6uCMfqar6-cLE,77
353
354
  wbfdm/viewsets/technical_analysis/monthly_performances.py,sha256=O1j8CGfOranL74LqVvcf7jERaDIboEJZiBf_AbbVDQ8,3974
354
- wbfdm-1.46.11.dist-info/METADATA,sha256=APQKFb1E4ZdhaxdSeTIdrizO5INV05Su8CRUTH7zBcM,738
355
- wbfdm-1.46.11.dist-info/WHEEL,sha256=tkmg4JIqwd9H8mL30xA7crRmoStyCtGp0VWshokd1Jc,105
356
- wbfdm-1.46.11.dist-info/RECORD,,
355
+ wbfdm-1.46.13.dist-info/METADATA,sha256=MEHS76Tos0J-qwMLxwwUS3ih5p2u0xVEykz7PJ8LGfE,738
356
+ wbfdm-1.46.13.dist-info/WHEEL,sha256=tkmg4JIqwd9H8mL30xA7crRmoStyCtGp0VWshokd1Jc,105
357
+ wbfdm-1.46.13.dist-info/RECORD,,