-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtempo.py
35 lines (27 loc) · 964 Bytes
/
tempo.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import datetime
import pandas as pd
import numpy as np
from utils import get_symbol, calc_rollsum, calc_sharpe
from strategies import strat_movavg
# markv = {i: str(i) for i in range(50, 120, 10)}
# print(markv)
# Define parameters
symbol = "SPY"
range = "day"
startd = datetime.date(2000, 1, 1)
endd = datetime.date.today()
# Download stock prices from Polygon for the symbol
ohlc = get_symbol(symbol=symbol, startd=startd, endd=endd, range=range)
# Calculate log stock prices
# ohlc[["Open", "High", "Low", "Close"]] = np.log(ohlc[["Open", "High", "Low", "Close"]])
# Calculate log asset returns
closep = np.log(ohlc.Close)
retsp = closep.diff()
sharpev = round(calc_sharpe(retsp), 3)
# Calculate the strategy Sharpe ratio
lookback = 21
lagv = 5
retstrat = strat_movavg(closep, retsp, lookback, lagv)
sharpestrat = calc_sharpe(retstrat)
textv = "Strategy Sharpe = " + str(round(sharpestrat, 3)) + "\n" + symbol + " Sharpe = " + str(sharpev)
print(textv)