def test_cumsum(): dt = mn.sum_money(rt.read_file('money')) # Assert at datapoint assert float(prg.transaction_at("2014-05-08", dt).total_value) == 4000.0 assert float(prg.transaction_at("2014-05-10", dt).total_value) == 5000.0 # Assert between datapoints (should get nearest smaller index) assert float(prg.transaction_at("2014-05-09", dt).total_value) == 4000.0
def plot_cumulative_state(transactions_file): cs = cumulative_state(rt.read_file(transactions_file)) cs = cs.drop('tsla_q', 1) cs = cs.drop('tsla_p', 1) cs = cs.drop('scty_q', 1) cs = cs.drop('scty_p', 1) cs = cs.drop('vgk_q', 1) cs = cs.drop('vgk_p', 1) cs = cs.drop('vig_q', 1) cs = cs.drop('vig_p', 1) cs = cs.drop('csco_q', 1) cs = cs.drop('csco_p', 1) cs = cs.drop('kndi_q', 1) cs = cs.drop('kndi_p', 1) cs = cs.drop('total_value', 1) print cs cs.plot(kind='area', x='pd_timestamp') plt.show()
def test_cumulative_state(): df = prg.cumulative_state(rt.read_file('transactions')) assert int(df[df.pd_timestamp == pd.Timestamp("2014-04-10")].tsla_q) == 8 assert float(df[df.pd_timestamp == pd.Timestamp("2014-04-10")].tsla_p) == 204.190002 assert float(df[df.pd_timestamp == pd.Timestamp("2014-04-10")].tsla_v) == 1633.520016 assert int(df[df.pd_timestamp == pd.Timestamp("2014-04-10")].scty_q) == 4 assert float(df[df.pd_timestamp == pd.Timestamp("2014-04-10")].scty_p) == 55.130001 assert float(df[df.pd_timestamp == pd.Timestamp("2014-04-10")].scty_v) == 220.520004 assert int(df[df.pd_timestamp == pd.Timestamp("2014-04-10")].ibm_q) == 4 assert float(df[df.pd_timestamp == pd.Timestamp("2014-04-10")].ibm_p) == 195.679993 assert float(df[df.pd_timestamp == pd.Timestamp("2014-04-10")].ibm_v) == 782.719972 assert int(df[df.pd_timestamp == pd.Timestamp("2014-04-10")]['sie.de_q']) == 0 assert float(df[df.pd_timestamp == pd.Timestamp("2014-04-10")]['sie.de_p']) == 97.26 assert float(df[df.pd_timestamp == pd.Timestamp("2014-04-10")]['sie.de_v']) == 0 assert float(df[df.pd_timestamp == pd.Timestamp("2014-04-10")].total_value) == 2636.759992
def plot_total_value_progress(transactions_file): cs = cumulative_state(rt.read_file(transactions_file)) cs.plot(x='pd_timestamp', y='total_value') plt.show()
def test_yield(): assert mn.count_yield(rt.read_file('money')) == 0.15
def test_worth_at_date(): moneystr = mn.worth_at_date(rt.read_file('money'), date(2014, 5, 9)) assert "bruce 59331.9" in moneystr assert "alice 19777.3" in moneystr
def test_invested(): moneystr = mn.invested(rt.read_file('money')) assert "alice 2000" in moneystr assert "bruce 4000" in moneystr
def test_read_file(): lines = rt.read_file('transactions') assert lines[0]['ticker'] == 'tsla' assert lines[1]['ticker'] == 'ibm' assert lines[2]['ticker'] == 'scty'
def test_transaction_at_missing_inter(): df = prg.to_dataframe(rt.read_file('transactions')) tr = prg.transaction_at("2014-04-09", df) field_by_field_equal(tr, example_dict_inter)
def test_transaction_at_direct(): df = prg.to_dataframe(rt.read_file('transactions')) tr = prg.transaction_at("2014-04-10", df) field_by_field_equal(tr, example_dict)
def test_money_cumulative_state(): df = prg.money_cumulative_state(rt.read_file('money')) assert int(df[df.pd_timestamp == pd.Timestamp("2014-05-10")].bruce_q) == 4000 assert int(df[df.pd_timestamp == pd.Timestamp("2014-05-11")].alice_q) == 2000
def test_overview(): rt.read_file('transactions')
def test_all_timestamps(): t = rt.read_file('transactions') l = rt.all_timestamps(t) assert l.count(1389312000000000000) == 1 assert l.count(1391990400000000000) == 1 assert l.count(1397088000000000000) == 1
def test_all_dates(): t = rt.read_file('transactions') l = rt.all_dates(t) assert l.count(date(2014, 1, 10)) == 1 assert l.count(date(2014, 2, 10)) == 1 assert l.count(date(2014, 4, 10)) == 1
def test_all_tickers(): t = rt.read_file('transactions') l = rt.all_tickers(t) assert l.count('tsla') == 1 assert l.count('ibm') == 1 assert l.count('scty') == 1
def read_file(transaction_file): return prg.to_dataframe(rt.read_file(transaction_file))
import stocks as st import report as rp ## This is how the lambda is done # ds['total_czk'] = ds.total_value.apply(lambda x: x * cv.getUSDCZK()) ## Bezny check print "Akcie v USD" print "Dne: " + str(date.today()) print str(st.worth_at_date('../transactions/us_stocks', date.today())) print "V czk:" print str(st.worth_at_date_czk('../transactions/us_stocks', date.today())) print "Investovane penize" print mn.invested(rt.read_file('../transactions/czk')) print "Prodat lze" print str(st.three_years_test('../transactions/us_stocks')) print "Zhodnoceni" print "Honza" print str(rp.appreciation(rt.read_file('../transactions/czk'), '../transactions/us_stocks', 'jd')) print "Deni" print str(rp.appreciation(rt.read_file('../transactions/czk'), '../transactions/us_stocks', 'deni')) print "Mama" print str(rp.appreciation(rt.read_file('../transactions/czk'), '../transactions/us_stocks', 'mama')) print "Terka" print str(rp.appreciation(rt.read_file('../transactions/czk'), '../transactions/us_stocks', 'terka')) print "Laura" print str(rp.appreciation(rt.read_file('../transactions/czk'), '../transactions/us_stocks', 'laura'))
def test_apprec(): assert rep.appreciation(rt.read_file('money'), 'transactions', 'alice') > 0