@Kapil3sh/

Algorithmic Trading, Intro to BT package

Python

No description

fork
loading
Files
  • main.py
  • requirements.txt
  • test.png
main.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
import bt
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt

data = bt.get('spy,agg', start='2010-01-01')
print (data.head)

s = bt.Strategy('s1', [bt.algos.RunMonthly(),
                      bt.algos.SelectAll(),
                      bt.algos.WeighEqually(),
                      bt.algos.Rebalance()])

test = bt.Backtest(s,data)
res = bt.run(test)
res.plot()
res.display()


t = np.arange(0.0, 2.0, 0.01)
s = 1 + np.sin(2 * np.pi * t)
fig, ax = plt.subplots()
ax.plot(t, s)
ax.set(xlabel='time (s)', ylabel='voltage (mV)', title='About as simple as it gets, folks')
ax.grid()
fig.savefig("test.png")
plt.show()