lambda-risk 0.0.0.4__tar.gz → 0.0.0.5__tar.gz
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.
- {lambda_risk-0.0.0.4 → lambda_risk-0.0.0.5}/PKG-INFO +1 -1
- {lambda_risk-0.0.0.4 → lambda_risk-0.0.0.5}/lambda_risk/client.py +69 -5
- lambda_risk-0.0.0.5/lambda_risk/risk.py +43 -0
- {lambda_risk-0.0.0.4 → lambda_risk-0.0.0.5}/lambda_risk.egg-info/PKG-INFO +1 -1
- {lambda_risk-0.0.0.4 → lambda_risk-0.0.0.5}/lambda_risk.egg-info/SOURCES.txt +1 -0
- {lambda_risk-0.0.0.4 → lambda_risk-0.0.0.5}/setup.py +1 -1
- {lambda_risk-0.0.0.4 → lambda_risk-0.0.0.5}/README.md +0 -0
- {lambda_risk-0.0.0.4 → lambda_risk-0.0.0.5}/lambda_risk/__init__.py +0 -0
- {lambda_risk-0.0.0.4 → lambda_risk-0.0.0.5}/lambda_risk.egg-info/dependency_links.txt +0 -0
- {lambda_risk-0.0.0.4 → lambda_risk-0.0.0.5}/lambda_risk.egg-info/requires.txt +0 -0
- {lambda_risk-0.0.0.4 → lambda_risk-0.0.0.5}/lambda_risk.egg-info/top_level.txt +0 -0
- {lambda_risk-0.0.0.4 → lambda_risk-0.0.0.5}/setup.cfg +0 -0
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
|
+
import mimetypes
|
|
3
4
|
import os
|
|
4
5
|
import tempfile
|
|
5
6
|
import time
|
|
@@ -12,8 +13,8 @@ import requests
|
|
|
12
13
|
|
|
13
14
|
@dataclass
|
|
14
15
|
class Config:
|
|
15
|
-
base_url: str
|
|
16
|
-
token: str
|
|
16
|
+
base_url: str = os.getenv("LAMBDA_API_URL")
|
|
17
|
+
token: str = os.getenv("LAMBDA_API_TOKEN")
|
|
17
18
|
timeout: int = 120
|
|
18
19
|
poll_seconds: int = 3
|
|
19
20
|
max_polls: int = 120
|
|
@@ -354,9 +355,9 @@ class FrameworkRiesgo(Config):
|
|
|
354
355
|
|
|
355
356
|
|
|
356
357
|
class StorageFiles(Config):
|
|
357
|
-
def get_file_url(self, bucket: str, path: str, log: bool = False) -> dict[str, Any]:
|
|
358
|
+
def get_file_url(self, bucket: str, path: str, *, admin_password: str, log: bool = False) -> dict[str, Any]:
|
|
358
359
|
started_at = time.perf_counter()
|
|
359
|
-
data = self._post("files/signed-url", {"bucket": bucket, "path": path})
|
|
360
|
+
data = self._post("files/signed-url", {"bucket": bucket, "path": path, "admin_password": admin_password})
|
|
360
361
|
elapsed = self._format_elapsed(time.perf_counter() - started_at)
|
|
361
362
|
self._print(
|
|
362
363
|
f"file_signed_url={elapsed} | bucket={bucket} | path={path} | size_bytes={data['size_bytes']}",
|
|
@@ -364,14 +365,40 @@ class StorageFiles(Config):
|
|
|
364
365
|
)
|
|
365
366
|
return data
|
|
366
367
|
|
|
368
|
+
def get_upload_url(
|
|
369
|
+
self,
|
|
370
|
+
bucket: str,
|
|
371
|
+
path: str,
|
|
372
|
+
*,
|
|
373
|
+
admin_password: str,
|
|
374
|
+
content_type: Optional[str] = None,
|
|
375
|
+
log: bool = False,
|
|
376
|
+
) -> dict[str, Any]:
|
|
377
|
+
started_at = time.perf_counter()
|
|
378
|
+
payload = {
|
|
379
|
+
"bucket": bucket,
|
|
380
|
+
"path": path,
|
|
381
|
+
"admin_password": admin_password,
|
|
382
|
+
"content_type": content_type or "application/octet-stream",
|
|
383
|
+
}
|
|
384
|
+
data = self._post("files/upload-url", payload)
|
|
385
|
+
elapsed = self._format_elapsed(time.perf_counter() - started_at)
|
|
386
|
+
self._print(
|
|
387
|
+
f"file_upload_url={elapsed} | bucket={bucket} | path={path} | content_type={data['content_type']}",
|
|
388
|
+
log,
|
|
389
|
+
)
|
|
390
|
+
return data
|
|
391
|
+
|
|
367
392
|
def download_file(
|
|
368
393
|
self,
|
|
369
394
|
bucket: str,
|
|
370
395
|
path: str,
|
|
396
|
+
*,
|
|
397
|
+
admin_password: str,
|
|
371
398
|
destination: str | os.PathLike = ".",
|
|
372
399
|
log: bool = False,
|
|
373
400
|
) -> Path:
|
|
374
|
-
file_info = self.get_file_url(bucket, path, log=log)
|
|
401
|
+
file_info = self.get_file_url(bucket, path, admin_password=admin_password, log=log)
|
|
375
402
|
destination_path = Path(destination)
|
|
376
403
|
if destination_path.suffix:
|
|
377
404
|
output_path = destination_path
|
|
@@ -394,3 +421,40 @@ class StorageFiles(Config):
|
|
|
394
421
|
log,
|
|
395
422
|
)
|
|
396
423
|
return output_path
|
|
424
|
+
|
|
425
|
+
def upload_file(
|
|
426
|
+
self,
|
|
427
|
+
source: str | os.PathLike,
|
|
428
|
+
bucket: str,
|
|
429
|
+
path: str,
|
|
430
|
+
*,
|
|
431
|
+
admin_password: str,
|
|
432
|
+
content_type: Optional[str] = None,
|
|
433
|
+
log: bool = False,
|
|
434
|
+
) -> dict[str, Any]:
|
|
435
|
+
source_path = Path(source)
|
|
436
|
+
detected_content_type = content_type or mimetypes.guess_type(source_path.name)[0] or "application/octet-stream"
|
|
437
|
+
file_info = self.get_upload_url(
|
|
438
|
+
bucket,
|
|
439
|
+
path,
|
|
440
|
+
admin_password=admin_password,
|
|
441
|
+
content_type=detected_content_type,
|
|
442
|
+
log=log,
|
|
443
|
+
)
|
|
444
|
+
|
|
445
|
+
started_at = time.perf_counter()
|
|
446
|
+
with source_path.open("rb") as file_obj:
|
|
447
|
+
response = requests.put(
|
|
448
|
+
file_info["signed_url"],
|
|
449
|
+
data=file_obj,
|
|
450
|
+
headers=file_info["headers"],
|
|
451
|
+
timeout=600,
|
|
452
|
+
)
|
|
453
|
+
response.raise_for_status()
|
|
454
|
+
|
|
455
|
+
elapsed = self._format_elapsed(time.perf_counter() - started_at)
|
|
456
|
+
self._print(
|
|
457
|
+
f"file_upload={elapsed} | gs_uri={file_info['gs_uri']} | mb={source_path.stat().st_size / (1024 * 1024):.2f}",
|
|
458
|
+
log,
|
|
459
|
+
)
|
|
460
|
+
return file_info
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import pandas as pd
|
|
2
|
+
import numpy as np
|
|
3
|
+
from scipy.stats import norm
|
|
4
|
+
from datetime import datetime, timedelta
|
|
5
|
+
from dataclasses import dataclass, field
|
|
6
|
+
from typing import List, Dict, Optional
|
|
7
|
+
from .client import Datamart, FrameworkRiesgo
|
|
8
|
+
|
|
9
|
+
@dataclass
|
|
10
|
+
class ExpostRisk:
|
|
11
|
+
|
|
12
|
+
def ewma_varianza(self,returns:pd.DataFrame,factor:float) -> float:
|
|
13
|
+
pass
|
|
14
|
+
|
|
15
|
+
def decay_varianza(self,returns:pd.DataFrame,factor:float) -> float:
|
|
16
|
+
pass
|
|
17
|
+
|
|
18
|
+
def volatilidad(self,returns:pd.DataFrame,ewma:bool=False, decay:bool=False) -> float:
|
|
19
|
+
pass
|
|
20
|
+
|
|
21
|
+
def value_at_risk(self, confidence_level:float, sigma:float, mu:float=0.0) -> float:
|
|
22
|
+
pass
|
|
23
|
+
|
|
24
|
+
def tracking_error(self, ret_target:pd.DataFrame, ret_bmk:pd.DataFrame, ewma:bool=False, decay:bool=False) -> float:
|
|
25
|
+
pass
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
@dataclass
|
|
29
|
+
class Retornos:
|
|
30
|
+
data : pd.DataFrame
|
|
31
|
+
agf_target : str
|
|
32
|
+
year : str
|
|
33
|
+
bmk_categ : str
|
|
34
|
+
dtd : bool = False
|
|
35
|
+
wtw : bool = False
|
|
36
|
+
rolling_window : Optional[dict] = None
|
|
37
|
+
drop_weekends : bool = True
|
|
38
|
+
len_data : str = '1Y'
|
|
39
|
+
result : Dict[str, pd.DataFrame] = None
|
|
40
|
+
|
|
41
|
+
def runs_target(self):
|
|
42
|
+
...
|
|
43
|
+
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|