Repository navigation
Expand file tree
/
Copy pathdefault.py
More file actions
785 lines (742 loc) · 23.1 KB
/
Copy pathdefault.py
File metadata and controls
785 lines (742 loc) · 23.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
# SPDX-License-Identifier: LicenseRef-Rateslib-Dual
#
# Copyright (c) 2026 Siffrorna Technology Limited
#
# Dual-licensed: Free Educational Licence or Paid Commercial Licence (commercial/professional use)
# Source-available, not open source.
#
# See LICENSE and https://rateslib.com/py/en/latest/i_licence.html for details,
# and/or contact info (at) rateslib (dot) com
####################################################################################################
from __future__ import annotations
from copy import deepcopy
from datetime import datetime
from typing import TYPE_CHECKING
import matplotlib.dates as mdates
import matplotlib.pyplot as plt
import numpy as np
from rateslib._spec_loader import INSTRUMENT_SPECS
from rateslib.enums.generics import NoInput, _drb
from rateslib.rs import Adjuster, Convention, Frequency, NamedCal
PlotOutput = tuple[plt.Figure, plt.Axes, list[plt.Line2D]] # type: ignore[name-defined]
# Licence: Creative Commons - Attribution-NonCommercial-NoDerivatives 4.0 International
# Commercial use of this code, and/or copying and redistribution is prohibited.
# Contact rateslib at gmail.com if this code is observed outside its intended sphere.
if TYPE_CHECKING:
from rateslib.local_types import ( # pragma: no cover
Any,
CalTypes,
)
DEFAULTS = dict(
stub="SHORTFRONT",
stub_length="SHORT",
eval_mode="swaps_align",
modifier="MF",
eom=False,
eom_fx=True,
# Instrument parameterisation
metric={
"SBS": "leg1",
},
convention="ACT360",
notional=1.0e6,
index_lag=3,
index_lag_curve=0,
index_method="daily",
payment_lag=2,
payment_lag_exchange=0,
payment_lag_specific={
"Fee": 0,
"Loan": 0,
"IRS": 2,
"STIRFuture": 0,
"IIRS": 2,
"YoYIS": 2,
"ZCS": 2,
"ZCIS": 0,
"FXSwap": 0,
"SBS": 2,
"Swap": 2,
"XCS": 2,
"NDXCS": 2,
"FixedRateBond": 0,
"IndexFixedRateBond": 0,
"FloatRateNote": 0,
"Bill": 0,
"FRA": 0,
"CDS": 0,
"NDF": 2,
},
fixing_method="rfr_payment_delay",
spread_compound_method="none_simple",
index_base_type="initial",
base_currency="usd",
fx_delivery_lag=2,
fx_delta_type="spot",
fx_option_metric="pips",
ir_option_metric="black_vol_shift_0",
ir_option_settlement="physical",
cds_premium_accrued=True,
cds_recovery_rate=0.40,
cds_protection_discretization=23,
# Curves
interpolation={
"dfs": "log_linear",
"values": "linear",
},
endpoints="natural",
multi_csa_steps=[
2,
5,
10,
20,
30,
50,
77,
81,
86,
91,
96,
103,
110,
119,
128,
140,
153,
169,
188,
212,
242,
281,
332,
401,
498,
636,
835,
1104,
1407,
1646,
1766,
1808,
1821,
1824,
1825,
],
multi_csa_min_step=1,
multi_csa_max_step=1825,
curve_caching=True,
curve_caching_max=1000,
# Solver
tag="v",
algorithm="levenberg_marquardt",
curve_not_in_solver="ignore", # or "warn" or "raise"
ini_lambda=(1000.0, 0.25, 2.0),
# bonds
calc_mode={
"FixedRateBond": "uk_gb",
"FloatRateNote": "uk_gb",
"Bill": "us_gbb",
"IndexFixedRateBond": "uk_gb",
},
settle=1,
ex_div=1,
calc_mode_futures="ytm",
# misc
pool=1,
no_fx_fixings_for_xcs="warn", # or "raise" or "ignore"
headers={
"type": "Type",
"stub_type": "Period",
"u_acc_start": "Unadj Acc Start",
"u_acc_end": "Unadj Acc End",
"a_acc_start": "Acc Start",
"a_acc_end": "Acc End",
"payment": "Payment",
"convention": "Convention",
"dcf": "DCF",
"df": "DF",
"notional": "Notional",
"reference_currency": "Reference Ccy",
"currency": "Ccy",
"fx_fixing": "FX Fixing",
"fx_fixing_date": "FX Fix Date",
"rate": "Rate",
"spread": "Spread",
"npv": "NPV",
"cashflow": "Cashflow",
"fx": "FX Rate",
"npv_fx": "NPV Ccy",
"base": "Base Ccy",
"unindexed_cashflow": "Unindexed Cashflow",
"index_fix_date": "Index Fix Date",
"index_value": "Index Val",
"index_ratio": "Index Ratio",
"index_base": "Index Base",
"collateral": "Collateral",
# Options headers
"pair": "Pair",
"expiry": "Expiry",
"t_e": "Time to Expiry",
"delivery": "Delivery",
"model": "Model",
"vol": "Vol",
"strike": "Strike",
# CDS headers
"survival": "Survival",
"recovery": "Recovery",
},
_global_ad_order=1,
oaspread_func_tol=1e-6,
oaspread_conv_tol=1e-8,
# Licence: Creative Commons - Attribution-NonCommercial-NoDerivatives 4.0 International
# Commercial use of this code, and/or copying and redistribution is prohibited.
# Contact rateslib at gmail.com if this code is observed outside its intended sphere.
spec=INSTRUMENT_SPECS,
fx_index={
# ISDA values determined from the ISDA MTM Matrix documentation
"eurusd": dict(
pair="eurusd",
calendar=NamedCal("tgt|fed"),
settle=Adjuster.BusDaysLagSettle(2),
isda_mtm_calendar=NamedCal("ldn"),
isda_mtm_settle=Adjuster.BusDaysLagSettle(-2),
allow_cross=False,
),
"eurgbp": dict(
pair="eurgbp",
calendar=NamedCal("ldn,tgt|fed"),
settle=Adjuster.BusDaysLagSettle(2),
isda_mtm_calendar=NamedCal("ldn"),
isda_mtm_settle=Adjuster.BusDaysLagSettle(-2),
allow_cross=True,
),
"eursek": dict(
pair="eursek",
calendar=NamedCal("tgt,stk|fed"),
settle=Adjuster.BusDaysLagSettle(2),
isda_mtm_calendar=NamedCal("tgt,stk"),
isda_mtm_settle=Adjuster.BusDaysLagSettle(-2),
allow_cross=False,
),
"gbpusd": dict(
pair="gbpusd",
calendar=NamedCal("ldn|fed"),
settle=Adjuster.BusDaysLagSettle(2),
isda_mtm_calendar=NamedCal("ldn"),
isda_mtm_settle=Adjuster.BusDaysLagSettle(-2),
allow_cross=False,
),
"usdcad": dict(
pair="usdcad",
calendar=NamedCal("tro|fed"),
settle=Adjuster.BusDaysLagSettle(1),
isda_mtm_calendar=NamedCal("tro,nyc,ldn"),
isda_mtm_settle=Adjuster.BusDaysLagSettle(-2),
allow_cross=False,
),
"gbpcad": dict(
pair="gbpcad",
calendar=NamedCal("tro,ldn|fed"),
settle=Adjuster.BusDaysLagSettle(2),
isda_mtm_calendar=NamedCal("tro,nyc,ldn"),
isda_mtm_settle=Adjuster.BusDaysLagSettle(-2),
allow_cross=True,
),
"usdnok": dict(
pair="usdnok",
calendar=NamedCal("osl|fed"),
settle=Adjuster.BusDaysLagSettle(2),
isda_mtm_calendar=NamedCal("osl"),
isda_mtm_settle=Adjuster.BusDaysLagSettle(-2),
allow_cross=True,
),
"usdsek": dict(
pair="usdsek",
calendar=NamedCal("stk|fed"),
settle=Adjuster.BusDaysLagSettle(2),
isda_mtm_calendar=NamedCal("stk"),
isda_mtm_settle=Adjuster.BusDaysLagSettle(-2),
allow_cross=True,
),
"chfsek": dict(
pair="chfsek",
calendar=NamedCal("stk,zur|fed"),
settle=Adjuster.BusDaysLagSettle(2),
isda_mtm_calendar=NamedCal("stk,zur,ldn"),
isda_mtm_settle=Adjuster.BusDaysLagSettle(-2),
allow_cross=True,
),
"usdchf": dict(
pair="usdchf",
calendar=NamedCal("zur|fed"),
settle=Adjuster.BusDaysLagSettle(2),
isda_mtm_calendar=NamedCal("ldn"),
isda_mtm_settle=Adjuster.BusDaysLagSettle(-2),
allow_cross=True,
),
"seknok": dict(
pair="seknok",
calendar=NamedCal("stk,osl|fed"),
settle=Adjuster.BusDaysLagSettle(2),
isda_mtm_calendar=NamedCal("stk,osl"),
isda_mtm_settle=Adjuster.BusDaysLagSettle(-2),
allow_cross=True,
),
"audusd": dict(
pair="audusd",
calendar=NamedCal("syd|fed"),
settle=Adjuster.BusDaysLagSettle(2),
isda_mtm_calendar=NamedCal("syd,nyc,ldn"),
isda_mtm_settle=Adjuster.BusDaysLagSettle(-2),
allow_cross=False,
),
"usdjpy": dict(
pair="usdjpy",
calendar=NamedCal("tyo|fed"),
settle=Adjuster.BusDaysLagSettle(2),
isda_mtm_calendar=NamedCal("tyo,nyc,ldn"),
isda_mtm_settle=Adjuster.BusDaysLagSettle(-2),
allow_cross=False,
),
"nzdusd": dict(
pair="nzdusd",
calendar=NamedCal("wlg|fed"),
settle=Adjuster.BusDaysLagSettle(2),
isda_mtm_calendar=NamedCal("wlg,nyc,ldn"),
isda_mtm_settle=Adjuster.BusDaysLagSettle(-2),
allow_cross=True,
),
# The following are not defined in the ISDA MTM Matrix
"audnzd": dict(
pair="audnzd",
calendar=NamedCal("wlg,syd|fed"),
settle=Adjuster.BusDaysLagSettle(2),
isda_mtm_calendar=NamedCal("wlg,syd,ldn,nyc"),
isda_mtm_settle=Adjuster.BusDaysLagSettle(-2),
allow_cross=True,
),
"usdinr": dict(
pair="usdinr",
calendar=NamedCal("mum|fed"),
settle=Adjuster.BusDaysLagSettle(2),
isda_mtm_calendar=NamedCal("mum"),
isda_mtm_settle=Adjuster.BusDaysLagSettle(-2),
allow_cross=False,
),
},
irs_series={
"eur_irs6": dict(
currency="eur",
settle=Adjuster.BusDaysLagSettle(2),
calendar="tgt",
modifier=Adjuster.ModifiedFollowing(),
convention=Convention.ThirtyE360,
leg2_convention=Convention.Act360,
frequency=Frequency.Months(12, None),
leg2_frequency=Frequency.Months(6, None),
leg2_fixing_method="ibor(2)",
eom=False,
payment_lag=Adjuster.BusDaysLagSettle(0),
),
"eur_irs3": dict(
currency="eur",
settle=Adjuster.BusDaysLagSettle(2),
calendar="tgt",
modifier=Adjuster.ModifiedFollowing(),
convention=Convention.ThirtyE360,
leg2_convention=Convention.Act360,
frequency=Frequency.Months(12, None),
leg2_frequency=Frequency.Months(3, None),
leg2_fixing_method="ibor(2)",
eom=False,
payment_lag=Adjuster.BusDaysLagSettle(0),
),
"usd_irs": dict(
currency="usd",
settle=Adjuster.BusDaysLagSettle(2),
calendar="nyc",
modifier=Adjuster.ModifiedFollowing(),
convention=Convention.Act360,
frequency=Frequency.Months(12, None),
leg2_fixing_method="rfr_payment_delay",
eom=False,
payment_lag=Adjuster.BusDaysLagSettle(2),
),
},
float_series={
"usd_ibor": dict(
lag=2,
calendar=NamedCal("nyc"),
modifier=Adjuster.ModifiedFollowing(),
convention=Convention.Act360,
eom=False,
tenors=["1B", "1W", "1M", "2M", "3M", "6M", "12M"],
),
"usd_rfr": dict(
lag=0,
calendar=NamedCal("nyc"),
modifier=Adjuster.Following(),
convention=Convention.Act360,
eom=False,
tenors=["1b"],
),
"gbp_ibor": dict(
lag=0,
calendar=NamedCal("ldn"),
modifier=Adjuster.ModifiedFollowing(),
convention=Convention.Act365F,
eom=True,
tenors=["1B", "1W", "1M", "2M", "3M", "6M", "12M"],
),
"gbp_rfr": dict(
lag=0,
calendar=NamedCal("ldn"),
modifier=Adjuster.Following(),
convention=Convention.Act365F,
eom=False,
tenors=["1b"],
),
"sek_ibor": dict(
lag=2,
calendar=NamedCal("ldn"),
modifier=Adjuster.ModifiedFollowing(),
convention=Convention.Act360,
eom=True,
tenors=["2B", "1W", "1M", "2M", "3M", "6M"],
),
"sek_rfr": dict(
lag=0,
calendar=NamedCal("ldn"),
modifier=Adjuster.Following(),
convention=Convention.Act360,
eom=False,
tenors=["1b"],
),
"eur_ibor": dict(
lag=2,
calendar=NamedCal("tgt"),
modifier=Adjuster.ModifiedFollowing(),
convention=Convention.Act360,
eom=False,
tenors=["1W", "1M", "3M", "6M", "12M"],
),
"eur_rfr": dict(
lag=0,
calendar=NamedCal("tgt"),
modifier=Adjuster.Following(),
convention=Convention.Act360,
eom=False,
tenors=["1b"],
),
"nok_ibor": dict(
lag=2,
calendar=NamedCal("osl"),
modifier=Adjuster.ModifiedFollowing(),
convention=Convention.Act360,
eom=False,
tenors=["1W", "1M", "2M", "3M", "6M"],
),
"nok_rfr": dict(
lag=0,
calendar=NamedCal("osl"),
modifier=Adjuster.Following(),
convention=Convention.Act365F,
eom=False,
tenors=["1b"],
),
"chf_ibor": dict(
lag=2,
calendar=NamedCal("zur"),
modifier=Adjuster.ModifiedFollowing(),
convention=Convention.Act360,
eom=False,
tenors=["1B", "1W", "1M", "2M", "3M", "6M", "12M"],
),
"chf_rfr": dict(
lag=0,
calendar=NamedCal("zur"),
modifier=Adjuster.Following(),
convention=Convention.Act360,
eom=False,
tenors=["1b"],
),
"cad_ibor": dict(
lag=2,
calendar=NamedCal("tro"),
modifier=Adjuster.ModifiedFollowing(),
convention=Convention.Act365F,
eom=False,
tenors=["1M", "2M", "3M", "6M", "12M"],
),
"cad_rfr": dict(
lag=0,
calendar=NamedCal("tro"),
modifier=Adjuster.Following(),
convention=Convention.Act365F,
eom=False,
tenors=["1b"],
),
"jpy_ibor": dict(
lag=2,
calendar=NamedCal("tyo"),
modifier=Adjuster.ModifiedFollowing(),
convention=Convention.Act365F,
eom=False,
tenors=["1M", "3M", "6M"],
),
"jpy_rfr": dict(
lag=0,
calendar=NamedCal("tyo"),
modifier=Adjuster.Following(),
convention=Convention.Act365F,
eom=False,
tenors=["1b"],
),
"aud_ibor": dict(
lag=0,
calendar=NamedCal("syd"),
modifier=Adjuster.ModifiedFollowing(),
convention=Convention.Act365F,
eom=True,
tenors=["1M", "2M", "3M", "4M", "5M", "6M"],
),
"aud_rfr": dict(
lag=0,
calendar=NamedCal("syd"),
modifier=Adjuster.Following(),
convention=Convention.Act365F,
eom=False,
tenors=["1b"],
),
"nzd_ibor": dict(
lag=0,
calendar=NamedCal("wlg"),
modifier=Adjuster.ModifiedFollowing(),
convention=Convention.Act365F,
eom=True,
tenors=["1M", "3M", "6M"],
),
"nzd_rfr": dict(
lag=0,
calendar=NamedCal("wlg"),
modifier=Adjuster.Following(),
convention=Convention.Act365F,
eom=False,
tenors=["1b"],
),
},
)
class Defaults:
"""
The *defaults* object used by initialising objects. Values are printed below:
.. ipython:: python
from rateslib import defaults
print(defaults.print())
"""
_instance = None
stub: str
stub_length: str
eval_mode: str
modifier: str
calendars: dict[str, CalTypes]
eom: bool
eom_fx: bool
metric: dict[str, str]
convention: str
notional: float
index_lag: int
index_lag_curve: int
index_method: str
payment_lag: int
payment_lag_exchange: int
payment_lag_specific: dict[str, int]
fixing_method: str
spread_compound_method: str
index_base_type: str
base_currency: str
fx_delivery_lag: int
fx_delta_type: str
fx_option_metric: str
ir_option_metric: str
ir_option_settlement: str
cds_premium_accrued: bool
cds_recovery_rate: float
cds_protection_discretization: int
interpolation: dict[str, str]
endpoints: str
multi_csa_steps: list[int]
multi_csa_min_step: int
multi_csa_max_step: int
curve_caching: bool
curve_caching_max: int
tag: str
algorithm: str
curve_not_in_solver: str
ini_lambda: tuple[int, float, float]
calc_mode: dict[str, str]
settle: int
ex_div: int
calc_mode_futures: str
pool: int
no_fx_fixings_for_xcs: str
headers: dict[str, str]
_global_ad_order: int
oaspread_func_tol: float
oaspread_conv_tol: float
# Licence: Creative Commons - Attribution-NonCommercial-NoDerivatives 4.0 International
# Commercial use of this code, and/or copying and redistribution is prohibited.
# Contact rateslib at gmail.com if this code is observed outside its intended sphere.
spec: dict[str, dict[str, Any]]
fx_index: dict[str, Any]
irs_series: dict[str, Any]
float_series: dict[str, Any]
def __new__(cls) -> Defaults:
if cls._instance is None:
# Singleton pattern creates only one instance: TODO (low) might not be thread safe
cls._instance = super(Defaults, cls).__new__(cls) # noqa: UP008
for k, v in DEFAULTS.items():
setattr(cls._instance, k, deepcopy(v))
return cls._instance
def reset_defaults(self) -> None:
"""
Revert defaults back to their initialisation status.
Examples
--------
.. ipython:: python
from rateslib import defaults
defaults.reset_defaults()
"""
attrs = [
v
for v in dir(self)
if "__" not in v and not callable(getattr(self, v)) and v != "_instance"
]
for attr in attrs:
delattr(self, attr)
for k, v in DEFAULTS.items():
setattr(self, k, deepcopy(v))
def print(self) -> str:
"""
Return a string representation of the current values in the defaults object.
"""
def _t_n(v: str) -> str: # teb-newline
return f"\t{v}\n"
_: str = f"""\
Scheduling:\n
{
"".join(
[
_t_n(f"{attribute}: {getattr(self, attribute)}")
for attribute in [
"stub",
"stub_length",
"modifier",
"eom",
"eom_fx",
"eval_mode",
]
]
)
}
Instruments:\n
{
"".join(
[
_t_n(f"{attribute}: {getattr(self, attribute)}")
for attribute in [
"convention",
"payment_lag",
"payment_lag_exchange",
"payment_lag_specific",
"notional",
"fixing_method",
"spread_compound_method",
"base_currency",
"fx_delivery_lag",
"fx_delta_type",
"fx_option_metric",
"cds_premium_accrued",
"cds_recovery_rate",
"cds_protection_discretization",
]
]
)
}
Curves:\n
{
"".join(
[
_t_n(f"{attribute}: {getattr(self, attribute)}")
for attribute in [
"interpolation",
"endpoints",
"multi_csa_steps",
"curve_caching",
]
]
)
}
Solver:\n
{
"".join(
[
_t_n(f"{attribute}: {getattr(self, attribute)}")
for attribute in [
"algorithm",
"tag",
"curve_not_in_solver",
]
]
)
}
Miscellaneous:\n
{
"".join(
[
_t_n(f"{attribute}: {getattr(self, attribute)}")
for attribute in [
"headers",
"no_fx_fixings_for_xcs",
"pool",
]
]
)
}
""" # noqa: W291
return _
def plot(
x: list[list[Any]], y: list[list[Any]], labels: list[str] | NoInput = NoInput(0)
) -> PlotOutput:
labels = _drb([], labels)
fig, ax = plt.subplots(1, 1)
lines = []
for _x, _y in zip(x, y, strict=True):
(line,) = ax.plot(_x, _y)
lines.append(line)
if not isinstance(labels, NoInput) and len(labels) == len(lines):
ax.legend(lines, labels)
ax.grid(True)
if isinstance(x[0][0], datetime):
years = mdates.YearLocator() # type: ignore[no-untyped-call]
months = mdates.MonthLocator() # type: ignore[no-untyped-call]
yearsFmt = mdates.DateFormatter("%Y") # type: ignore[no-untyped-call]
ax.xaxis.set_major_locator(years)
ax.xaxis.set_major_formatter(yearsFmt)
ax.xaxis.set_minor_locator(months)
fig.autofmt_xdate()
return fig, ax, lines
def plot3d(
x: list[Any], y: list[Any], z: np.ndarray[tuple[int, int], np.dtype[np.float64]]
) -> tuple[plt.Figure, plt.Axes, None]: # type: ignore[name-defined]
import matplotlib.pyplot as plt
from matplotlib import cm
# import matplotlib.dates as mdates # type: ignore[import]
fig, ax = plt.subplots(subplot_kw={"projection": "3d"})
X, Y = np.meshgrid(x, y)
# Plot the surface.
ax.plot_surface(X, Y, z, cmap=cm.coolwarm, linewidth=0, antialiased=False) # type: ignore[attr-defined]
return fig, ax, None
def _make_py_json(json: str, class_name: str) -> str:
"""Modifies the output JSON output for Rust structs wrapped by Python classes."""
return '{"PyWrapped":' + json + "}"
__all__ = ["Defaults"]