valuate_portfolio¶
- coin2086.valuate_portfolio(trades, initial_portfolio=None)¶
Determines the valuation of the porfolio before each sale
The formula used to compute your taxable PnL (profit and loss) from each sale requires determining the total value of your portfolio of crypto-currencies before each sale. This is the purpose of this function. This function retrieves the prices of crypto-currencies from the public Bitstamp API to determine the value of your portfolio. Even if you did not trade on Bistamp, the prices should be close enough for our purposes. This function returns a column multi-indexed DataFrame. The first level of the column index is either quantity, sell_price, public_price, ref_price and value. The second level of the index are the crypto-currencies. For instance:
quantity sell_price public_price cryptocurrency BTC ETH BTC ETH BTC ETH 2 1.0 5.0 8722.70 NaN 8722.70 300.84 3 0.5 5.0 NaN 285.07 8509.24 285.07 6 1.5 5.0 19531.69 NaN 19531.69 527.45 ref_price value cryptocurrency BTC ETH BTC ETH TOTAL 2 8722.70 300.84 8722.700 1504.20 10226.900 3 8509.24 285.07 4254.620 1425.35 5679.970 6 19531.69 527.45 29297.535 2637.25 31934.785
The meaning of each column is as follows:
- quantity
The quantity of each crypto-currency in the porfolio
- sell_price
The price you sold a crypto-currency at. It will be a non-null value for the crypto-currency you sold, and NaN for the other ones
- public_price
The known price on Bitstamp of each crypto-currency at the moment of your sale trade (the close price of the minute you traded is used)
- ref_public
The union of sell_price and public_price. For a given crypto-currency, if the sale price is known, it is used, otherwise public_price is used
- value
The value of each of your crypto-currencies holdings. This is computed by multiplying quantity by ref_price. This column has an additional TOTAL sub-column that gives the total value of your portfolio
Note that the indexes of this DataFrame are the indexes of the sales (trades with trade_side = SELL) of your trades DataFrame.
- Parameters
trades (pandas.DataFrame) – A normalized DataFrame of trades (see paragraph above). It must include all your buy and sell trades since you bought your first crypto-currency. If this is not the case, you will have to determine your initial portfolio (see
initial_portfolio
argument), and the purchase price of your initial porfolio.initial_portfolio (dict) –
A dictionary representing your portfolio of crypto-currencies as it was before the first trade in the
trades
DataFrame (seetrades
argument). The keys of theinitial_portfolio
dictionary are the crypto-currencies, and the values are the quantities. For example:{ 'BTC': 2, 'ETH': 50, 'LTC': 100 }
- Returns
- The DataFrame containing the composition of the
portfolio, the valuation of the portfolio and the reference prices used for valuation before each sale.
- Return type
pandas.DataFrame