Skip to content

Instantly share code, notes, and snippets.

@marcosan93
Created October 18, 2021 18:53
Show Gist options
  • Select an option

  • Save marcosan93/bf32261e4b3736cf5c005cd85a4ab165 to your computer and use it in GitHub Desktop.

Select an option

Save marcosan93/bf32261e4b3736cf5c005cd85a4ab165 to your computer and use it in GitHub Desktop.
# API Key
with open("../eodHistoricalData-API.txt", "r") as f:
api_key = f.read()
# Backtest over 1 year and train on about 1 year's worth of data
train_days = 365
range_of_bt = 365
# Usual Backtest
norm_performance = linRegModelBT(
"BTC-USD",
days_to_backtest=range_of_bt,
days_to_train=train_days,
api_key=api_key,
short=True,
inverse_strat=False
)
# Backtesting but without shorting
bullish_only = linRegModelBT(
"BTC-USD",
days_to_backtest=range_of_bt,
days_to_train=train_days,
api_key=api_key,
short=False,
inverse_strat=False
)
# Do the inverse of the strategy
inverse_performance = linRegModelBT(
"BTC-USD",
days_to_backtest=range_of_bt,
days_to_train=train_days,
api_key=api_key,
short=True,
inverse_strat=True
)
# Inverse and bullish
inverse_bullish = linRegModelBT(
"BTC-USD",
days_to_backtest=range_of_bt,
days_to_train=train_days,
api_key=api_key,
short=False,
inverse_strat=True
)
# Visualizing the Different Outcomes
outcomes = {
"Normal Backtest": norm_performance,
"Bullish Backtest": bullish_only,
"Inverse Strategy": inverse_performance,
"Inverse and Bullish": inverse_bullish
}
for i in outcomes.keys():
fig = px.line(
outcomes[i],
x=outcomes[i].index,
y=outcomes[i],
title=f'{i} Performance',
labels={"y": "Portfolio Balance",
"ds": "Date"})
fig.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment