-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_assets_allocator.py
47 lines (29 loc) · 1.44 KB
/
test_assets_allocator.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
import pytest
import numpy as np
import numpy.testing as npt
from assets_allocator import generatePortfolio, probabilityOfGoal, allocateGoals
import pandas as pd
class TestAssetsAllocator:
def test_should_return_initial_value_for_zero_returns(self):
returns = [0,0,0,0,0,0,0,0,0,0]
assert generatePortfolio(returns,10000,0) == 10000
def test_should_return_calculated_value_for_initial_value(self):
returns = [0.07,0.07,0.07,0.07,0.07,0.07,0.07,0.07,0.07,0.07]
assert generatePortfolio(returns,10000,0) == 19671.51
def test_should_return_calculated_value_with_payments(self):
returns = [0.07,0.07,0.07,0.07,0.07,0.07,0.07,0.07,0.07,0.07]
assert generatePortfolio(returns,10000,1500) == 41846.91
def test_shoult_return_propability_of_goal_value(self):
values = np.array([10, 5, 11, 22, 8])
assert probabilityOfGoal(10,values) == 0.6
def test_should_allocate_goals():
initialAllocation = [0.3,0.5,0.6]
initialValue = 0
payments = 10000
paymentsGrowth = 0
initialAllocation = np.array([0.4,0.6])
goals = {'Nazwa': ["Dom", 'Emerytura'], 'Czas_trwania': [5,5], 'ExpectedValue': [120000, 400000]}
goalsdf = pd.DataFrame(goals)
cashFlows = allocateGoals(goalsdf,initialAllocation, initialValue, payments)
print(goalsdf['Czas_trwania'][0])
npt.assert_array_equal(cashFlows, np.array([[4000,4000,4000,4000,4000],[6000,6000,6000,6000,6000]]))