Example #1
0
    def setUpClass(cls):
        # configure data directory
        DATA_DIR = path.abspath(path.join(__file__, "../setup/data"))
        left_fileName = 'test_join_left_table.csv'
        right_fileName = 'test_join_right_table.csv'
        data_left = os.path.join(DATA_DIR, left_fileName)
        data_left = data_left.replace('\\', '/')
        data_right = os.path.join(DATA_DIR, right_fileName)
        data_right = data_right.replace('\\', '/')
        dfsDatabase = "dfs://testjoinDB"

        # connect to a DolphinDB server
        orca.connect(HOST, PORT, "admin", "123456")
        _create_odf_csv(data_left, data_right)

        # import
        Csv.odf_csv_left = orca.read_csv(data_left,
                                         dtype={"TRDSTAT": "SYMBOL"})
        Csv.odfs_csv_left = orca.read_table(dfsDatabase, 'tb_left')
        Csv.pdf_csv_left = pd.read_csv(data_left, parse_dates=[1])

        Csv.odf_csv_right = orca.read_csv(data_right,
                                          dtype={"TRDSTAT": "SYMBOL"})
        Csv.odfs_csv_right = orca.read_table(dfsDatabase, 'tb_right')
        Csv.pdf_csv_right = pd.read_csv(data_right, parse_dates=[0])
Example #2
0
    def setUpClass(cls):
        # configure data directory
        DATA_DIR = path.abspath(path.join(__file__, "../setup/data"))
        fileName = 'USPricesSample.csv'
        data = os.path.join(DATA_DIR, fileName)
        data = data.replace('\\', '/')

        # Orca connect to a DolphinDB server
        orca.connect(HOST, PORT, "admin", "123456")

        # odf from import
        Csv.odf_csv = orca.read_csv(data,
                                    dtype={
                                        "PERMNO": np.int32,
                                        "date": 'DATE',
                                        "TRDSTAT": 'SYMBOL',
                                        "DLSTCD": np.float32,
                                        "DLPRC": np.float32,
                                        "VOL": np.float32,
                                        "SHROUT": np.float32
                                    })
        # pdf from import
        Csv.pdf_csv = pd.read_csv(data,
                                  parse_dates=[1],
                                  dtype={
                                      "PERMNO": np.int32,
                                      "SHRCD": np.int32,
                                      "HEXCD": np.int32,
                                      "DLSTCD": np.float32,
                                      "DLPRC": np.float32,
                                      "VOL": np.float32,
                                      "SHROUT": np.float32
                                  })
Example #3
0
    def setUpClass(cls):
        # configure data directory
        DATA_DIR = path.abspath(path.join(__file__, "../setup/data"))
        fileName = 'onlyNumericalColumns.csv'
        data = os.path.join(DATA_DIR, fileName)
        data = data.replace('\\', '/')

        # Orca connect to a DolphinDB server
        orca.connect(HOST, PORT, "admin", "123456")

        Csv.pdf_csv = pd.read_csv(data)
        Csv.odf_csv = orca.read_csv(data)
Example #4
0
    def setUpClass(cls):
        # configure data directory
        DATA_DIR = path.abspath(path.join(__file__, "../setup/data"))
        left_fileName = 'test_merge_left_table.csv'
        right_fileName = 'test_merge_right_table.csv'
        datal = os.path.join(DATA_DIR, left_fileName)
        datal= datal.replace('\\', '/')
        datar = os.path.join(DATA_DIR, right_fileName)
        datar = datar.replace('\\', '/')
        dfsDatabase = "dfs://testMergeDB"

        # connect to a DolphinDB server
        orca.connect(HOST, PORT, "admin", "123456")
        _create_odf_csv(datal, datar)

        # import
        Csv.odf_csv_left = orca.read_csv(datal)
        Csv.odfs_csv_left = orca.read_table(dfsDatabase, 'tickers')
        Csv.pdf_csv_left = pd.read_csv(datal, parse_dates=[0,1])
        Csv.odf_csv_right = orca.read_csv(datar)
        Csv.odfs_csv_right = orca.read_table(dfsDatabase, 'values')
        Csv.pdf_csv_right = pd.read_csv(datar)
Example #5
0
    def setUpClass(cls):
        # configure data directory
        DATA_DIR = path.abspath(path.join(__file__, "../setup/data"))
        fileName = 'USPricesSample.csv'
        data = os.path.join(DATA_DIR, fileName)
        data = data.replace('\\', '/')

        # Orca connect to a DolphinDB server
        orca.connect(HOST, PORT, "admin", "123456")

        # import
        Csv.odf_csv = orca.read_csv(data)
        Csv.odf_csv.set_index('date', inplace=True)
        Csv.pdf_csv = pd.read_csv(data)
        Csv.pdf_csv.set_index('date', inplace=True)
Example #6
0
    def setUpClass(cls):
        # configure data directory
        DATA_DIR = path.abspath(path.join(__file__, "../setup/data"))
        fileName = 'USPricesSample.csv'
        data = os.path.join(DATA_DIR, fileName)
        data = data.replace('\\', '/')

        # connect to a DolphinDB server
        orca.connect(HOST, PORT, "admin", "123456")

        Csv.odf_csv = orca.read_csv(data,
                                    dtype={
                                        "DLSTCD": np.float32,
                                        "DLPRC": np.float32
                                    })
        # pdf from import
        Csv.pdf_csv = pd.read_csv(data)
        Csv.odf_csv = Csv.odf_csv.drop(columns=['DLRET'])
        Csv.pdf_csv.drop(columns=['DLRET'], inplace=True)
Example #7
0
def main():
    df = orca.read_csv(US)

    price_data = load_price_data(df)
    tradables = gen_trade_tables(price_data)

    start_date, end_date = orca.Timestamp("1996.01.01"), orca.Timestamp(
        "2017.01.01")
    holding_days = 5
    groups = 10
    ports = form_portfolio(start_date, end_date, tradables, holding_days,
                           groups, 2)
    daily_rtn = price_data.loc[price_data.date.between(start_date, end_date),
                               ['date', 'PERMNO', 'RET']]

    last_days = price_data.groupby('PERMNO')['date'].max()
    last_days.rename("last_day", inplace=True)
    stock_pnl = calc_stock_pnl(ports, daily_rtn, holding_days, end_date,
                               last_days)

    port_pnl = stock_pnl.groupby('date')['pnl'].sum()
    cumulative_return = port_pnl.cumsum()
    cumulative_return.plot()
    plt.show()
Example #8
0
from setup.settings import *
import csv

# configure data directory
DATA_DIR = path.abspath(path.join(__file__, "../setup/data"))
PRECISION_POINT = 1
fileName = 'USPrices.csv'
data = os.path.join(DATA_DIR, fileName)
data = data.replace('\\', '/')

# Orca connect to a DolphinDB server
orca.connect(HOST, PORT, "admin", "123456")

# import
startTime = time.time()
odf = orca.read_csv(data)
print("Orca spent " + str(time.time() - startTime) + "s importing '" +
      fileName + "'")

# generate report.csv
csvfile = open(WORK_DIR + 'report.csv', 'a')
writer = csv.writer(csvfile)
writer.writerow(
    [time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time()))])
writer.writerow(['groupby', 'orca'])


def reportToCsv(operation, timecost):
    lines = [operation, timecost]
    writer.writerow(lines)
Example #9
0
import orca
from setup.settings import *
import matplotlib.pyplot as plt
import os.path as path

# configure data directory
DATA_DIR = path.abspath(path.join(__file__, "../setup/data"))
fileName = 'wages_hours.csv'
data = path.join(DATA_DIR, fileName)
data = data.replace('\\', '/')

orca.connect(HOST, PORT, "admin", "123456")

odf = orca.read_csv(data)
odf.head()

odf = orca.read_csv(data, sep="\t")
odf.head()

odf2 = odf[["AGE", "RATE"]]
odf2.head()

data_sorted = odf2.sort_values(["AGE"])
data_sorted.head()

data_sorted.set_index("AGE", inplace=True)
data_sorted.head()

data_sorted.plot()
plt.show()
Example #10
0
    def a_load(self):
        self.df_ticker = orca.read_csv(self.ticker_file)
        self.df_ticker.columns = ticker_columns

        self.df_value = orca.read_csv(self.value_file)
        self.df_value.columns = value_columns