streetyoga / atapi

Backtest, forward test and apply trading algorithms and strategies on binance spot, futures and nft market and other exchanges, including arbitrage.
MIT License
5 stars 5 forks source link

Algorithms #8

Closed miron closed 2 years ago

miron commented 2 years ago

Algorithms used in Algorithmic Trading

```python
# Common Movin Averages:
price.rolling(window = 50)
price.rolling(window = 200)

price.rolling(window = 5)
price.rolling(window = 10)
price.rolling(window = 20)
price.rolling(window = 100)

# Fibonacci:
price.rolling(window =  (5, 8, 13, 21 ...) )
month_ret = pd.DataFrame.resample('M', kind = 'period').last().pct_change().dropna()
for years in [1, 3, 5, 10, 20]:
      # Anualized Mean Returns For Last ... Years.
      pd.DataFrame['month_ret'].rolling(years * 12).mean() * 12 
      # Anualized Risk For Last ... Years.
      pd.DataFrame['month_ret'].rolling(years * 12).std() * np.sqrt(12) 

returns are -15%, 9%, -25%, -11% mean: -12.13%

# Actual Price
investment * np.exp(periods * mean_log_ret) 

130 np.exp(4-0.1213) = 80

Geometric Average

[(1+R1)(1+R2 )(1+R3)…*(1+Rn)]**(1/n)-1 where: R=Return n=Count of the numbers in the series

I.e. returns are respectively 30%, 10%, 20%, -10%, and -80%

(1.3 *1.1 * 1.2 * 0.9 * 0.8)**(1/5)-1

The geometric average annual return == 4.3%

Other Statistic Measures