def test_it_returns_the_debt_to_equity_ratio_for_a_historical_time(self):
     asset = AccountBuilder().set_name("name") \
         .set_institution("institution") \
         .set_owner("owner") \
         .set_investment("investment") \
         .set_asset_class(AssetClass.NONE) \
         .set_account_type(AccountType.ASSET) \
         .build()
     liability = AccountBuilder().set_name("name") \
         .set_institution("institution") \
         .set_owner("owner") \
         .set_investment("investment") \
         .set_asset_class(AssetClass.NONE) \
         .set_account_type(AccountType.LIABILITY) \
         .build()
     timestamp = EpochDateConverter().date_to_epoch()
     early_timestamp = timestamp - 200000
     query_time = timestamp - 100000
     asset.import_snapshot(timestamp, 112233)
     liability.import_snapshot(early_timestamp, 223344)
     portfolio = Portfolio()
     portfolio.import_account(asset)
     portfolio.import_account(liability)
     self.assertEqual(
         PortfolioAnalyzer(portfolio).debt_to_equity(
             EpochDateConverter().epoch_to_date(query_time)), 1.0)
Exemplo n.º 2
0
 def test_it_returns_the_value_of_two_accounts(self):
     account_one = AccountBuilder().set_name("name")\
         .set_institution("institution")\
         .set_owner("Craig")\
         .set_investment("investment")\
         .build()
     account_two = AccountBuilder().set_name("name")\
         .set_institution("institution")\
         .set_owner("Samuel")\
         .set_investment("investment")\
         .set_liability()\
         .build()
     account_one.import_snapshot(
         EpochDateConverter().date_to_epoch("2009-10-15"), 10)
     account_two.import_snapshot(
         EpochDateConverter().date_to_epoch("2009-10-17"), 1000)
     self.portfolio.import_account(account_one)
     self.portfolio.import_account(account_two)
     line_graph = LineGraph(self.portfolio)
     net_worth_values = line_graph.net_worth_vs_time(
         "2009-10-13", "2009-10-19")
     self.assertEqual(net_worth_values[0], {
         "series": "net-worth",
         "date": "2009-10-13",
         "value": 0
     })
     self.assertEqual(net_worth_values[1], {
         "series": "net-worth",
         "date": "2009-10-14",
         "value": 0
     })
     self.assertEqual(net_worth_values[2], {
         "series": "net-worth",
         "date": "2009-10-15",
         "value": 10
     })
     self.assertEqual(net_worth_values[3], {
         "series": "net-worth",
         "date": "2009-10-16",
         "value": 10
     })
     self.assertEqual(net_worth_values[4], {
         "series": "net-worth",
         "date": "2009-10-17",
         "value": -990
     })
     self.assertEqual(net_worth_values[5], {
         "series": "net-worth",
         "date": "2009-10-18",
         "value": -990
     })
     self.assertEqual(net_worth_values[6], {
         "series": "net-worth",
         "date": "2009-10-19",
         "value": -990
     })
Exemplo n.º 3
0
 def setUp(self):
     self.asset = AccountBuilder().set_name("name") \
         .set_owner("owner") \
         .set_investment("investment") \
         .set_institution("institution") \
         .set_update_frequency(3) \
         .build()
     self.liability = AccountBuilder().set_name("name") \
         .set_owner("owner") \
         .set_investment("investment") \
         .set_institution("institution") \
         .set_liability() \
         .build()
     self.portfolio = Portfolio()
Exemplo n.º 4
0
 def test_it_does_not_return_duplicate_institutions(self):
     account_one = AccountBuilder().set_name("name one") \
         .set_institution("inst") \
         .set_owner("owner") \
         .set_investment("investment") \
         .build()
     account_two = AccountBuilder().set_name("name two") \
         .set_institution("inst") \
         .set_owner("owner") \
         .set_investment("investment") \
         .build()
     self.portfolio.import_account(account_one)
     self.portfolio.import_account(account_two)
     self.assertEqual(self.portfolio.institutions(), ["inst"])
Exemplo n.º 5
0
 def test_it_returns_two_institutions(self):
     account_one = AccountBuilder().set_name("name one") \
         .set_institution("institution 1") \
         .set_owner("owner") \
         .set_investment("investment") \
         .build()
     account_two = AccountBuilder().set_name("name two") \
         .set_institution("institution 2") \
         .set_owner("owner") \
         .set_investment("investment") \
         .build()
     self.portfolio.import_account(account_one)
     self.portfolio.import_account(account_two)
     self.assertTrue("institution 1" in self.portfolio.institutions())
     self.assertTrue("institution 2" in self.portfolio.institutions())
Exemplo n.º 6
0
 def test_it_returns_the_value_of_a_single_account(self):
     account = AccountBuilder().set_name("name")\
         .set_institution("institution")\
         .set_owner("Craig")\
         .set_investment("investment")\
         .build()
     account.import_snapshot(
         EpochDateConverter().date_to_epoch("2005-12-10"), 1000)
     self.portfolio.import_account(account)
     line_graph = LineGraph(self.portfolio)
     net_worth_values = line_graph.net_worth_vs_time(
         "2005-12-09", "2005-12-11")
     self.assertEqual(net_worth_values[0], {
         "series": "net-worth",
         "date": "2005-12-09",
         "value": 0
     })
     self.assertEqual(net_worth_values[1], {
         "series": "net-worth",
         "date": "2005-12-10",
         "value": 1000
     })
     self.assertEqual(net_worth_values[2], {
         "series": "net-worth",
         "date": "2005-12-11",
         "value": 1000
     })
Exemplo n.º 7
0
 def test_it_returns_one_institution(self):
     account = AccountBuilder().set_name("name one") \
         .set_institution("institution") \
         .set_owner("owner") \
         .set_investment("investment") \
         .build()
     self.portfolio.import_account(account)
     self.assertEqual(self.portfolio.institutions(), ["institution"])
Exemplo n.º 8
0
 def test_it_imports_a_second_account_in_the_portfolio(self):
     account_one = AccountBuilder().set_name("name") \
         .set_institution("institution") \
         .set_owner("owner") \
         .set_investment("investment") \
         .set_asset_class(AssetClass.NONE) \
         .set_account_type(AccountType.ASSET) \
         .build()
     account_two = AccountBuilder().set_name("name") \
         .set_institution("institution") \
         .set_owner("another owner") \
         .set_investment("investment") \
         .set_asset_class(AssetClass.NONE) \
         .set_account_type(AccountType.ASSET) \
         .build()
     self.portfolio.import_account(account_one)
     self.portfolio.import_account(account_two)
     self.assertEqual(self.portfolio.accounts, [account_one, account_two])
Exemplo n.º 9
0
 def test_it_imports_an_account(self):
     account = AccountBuilder().set_name("name") \
         .set_institution("institution") \
         .set_owner("owner") \
         .set_investment("investment") \
         .set_asset_class(AssetClass.NONE) \
         .set_account_type(AccountType.ASSET) \
         .build()
     self.portfolio.import_account(account)
     self.assertEqual(self.portfolio.accounts, [account])
Exemplo n.º 10
0
 def test_it_returns_two_assets(self):
     asset_one = AccountBuilder().set_name("name one") \
         .set_owner("owner one") \
         .set_investment("investment one") \
         .set_institution("institution one") \
         .set_update_frequency(5) \
         .build()
     asset_two = AccountBuilder().set_name("name two") \
         .set_owner("owner two") \
         .set_investment("investment two") \
         .set_institution("institution two") \
         .set_update_frequency(3) \
         .build()
     asset_one.import_snapshot(EpochDateConverter().date_to_epoch('2005-11-12'), 100.50)
     asset_two.import_snapshot(EpochDateConverter().date_to_epoch('2000-12-12'), 1289)
     self.portfolio.import_account(asset_one)
     self.portfolio.import_account(asset_two)
     balance_sheet = BalanceSheet(self.portfolio)
     expected_output = {"assets": [{"lastUpdated": "2005-11-12T12:00:00-05:00", "institution": "institution one", "owner": "owner one", "account": "name one", "value": 100.50, "investment": "investment one"}, {"lastUpdated": "2000-12-12T12:00:00-05:00", "institution": "institution two", "owner": "owner two", "account": "name two", "value": 1289, "investment": "investment two"}], "liabilities": []}
     self.assertEqual(balance_sheet.json(), expected_output)
 def test_it_returns_the_debt_to_equity_ratio_for_a_portfolio_with_only_liabilities(
         self):
     account = AccountBuilder().set_name("name") \
         .set_institution("institution") \
         .set_owner("owner") \
         .set_investment("investment") \
         .set_asset_class(AssetClass.NONE) \
         .set_account_type(AccountType.LIABILITY) \
         .build()
     account.import_snapshot(EpochDateConverter().date_to_epoch(), 1234)
     portfolio = Portfolio()
     portfolio.import_account(account)
     self.assertEqual(PortfolioAnalyzer(portfolio).debt_to_equity(), 1.0)
Exemplo n.º 12
0
 def test_it_returns_a_list_of_outdated_liabilities(self):
     account_one = AccountBuilder().set_name("name one") \
         .set_institution("institution") \
         .set_owner("owner") \
         .set_investment("investment") \
         .set_asset_class(AssetClass.NONE) \
         .set_account_type(AccountType.LIABILITY) \
         .set_update_frequency(10) \
         .build()
     account_two = AccountBuilder().set_name("name two") \
         .set_institution("institution") \
         .set_owner("owner") \
         .set_investment("investment") \
         .set_asset_class(AssetClass.NONE) \
         .set_account_type(AccountType.LIABILITY) \
         .set_update_frequency(3) \
         .build()
     timestamp = EpochDateConverter().date_to_epoch() - 7 * Constants.SECONDS_PER_DAY
     account_one.import_snapshot(timestamp, 100)
     account_two.import_snapshot(timestamp, 100)
     self.portfolio.import_account(account_one)
     self.portfolio.import_account(account_two)
     self.assertEqual(self.portfolio.outdated_liabilities(), [account_two])
 def test_it_returns_the_debt_to_equity_ratio_for_a_portfolio_with_a_mixture_of_accounts_in_nonequal_value(
         self):
     asset = AccountBuilder().set_name("name") \
         .set_institution("institution") \
         .set_owner("owner") \
         .set_investment("investment") \
         .set_asset_class(AssetClass.NONE) \
         .set_account_type(AccountType.ASSET) \
         .build()
     liability = AccountBuilder().set_name("name") \
         .set_institution("institution") \
         .set_owner("owner") \
         .set_investment("investment") \
         .set_asset_class(AssetClass.NONE) \
         .set_account_type(AccountType.LIABILITY) \
         .build()
     asset.import_snapshot(EpochDateConverter().date_to_epoch(), 1234)
     liability.import_snapshot(EpochDateConverter().date_to_epoch(), 12345)
     portfolio = Portfolio()
     portfolio.import_account(asset)
     portfolio.import_account(liability)
     self.assertAlmostEqual(
         PortfolioAnalyzer(portfolio).debt_to_equity(), 1.1110611)
Exemplo n.º 14
0
 def import_data(self, data):
     account = AccountBuilder()\
         .set_name(data.get("name"))\
         .set_institution(data.get("institution"))\
         .set_owner(data.get("owner"))\
         .set_investment(data.get("investment"))\
         .set_asset_class(AssetClass(data.get("asset_class")))\
         .set_account_type(AccountType(data.get("account_type")))\
         .set_update_frequency(data.get("update_frequency"))\
         .set_open_date(data.get("open_date"))\
         .set_term(Term(data.get("term")))\
         .build()
     self.__create_or_update(data.get("timestamp"), data.get("value"),
                             account)
Exemplo n.º 15
0
separator = "=>"
default_start_date = "2018-01-01"

institution = "Charles Schwab"
name = "Brokerage"
owner = "Cyrus"
investment = "Johnson and Johnson"
account_type = AccountType.ASSET
asset_class = AssetClass.EQUITIES
open_date = None

test_account = AccountBuilder().set_name(name) \
    .set_institution(institution) \
    .set_owner(owner) \
    .set_investment(investment) \
    .set_asset_class(asset_class) \
    .set_account_type(account_type) \
    .set_update_frequency(90) \
    .set_open_date(open_date)\
    .build()

account = None

for a in portfolio.accounts:
    if a.is_identical_to(test_account):
        account = a

if account is None:
    print("No account found")
    exit(1)
 def setUp(self):
     self.builder = AccountBuilder().set_name("name").set_owner("owner").set_investment("investment").set_institution("institution")
 def test_the_account_institution_is_required(self):
     builder = AccountBuilder().set_name("name").set_owner("owner").set_investment("investment")
     self.assertRaises(InvalidAccountException, builder.build)