Skip to content

Instantly share code, notes, and snippets.

View samchaaa's full-sized avatar
🥑
hi

Sam Chakerian samchaaa

🥑
hi
View GitHub Profile
@samchaaa
samchaaa / .py
Created December 20, 2020 08:29
# Fade if price closes outside of running 1h % change (w/2h ema)... closes after 15m.
close_time = 1
pct_change = 4
smoothing = 8
results = []
for ticker in tqdm(sp):
data = pd.read_json(json.load(open('./{}/{}.json'.format(data_path, ticker), 'r')))
@samchaaa
samchaaa / .py
Created December 20, 2020 08:30
# Concat all trades
trades_all = pd.DataFrame()
for x in results:
trades = pd.DataFrame(x['trades'])
trades['sym'] = x['ticker']
trades_all = pd.concat([
trades_all,
trades
], axis=0)
trades_all = trades_all[trades_all['change'] != 0].dropna()
def get_max_min(prices, smoothing, window_range):
# Get prices
smooth_prices = prices['close'].rolling(window=smoothing).mean().dropna()
# Get max and min for window
local_max = argrelextrema(smooth_prices.values, np.greater)[0]
local_min = argrelextrema(smooth_prices.values, np.less)[0]
print('local_max, local_min', local_max, local_min)
price_local_max_dt = []
# iterate thru points
for i in local_max:
(
agg_flow
.reset_index()
.style
# after this we are not working a a dataframe but a "styler" object
.format({'cost': '${:,.2f}', 'datetime': '{:%Y/%m}/01',
'percent_quarterly flow': '{:.1%}',
'off_goal': '{:+.1%}',
**{col: '{:.1f}' for col in ['cfs', 'total_flow', 'quarterly_flow']}},
na_rep='Missing')