PyQuantimClient 1.0.61__tar.gz → 1.0.63__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: PyQuantimClient
3
- Version: 1.0.61
3
+ Version: 1.0.63
4
4
  Summary: Python client to access quantIM services
5
5
  Author: Daniel Velasquez
6
6
  Author-email: daniel.velasquez@sura-im.com
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: PyQuantimClient
3
- Version: 1.0.61
3
+ Version: 1.0.63
4
4
  Summary: Python client to access quantIM services
5
5
  Author: Daniel Velasquez
6
6
  Author-email: daniel.velasquez@sura-im.com
@@ -7,6 +7,7 @@ PyQuantimClient.egg-info/top_level.txt
7
7
  src/__init__.py
8
8
  src/api.py
9
9
  src/benchmarks.py
10
+ src/bi.py
10
11
  src/data.py
11
12
  src/energy.py
12
13
  src/portfolios.py
@@ -4,7 +4,7 @@ setup(
4
4
  name='PyQuantimClient',
5
5
  packages=['PyQuantimClient'],
6
6
  package_dir={'PyQuantimClient': 'src'},
7
- version='1.0.61',
7
+ version='1.0.63',
8
8
  description='Python client to access quantIM services',
9
9
  author='Daniel Velasquez',
10
10
  author_email='daniel.velasquez@sura-im.com',
@@ -47,7 +47,12 @@ class quantim:
47
47
  else:
48
48
  print("Method not supported!")
49
49
  return None
50
- return json.loads(api_call_response.text)
50
+
51
+ try:
52
+ resp = json.loads(api_call_response.text)
53
+ except:
54
+ resp = api_call_response.text
55
+ return resp
51
56
 
52
57
  def retrieve_s3_df(self, bucket, key, sep=','):
53
58
  '''
@@ -0,0 +1,28 @@
1
+ # -*- coding: utf-8 -*-
2
+ import pandas as pd
3
+ import numpy as np
4
+ import datetime as dt
5
+ from dateutil.relativedelta import relativedelta as rd
6
+ from .api import quantim
7
+
8
+ class bi_data(quantim):
9
+ def __init__(self, username, password, secretpool, env="pdn", api_url=None):
10
+ super().__init__(username, password, secretpool, env, api_url)
11
+
12
+ def get_positions_afps_cl(self, ref_date=None, bucket="condor-sura"):
13
+ '''
14
+ Get Value at Risk results and suport information.
15
+ '''
16
+ ref_date = dt.datetime.today().replace(day=1, hour=0, minute=0, second=0, microsecond=0) - rd(days=1) if ref_date is None else dt.datetime.strptime(ref_date, '%Y-%m-%d')
17
+ key = f'{prefix}{ref_date.year}/{ref_date.strftime("%m")}/data.json'
18
+
19
+ data = {'bucket':bucket, 'key':key}
20
+ try:
21
+ resp = self.api_call('retrieve_json_s3', method="post", data=data, verify=False)
22
+ keys = list(resp.keys())
23
+ resp_dfs = {k:pd.DataFrame(resp[k]) for k in keys}
24
+ except:
25
+ print(f"Data not available for {ref_date}. Try previous month!")
26
+ keys, resp_dfs = None, None
27
+ return keys, resp_dfs
28
+
@@ -138,3 +138,36 @@ class risk_data(quantim):
138
138
  cfs = pd.read_csv(resp['cf_url']) if return_cfs else None
139
139
 
140
140
  return irl_report, cfs
141
+
142
+ def load_fund_series_cl(self, file_path, sep=";", encoding='utf-8', blocks=1):
143
+ '''
144
+ Load series Chile to s3.
145
+ '''
146
+ # Validate filename:
147
+ filename = file_path.split('/')[-1]
148
+ label = filename.split('.')[-2]
149
+ if filename.split('.')[-1]!='csv':
150
+ raise ValueError('Extension must be csv. Please check file.')
151
+ if not np.any(np.in1d(label, ['series_performance'])):
152
+ raise ValueError('You can only load series_performance.csv')
153
+
154
+ if get_csv_separator(file_path)!=sep:
155
+ raise ValueError(f'Separator must be ({sep}). Please check file.')
156
+
157
+ # Read new file:
158
+ try:
159
+ df_new = pd.read_csv(file_path, sep=sep, encoding=encoding)
160
+ except:
161
+ raise ValueError("Cannot read file. Check path and encoding.")
162
+
163
+ # Load data
164
+ li = int(np.ceil(len(df_new)/blocks))
165
+ for i in range(blocks):
166
+ payload = df_new.iloc[(i*li):(i+1)*li, :].to_dict(orient='records')
167
+ data = {'bucket':'condor-sura', 'file_name':f"inputs/benchmarks/performance/cl/{label}{i if i>0 else ''}.csv", 'payload':payload, 'sep':sep, 'overwrite':True, 'encoding':encoding}
168
+ try:
169
+ resp = self.api_call('load_data_s3', method="post", data=data, verify=False)
170
+ except:
171
+ resp = {'success':False, 'message':'Check permissions or file size!'}
172
+ return resp
173
+ return resp