Skip to content

Instantly share code, notes, and snippets.

View maxwellbade's full-sized avatar

Max Bade maxwellbade

View GitHub Profile
@maxwellbade
maxwellbade / Fraud_rate.py
Last active February 18, 2021 19:58
Fraud Rate Function
def fraud_rate(df, agg, cols=None, threshold=None, limit=None, days=None):
if isinstance(cols, str):
groupcols = [cols]
elif cols is None:
groupcols = []
else:
try:
groupcols = list(cols)
except:
raise TypeError('Unable to convert cols to a list.')
@maxwellbade
maxwellbade / multiple_defect.py
Last active February 18, 2021 19:58
multiple defect
def multiple_defect(nds, agg, cols, n, minrate=0.05):
import itertools
combos = list(itertools.combinations(cols, n))
num_cols = ['col' + str(i) for i in range(1, n + 1)]
res = []
for combo in combos:
fr = fraud_rate(nds, agg, combo)
fr = fr.reset_index()
fr.columns = num_cols + ['fraud', 'nonfraud', 'fraudrate','fpr']
fr = fr.assign(groupcols = ', '.join(combo))
@maxwellbade
maxwellbade / fraud_plots.py
Last active February 18, 2021 19:28
fraud plots
#random pivot df for a plot
create_date_df = df[['Microsoft Account Created Date', 'fraud']]
create_date_df = pd.pivot_table(create_date_df
, index=['Microsoft Account Created Date']
, columns = 'fraud'
, aggfunc=len
).reset_index()
@maxwellbade
maxwellbade / .py
Created May 7, 2021 18:10
json_to_csv
dirpath = '/Users/max.bade/Downloads/pancakeswap/'
output = '/Users/max.bade/Downloads/pancakeswap/output/pancakeswap.csv'
csvout_lst = []
files = [os.path.join(dirpath, fname) for fname in os.listdir(dirpath)]
# for filename in sorted(files):
for filename in cakes:
def cross_join(left, right):
new_rows = []
@maxwellbade
maxwellbade / .py
Created May 7, 2021 18:15
json_to_csv_2
cake_4_1 = json.load(open('/Users/max.bade/Downloads/pancakeswap/4_1.txt'))
cake_4_2 = json.load(open('/Users/max.bade/Downloads/pancakeswap/4_2.txt'))
cake_4_3 = json.load(open('/Users/max.bade/Downloads/pancakeswap/4_3.txt'))
cake_4_4 = json.load(open('/Users/max.bade/Downloads/pancakeswap/4_4.txt'))
cake_4_5 = json.load(open('/Users/max.bade/Downloads/pancakeswap/4_5.txt'))
cake_4_6 = json.load(open('/Users/max.bade/Downloads/pancakeswap/4_6.txt'))
cake_4_7 = json.load(open('/Users/max.bade/Downloads/pancakeswap/4_7.txt'))
cake_4_8 = json.load(open('/Users/max.bade/Downloads/pancakeswap/4_8.txt'))
cake_4_9 = json.load(open('/Users/max.bade/Downloads/pancakeswap/4_9.txt'))
cake_4_10 = json.load(open('/Users/max.bade/Downloads/pancakeswap/4_10.txt'))
@maxwellbade
maxwellbade / .py
Created May 7, 2021 18:17
pandas_json
df = pd.read_csv(output,)
df.columns = ['index_duplicate','buy_symbol','sell_symbol','#_trades','trade_amount_$']
del df['index_duplicate']
df['num_trades_x_tradeamount'] = df['#_trades'] * df['trade_amount_$']
# df = df.sort_values(by='num_trades_x_tradeamount',ascending=False).reset_index()
# del df['index']
start = pd.to_datetime("4/1/2021")
df['trade_date'] = pd.Series(np.arange(len(df)) // 1000) \
.apply(lambda x: pd.Timedelta(days=x)) + start
@maxwellbade
maxwellbade / .py
Created May 7, 2021 18:21
filtered_df_pandas
filtered_coins = df.groupby(['Week_Number','pair'])['pct_ch'].agg('sum').reset_index()
filtered_coins.columns = ['Week_Number','pair','total_weekly_pct_ch']
filtered_coins = filtered_coins[filtered_coins['Week_Number'] == 18][['Week_Number','pair','total_weekly_pct_ch']].sort_values(by='total_weekly_pct_ch',ascending=False).reset_index()
filtered_coins = filtered_coins[filtered_coins['total_weekly_pct_ch']>=50]
print(filtered_coins.shape)
print(filtered_coins.pair.nunique())
filtered_coins.head(10)
@maxwellbade
maxwellbade / .py
Created May 7, 2021 18:28
plot_coins
fig = px.bar(filtered_coins
,x='pair'
,y='total_weekly_pct_ch'
,color='pair'
# ,size='total_weekly_pct_ch'
# ,facet_row='pair'
# ,facet_row_spacing=.005
# ,facet_col='Week_Number'
# ,facet_col_wrap=2
# ,log_y=True
@maxwellbade
maxwellbade / .py
Created May 7, 2021 18:32
facet_row
fig = px.line(df2
,x='trade_date'
,y='pct_ch'
,color='pair'
,facet_row='pair'
,facet_row_spacing=.005
# ,facet_col='Week_Number'
# ,facet_col_wrap=2
# ,log_y=True
,range_y=[0, 8000]
@maxwellbade
maxwellbade / .py
Last active May 7, 2021 18:41
joyplot
coins_to_remove = ['BUSD','WBNB','ETH','USDT','USDC','BTC','Cake']
df = df[~df.buy_symbol.isin(coins_to_remove)]
print(df.shape)
print('unique pairs: ',df.pair.nunique())
df.head(20)
df2 = df
df2 = df2[df2['sum_pct_change'] >= 500]
print(df2.pair.nunique())
df2.head()