-
Notifications
You must be signed in to change notification settings - Fork 6
/
trade.py
50 lines (33 loc) · 1.06 KB
/
trade.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# -*- coding: utf-8 -*-
"""
Algorithmic trading testing.
"""
import pandas as pd
import strategy
from pyalgotrade.barfeed import googlefeed
def show_clustered_equities(exchange):
"""
Show details for the clustered equities
:param exchange: Exchange name
:return: None
"""
df_clustered_equities = pd.read_csv('dataset/{}_clustered_equities.csv'.format(exchange))
print(df_clustered_equities.groupby(['cluster']).symbol.nunique())
def get_equities_by_cluster(df_equities, cluster):
print("Get equities by clusters")
def run_strategy(smaPeriod):
# Load the Google feed from the CSV file
feed = googlefeed.Feed()
feed.addBarsFromCSV("ytlpowr", "dataset/6742.kl.csv")
# Evaluate the strategy with the feed's bars.
myStrategy = strategy.SmaTradingStrategy(feed, "ytlpowr", smaPeriod)
myStrategy.run()
print("Final portfolio value: $%.2f" % myStrategy.getBroker().getEquity())
def main():
"""
Main script.
"""
# show_clustered_equities('KLS')
run_strategy(15)
if __name__ == "__main__":
main()