-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdev.py
More file actions
71 lines (60 loc) · 2.29 KB
/
Copy pathdev.py
File metadata and controls
71 lines (60 loc) · 2.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
from datetime import datetime
import os
import logging
import numpy as np
import pandas as pd
import pystore
from decimal import Decimal
from tests.fixtures import Fixes
from src.crypto_accountant.bookkeeper import BookKeeper
logging.basicConfig(level=os.environ.get("LOGLEVEL", "INFO"))
pd.set_option("display.expand_frame_repr", False)
pd.set_option("display.width", 0)
pd.set_option('display.float_format', lambda x: '%.8f' % x)
pd.set_option("display.max_colwidth", 20)
pd.set_option("display.max_rows", None)
pd.set_option("display.min_rows", 100)
pd.set_option("display.max_columns", 8)
# Hardcoded transactions
# txs = TxnFactory.hardcoded_txs()
# Firebase Transactions
firestore_cred_file = Fixes.firestore_cred_file(Fixes.storage_dir())
firestore_ref = Fixes.firestore_ref(firestore_cred_file)
txs = Fixes.firestore_user_transactions(firestore_ref)
# Pystore historical data
pystore.set_path("/Volumes/CAPA/.storage")
store = pystore.store("messari")
historical_prices = store.collection('price')
def get_historical_df(symbols):
df = pd.DataFrame()
available_assets = historical_prices.list_items()
not_found_assets = []
for symbol in symbols:
if symbol in available_assets:
prices = historical_prices.item(symbol).to_pandas()
prices[symbol] = prices['close'].apply(lambda x: Decimal(x))
prices = prices.drop(['open', 'close', 'high', 'low', 'volume'], axis=1)
if df.empty:
df = prices.copy()
else:
df = df.join(prices, how='outer')
else:
not_found_assets.append(symbol)
print(not_found_assets)
df[not_found_assets] = np.nan # create nan columns for unfound assets
df['USD'] = Decimal(1) # create nan columns for unfound assets
df = df.fillna(Decimal(0))
df.index = df.index.tz_localize(tz='UTC').floor('1D')
return df
start = datetime.now()
# initialize bookkeeper
bk = BookKeeper()
bk.add_txs(txs, auto_detect=True)
eq_curve = bk.ledger.generate_equity_curve('assets')
print(eq_curve)
# multiply qty df with price df and then sum them all into total
# historical = get_historical_df(bk.ledger.symbols)
# val_curve = eq_curve.mul(historical)
# val_curve['total'] = val_curve[bk.ledger.symbols].sum(axis=1)
# print(val_curve['total'])
print(datetime.now() - start)