예제 #1
0
 def test_portfolio_profile(self):
     profile = r.load_portfolio_profile(info=None)
     assert profile
     assert ('url' in profile)
     assert ('account' in profile)
     assert ('start_date' in profile)
     assert ('market_value' in profile)
     assert ('equity' in profile)
     assert ('extended_hours_market_value' in profile)
     assert ('extended_hours_equity' in profile)
     assert ('extended_hours_portfolio_equity' in profile)
     assert ('last_core_market_value' in profile)
     assert ('last_core_equity' in profile)
     assert ('last_core_portfolio_equity' in profile)
     assert ('excess_margin' in profile)
     assert ('excess_maintenance' in profile)
     assert ('excess_margin_with_uncleared_deposits' in profile)
     assert ('excess_maintenance_with_uncleared_deposits' in profile)
     assert ('equity_previous_close' in profile)
     assert ('portfolio_equity_previous_close' in profile)
     assert ('adjusted_equity_previous_close' in profile)
     assert ('adjusted_portfolio_equity_previous_close' in profile)
     assert ('withdrawable_amount' in profile)
     assert ('unwithdrawable_deposits' in profile)
     assert ('unwithdrawable_grants' in profile)
예제 #2
0
def get_total_gains_minus_dividends():
    """ Returns the amount of money you've gained/lost through trading since the creation of your account, minus dividends
    """
    profileData = r.load_portfolio_profile()
    print(profileData)
    allTransactions = r.get_bank_transfers()
    deposits = sum(
        float(x['amount']) for x in allTransactions
        if (x['direction'] == 'deposit'))  # and (x['state'] == 'completed'))
    withdrawals = sum(
        float(x['amount']) for x in allTransactions
        if (x['direction'] == 'withdraw') and (x['state'] == 'completed'))
    money_invested = deposits - withdrawals
    print(deposits)
    dividends = r.get_total_dividends()
    percentDividend = dividends / money_invested * 100
    totalGainMinusDividends = float(
        profileData['extended_hours_equity']) - dividends - money_invested
    return totalGainMinusDividends
예제 #3
0
dividends from net gain to figure out how much your stocks/options have paid
off.

Note: load_portfolio_profile() contains some other useful breakdowns of equity.
Print profileData and see what other values you can play around with.

'''

#!!! Fill out username and password
username = ''
password = ''
#!!!

login = r.login(username, password)

profileData = r.load_portfolio_profile()
allTransactions = r.get_bank_transfers()
cardTransactions = r.get_card_transactions()

deposits = sum(
    float(x['amount']) for x in allTransactions
    if (x['direction'] == 'deposit') and (x['state'] == 'completed'))
withdrawals = sum(
    float(x['amount']) for x in allTransactions
    if (x['direction'] == 'withdraw') and (x['state'] == 'completed'))
debits = sum(
    float(x['amount']['amount']) for x in cardTransactions
    if (x['direction'] == 'debit' and (x['transaction_type'] == 'settled')))
reversal_fees = sum(
    float(x['fees']) for x in allTransactions
    if (x['direction'] == 'deposit') and (x['state'] == 'reversed'))