Exemplo n.º 1
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
     })
 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.º 3
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
     })
 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.º 5
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)
Exemplo n.º 6
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.º 8
0
class BalanceSheetTestCase(unittest.TestCase):
    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()

    def test_it_returns_a_formatted_row_for_a_balance_sheet(self):
        date_difference = Constants.SECONDS_PER_DAY * 2
        timestamp = EpochDateConverter().date_to_epoch()
        expected_date = EpochDateConverter().epoch_to_date(timestamp - date_difference)
        self.asset.import_snapshot(timestamp - date_difference, 100)
        balance_sheet_row = BalanceSheet().row(self.asset)
        self.assertEqual(balance_sheet_row, [expected_date, "institution", "name", "investment", "owner", "100.00"])

    def test_it_returns_an_empty_balance_sheet_if_there_are_no_accounts_in_the_portfolio(self):
        balance_sheet = BalanceSheet(self.portfolio)
        expected_output = [["---", "---", "---", "---", "---", "---"],
                           ["", "", "", "", "Total", "0.00"]]
        self.assertEqual(balance_sheet.create(), expected_output)

    def test_it_returns_a_balance_sheet_with_one_asset(self):
        self.asset.import_snapshot(EpochDateConverter().date_to_epoch('2017-12-12'), 100)
        self.portfolio.import_account(self.asset)
        balance_sheet = BalanceSheet(self.portfolio)
        expected_output = [["2017-12-12", "institution", "name", "investment", "owner", "100.00"],
                           ["---", "---", "---", "---", "---", "---"],
                           ["", "", "", "", "Total", "100.00"]]
        self.assertEqual(balance_sheet.create(), expected_output)

    def test_it_returns_a_balance_sheet_with_one_liability(self):
        self.liability.import_snapshot(EpochDateConverter().date_to_epoch('2011-1-1'), 500.12)
        self.portfolio.import_account(self.liability)
        balance_sheet = BalanceSheet(self.portfolio)
        expected_output = [["---", "---", "---", "---", "---", "---"],
                           ["2011-01-01", "institution", "name", "investment", "owner", "500.12"],
                           ["", "", "", "", "Total", "-500.12"]]
        self.assertEqual(balance_sheet.create(), expected_output)

    def test_it_returns_a_balance_sheet_with_an_asset_and_a_liability(self):
        self.asset.import_snapshot(EpochDateConverter().date_to_epoch('2017-11-12'), 1020)
        self.liability.import_snapshot(EpochDateConverter().date_to_epoch('2013-5-5'), 0.12)
        self.portfolio.import_account(self.asset)
        self.portfolio.import_account(self.liability)
        balance_sheet = BalanceSheet(self.portfolio)
        expected_output = [["2017-11-12", "institution", "name", "investment", "owner", "1020.00"],
                           ["---", "---", "---", "---", "---", "---"],
                           ["2013-05-05", "institution", "name", "investment", "owner", "0.12"],
                           ["", "", "", "", "Total", "1019.88"]]
        self.assertEqual(balance_sheet.create(), expected_output)

    def test_it_returns_no_assets_or_liabilities(self):
        balance_sheet = BalanceSheet(self.portfolio)
        expected_output = {"assets": [], "liabilities": []}
        self.assertEqual(balance_sheet.json(), expected_output)

    def test_it_returns_an_asset(self):
        self.asset.import_snapshot(EpochDateConverter().date_to_epoch('2017-11-12'), 1020)
        self.portfolio.import_account(self.asset)
        balance_sheet = BalanceSheet(self.portfolio)
        expected_output = {"assets": [{"lastUpdated": "2017-11-12T12:00:00-05:00", "institution": "institution", "owner": "owner", "account": "name", "value": 1020, "investment": "investment"}], "liabilities": []}
        self.assertEqual(balance_sheet.json(), expected_output)

    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_a_liability(self):
        self.liability.import_snapshot(EpochDateConverter().date_to_epoch('2010-01-10'), 129)
        self.portfolio.import_account(self.liability)
        balance_sheet = BalanceSheet(self.portfolio)
        expected_output = {"assets": [], "liabilities": [{"lastUpdated": "2010-01-10T12:00:00-05:00", "institution": "institution", "owner": "owner", "account": "name", "value": 129, "investment": "investment"}]}
        self.assertEqual(balance_sheet.json(), expected_output)

    def test_it_returns_two_liabilities(self):
        liability_one = AccountBuilder().set_name("name one") \
            .set_owner("owner one") \
            .set_investment("investment one") \
            .set_institution("institution one") \
            .set_update_frequency(5) \
            .set_liability() \
            .build()
        liability_two = AccountBuilder().set_name("name two") \
            .set_owner("owner two") \
            .set_investment("investment two") \
            .set_institution("institution two") \
            .set_update_frequency(3) \
            .set_liability() \
            .build()
        liability_one.import_snapshot(EpochDateConverter().date_to_epoch('2005-11-12'), 100.50)
        liability_two.import_snapshot(EpochDateConverter().date_to_epoch('2000-12-12'), 1289)
        self.portfolio.import_account(liability_one)
        self.portfolio.import_account(liability_two)
        balance_sheet = BalanceSheet(self.portfolio)
        expected_output = {"assets": [], "liabilities": [{"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"}]}
        self.assertEqual(balance_sheet.json(), expected_output)