-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstress.py
38 lines (28 loc) · 1.15 KB
/
stress.py
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
from copy import deepcopy
from operator import add
import re
__author__ = 'andriod'
def point_tweak(collection, curve, date, operation, amount):
path = [x for x in re.split("[\.[\]]", curve) if x]
collection = deepcopy(collection)
curr = collection
for element in path:
curr = curr[element]
curr[date] = operation(curr[date], amount)
return collection
def step_tweak(collection, curve, start_date, end_date, operation, amount):
path = [x for x in re.split("[\.[\]]", curve) if x]
collection = deepcopy(collection)
curr = collection
for element in path:
curr = curr[element]
curr[start_date:end_date] = curr[start_date:end_date].apply(operation, args=(amount,))
return collection
if __name__ == "__main__":
from data_access import get_dummy
dummyCollection = get_dummy("test")
baseVol = dummyCollection['fx']["usd_eur"]['High (est)']['2010-05-14']
tweakedCollection = point_tweak(dummyCollection, 'fx.usd_eur.High (est)', '2010-05-14', add, .001)
tweakedVol = tweakedCollection['fx']["usd_eur"]['High (est)']['2010-05-14']
print(baseVol, tweakedVol)
print(repr(tweakedCollection))