-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdm_data.py
More file actions
33 lines (27 loc) · 909 Bytes
/
dm_data.py
File metadata and controls
33 lines (27 loc) · 909 Bytes
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
#coding=utf-8
import tushare as ts
import pandas as pd
import numpy as np
import math
def singleton(cls):
def wrapper(code_list, starttime, endtime):
if cls._instance is None:
cls._instance = cls(code_list, starttime, endtime)
return cls._instance
return wrapper
@singleton
#DataRepository = singleton(DataRepository)
class DataRepository(object):
_instance = None
def __init__(self, code_list, starttime, endtime):
self.all_data = {}
for code in code_list:
df = ts.get_k_data(code, starttime, endtime)
df['ma5'] = df['close'].rolling(5).mean()
df['ma10'] = df['close'].rolling(10).mean()
df = df.dropna(how='any')
self.all_data[code] = df
def get_onecode_df(self, code):
return self.all_data[code]
def get_instance(self, code_list, starttime, endtime):
pass