def test_linear_market_model(self): t = 0 market = Market("NYSE") model = LinearMarketModel("y=2t+3", slope=2, initial_value=3) market.add_market_model(model, 10) for i in range(20): assert_equals(market.quote(Amount(7, USD), MYR, t+i), Amount(2*i + 3, MYR))
def test_static_market_model(self): t = 0 market = Market("NYSE") model_a = StaticMarketModel("10", 10) model_b = StaticMarketModel("100", 100) # model_a is twice as legit as model_b market.add_market_model(model_a, 2) market.add_market_model(model_b, 1) assert_equals(market.quote(Amount(2, USD), MYR, t+1), Amount(80, MYR))
def test_getting_total_value_of_account(self): t = 0 market = Market("NYSE") static_model = StaticMarketModel("multiplyByTenModel", 10) market.add_market_model(static_model, 1) b = BrokerageAccount("Schwab", market) b.add(Lot.Spot(USD, 0, t + 1), 100, t + 5) b.add(Lot.Spot(MYR, 1, t + 1), 200, t + 10) b.add(Lot.Spot(USD, 2, t + 1), 300, t + 20) b.add(Lot.Spot(MYR, 0, t + 2), 400, t + 30) b.add(Lot.Spot(USD, 0, t + 2), 500, t + 40) assert_equals(b.get_value_amount_of_account_in_security(USD, t=0), 0) assert_equals(b.get_value_amount_of_account_in_security(USD, t=6), Amount(100, USD)) assert_equals(b.get_value_amount_of_account_in_security(USD, t=11), Amount(2100, USD)) assert_equals(b.get_value_amount_of_account_in_security(USD, t=50), Amount(6900, USD))