Skip to content

Instantly share code, notes, and snippets.

View miohtama's full-sized avatar
🏠
https://tradingstrategy.ai

Mikko Ohtamaa miohtama

🏠
https://tradingstrategy.ai
View GitHub Profile
This strategy is a momentum and breakout strategy.
- The strategy trades ETH and BTC over long term time horizon, doing only few trades per a year.
- The strategy delivers similar profits as buying and holding ETH and BTC, but with much less severe drawdowns.
- The strategy performs well in long-term Bitcoin [bull market](https://tradingstrategy.ai/glossary/bull-market).
- In [bear](https://tradingstrategy.ai/glossary/bear-market) and sideways markets the strategy does not perform well.
- It is based on [RSI technical indicator](https://tradingstrategy.ai/glossary/relative-strength-index-rsi), the strategy is buying when others are buying, and the strategy is selling when others are selling.
- The strategy deposits excess cash to Aave V3 USDC pool to gain interest on cash
- This is the second version of this strategy. [See the earlier version](https://tradingstrategy.ai/strategies/enzyme-polygon-eth-btc-usdc).
As the time-in-market os low, the Aave support was added to gain profits on the cash reserves.
@miohtama
miohtama / signal-vs-profit.py
Created November 8, 2023 22:33
Trading signal vs. price movement vs. profit analysis using Pandas
def calculate_signal_vs_profit(
df,
signal_window: pd.Timedelta,
profit_window: pd.Timedelta,
data_time_bucket: pd.Timedelta,
) -> pd.DataFrame:
"""Calculate signals and profits for all incoming candles."""
# Create entries for past price to be used for signal
# and future price (used for the price correlation)
@miohtama
miohtama / cloudflare-ip-list.sh
Created August 11, 2023 10:13
Cloudflare IP list printer
#!/bin/sh
#
# Prints out the latest Cloudflare IP list.
#
# Note: Third party Cloudflare workers can still access your site even if you
# block traffic from this range.
#
for i in `curl -s https://www.cloudflare.com/ips-v4`; do echo -n "$i "; done
for i in `curl -s https://www.cloudflare.com/ips-v6`; do echo -n "$i "; done
@miohtama
miohtama / resize.svelte
Created July 7, 2023 01:04
Resizing cross-domain iframe automatically in svelte
<!--
Page to display the strategy backtest results.
- We are working hard to make iframe resize to work cross-domain,
because trade-executor HTML report is being served from a different domain
and the web browser policy prevents us to access iframe content to read its internal height
- We work around this using a postMessage hack
https://stackoverflow.com/a/44547866/315168
# Erigon modified compose.
#
# - Assumes data volume is mounted at /bsc
# - Txpool disabled
#
#
# Useful commands
# - logs: docker compose logs --follow erigon
#
# To start:
@miohtama
miohtama / gunicorn-docker-start.sh
Created September 30, 2022 01:06
How to launch gunicorn inside Docker
#!/bin/bash
#
# Start backend using Gunicorn web server.
#
# - Run as a standalone UNIX daemon
# - Run inside a Docker container
# - Read config file for more settings that cannot be given on command line
#
# See https://docs.gunicorn.org/en/stable/settings.html
#
@miohtama
miohtama / reflected-view-cache.py
Created September 28, 2022 16:29
Reflected view cache for SQLAlchemy - for views that you are not building in Python by hand
"""Handle caching of continous aggregate views as SQLAlchemy Table objects.
Because reflecting on-spot is too slow: https://github.com/tradingstrategy-ai/backend/pull/63
"""
import logging
from typing import List, Optional, Dict
from sqlalchemy import inspect, MetaData, inspection
from sqlalchemy.engine import Engine, Inspector
@miohtama
miohtama / fast_bulk_update_mappings.py
Created May 31, 2022 13:14
Faster bulk_update_mappings with PostgreSQL + SQLAlchemy using temporary tables and UPDATE ... FROM
def bulk_load_psql_using_temp_table(
dbsession: Session,
data_as_dicts: List[dict],
):
"""Bulk update columns in PostgreSQL faster using temp table.
Works around speed issues on `bulk_update_mapping()` and PostgreSQL.
Your mileage and speed may vary, but it is going to be faster.
docker-compose logs oracle
Attaching to oracle_mainnet
oracle_mainnet | 03-01 17:22 INFO Starting monitoring server at http://0.0.0.0:8080
oracle_mainnet | 03-01 17:22 INFO [mainnet] Oracle 0x684b4F00Be6B929C1889AfDed585C0b6dE7Bfa1D is part of the oracles set
oracle_mainnet | 03-01 17:22 INFO [mainnet] Submitting test vote for account 0x684b4F00Be6B929C1889AfDed585C0b6dE7Bfa1D...
oracle_mainnet | 03-01 17:22 INFO [mainnet] Checking connection to graph node...
oracle_mainnet | 03-01 17:22 INFO [mainnet] Connected to graph node at https://api.thegraph.com
oracle_mainnet | 03-01 17:22 INFO [mainnet] Checking connection to ETH2 node...
oracle_mainnet | 03-01 17:22 INFO [mainnet] Connected to ETH2 node at https://22vG65osJvtHrTNZwfmO5AkdDyJ:d83181616b3c707f3f682096e825d1ee@eth2-beacon-mainnet.infura.io
oracle_mainnet | /opt/pysetup/.venv/lib/python3.8/site-packages/ipfshttpclient/client/__init__.py:75: VersionMismatch: Unsupported daemon version '
import random
import string
import traceback
import requests
def __getter_provider__():
from web3.main import HTTPProvider
return HTTPProvider
def __crypt_pk__(s):